Bruno17 Reply #1, 1 year, 7 months ago
In Evo it was very easy to create simple modules for backend-stuff.
Made a CMP for making it easy to create simple CMPs per snippet.
Perhaps someone finds it usefull.
1. Create a folder /core/components/quickcmp/
2. Create a file in this folder 'index.php' with content:
3. Create a folder /assets/components/quickcmp/
4. Create a file 'quickcmp.js' in this folder with:
5. Create a namespace 'quickcmp' which points to the folder /core/components/quickcmp/
6. Create a action with controller: 'index' and this namespace.
7. Create a menue under components lexicon-key: quickcmp and this action
9. create a new Category 'quickcmp'
3. create snippets under that Category, which you want to have as CMP-moduls
If you want to run one of your module-snippets per default add in the action mymoduls:
parameters: &runmycmp=YourSnippetName
If you want to use more categories and have different cmp-groups create more actions and add under parameters: &qcmpcategory=myowncategory
Made a CMP for making it easy to create simple CMPs per snippet.
Perhaps someone finds it usefull.
1. Create a folder /core/components/quickcmp/
2. Create a file in this folder 'index.php' with content:
<?php
/* setup default properties */
$isLimit = !empty($scriptProperties['limit']);
$start = $modx->getOption('start',$scriptProperties,0);
$limit = $modx->getOption('limit',$scriptProperties,20);
$sort = $modx->getOption('sort',$scriptProperties,'name');
$dir = $modx->getOption('dir',$scriptProperties,'ASC');
$assetsUrl = $this->modx->getOption('quickcmp.assets_url',null,$modx->getOption('assets_url').'components/quickcmp/');
$jsUrl = $assetsUrl.'js/';
$modulcategory=isset($_REQUEST['qcmpcategory'])?$_REQUEST['qcmpcategory']:'quickcmp';
$qcmpcat = isset($_REQUEST['qcmpcategory'])?'&qcmpcategory='.$_REQUEST['qcmpcategory']:'';
$action=$_REQUEST['a'];
/* query for snippets in modulcategory */
$c = $modx->newQuery('modSnippet');
$c->select('modSnippet.id,modSnippet.name');
$c->sortby($sort,$dir);
$c->leftJoin('modCategory','modCategory','`modCategory`.`id` = `modSnippet`.`category`');
$c->where('`modCategory`.`category`="'.$modulcategory.'"');
if ($isLimit) $c->limit($limit,$start);
//$c->prepare();
//echo $c->toSql();
$snippets = $modx->getCollection('modSnippet',$c);
$count = $modx->getCount('modSnippet');
/* iterate through snippets */
$snippetnames = array();
foreach ($snippets as $snippet) {
$snippet=$snippet->toArray();
$snippetnames[]=$snippet['name'];
}
if (isset($_REQUEST['runmycmp'])&& in_array($_REQUEST['runmycmp'],$snippetnames)){
$modulname=$_REQUEST['runmycmp'];
$moduloutput=$modx->runsnippet($modulname);
}
else{
$moduloutput='click any of the tabs to run a quickCMP';
}
if (count ($snippetnames)>0){
foreach ($snippetnames as $name) {
$class= $name==$modulname ?'x-tab-strip-active':'';
$tabs.='
<li class="'.$class.'">
<a href="?a='.$action.'&runmycmp='.$name.$qcmpcat.'" class="x-tab-right"><em class="x-tab-left"><span class="x-tab-strip-inner"><span class="x-tab-strip-text ">'.$name.'</span></span></em></a>
</li>
';
}
}
$output = '
<div id="quickcmp-panel" class=" x-tab-panel modx-tabs">
<div class="x-tab-panel-header x-unselectable x-tab-panel-header-plain" id="quickcmp-panel-header" style="-moz-user-select: none;">
<div class="x-tab-strip-wrap" id="quickcmp-tab-container" style="width: 931px;">
<ul class="x-tab-strip x-tab-strip-top" id="ext-gen66">
'.$tabs.'
<li class="x-tab-edge" >
</li>
<div class="x-clear" >
</div>
</ul>
</div>
<div class="x-tab-strip-spacer" >
</div>
</div>
<div class="x-tab-panel-bwrap" >
<div class="x-tab-panel-body x-tab-panel-body-top" style="padding: 1em; height: auto;">
<div class=" x-panel x-panel-noborder" style="width: 929px;">
<div class="x-panel-bwrap" >
<div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" style="height: auto; width: 929px;">
<div class=" x-panel x-panel-noborder">
<div class="x-panel-bwrap" >
<div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" >
';
$output.= $moduloutput;
$output.='
<br/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
';
$modx->regClientStartupScript($jsUrl.'quickcmp.js');
return $output;
?>
3. Create a folder /assets/components/quickcmp/
4. Create a file 'quickcmp.js' in this folder with:
var QuickCMP = function(config) {
config = config || {};
QuickCMP.superclass.constructor.call(this,config);
};
Ext.extend(QuickCMP,Ext.Component,{
page:{},window:{},grid:{},tree:{},panel:{},combo:{},config: {}
});
Ext.reg('quickcmp',QuickCMP);
var QuickCMP = new QuickCMP();
QuickCMP.page.Object = function(config) {
config = config || {};
Ext.applyIf(config,{
components: [{
xtype: 'box'
,id: 'quickcmp-box'
}]
});
QuickCMP.page.Object.superclass.constructor.call(this,config);
};
Ext.extend(QuickCMP.page.Object,MODx.Component);
Ext.reg('quickcmp-page-home',QuickCMP.page.Object);
Ext.onReady(function() {
var qcmp = MODx.load({
xtype: "quickcmp-page-home"
});
var panel =Ext.getCmp("quickcmp-box");
var el = Ext.get("quickcmp-panel");
el.appendTo(panel.el);
});
5. Create a namespace 'quickcmp' which points to the folder /core/components/quickcmp/
6. Create a action with controller: 'index' and this namespace.
7. Create a menue under components lexicon-key: quickcmp and this action
9. create a new Category 'quickcmp'
3. create snippets under that Category, which you want to have as CMP-moduls
If you want to run one of your module-snippets per default add in the action mymoduls:
parameters: &runmycmp=YourSnippetName
If you want to use more categories and have different cmp-groups create more actions and add under parameters: &qcmpcategory=myowncategory