Skip to content

Commit

Permalink
Added duplicate feature to the sets
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert Oost committed May 6, 2014
1 parent 79c5d34 commit 27e02d9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
18 changes: 18 additions & 0 deletions assets/components/quickstartbuttons/js/mgr/widgets/sets.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ Ext.extend(QuickstartButtons.grid.Sets, MODx.grid.Grid, {
var m = [{
text: _('quickstartbuttons.sets.update')
,handler: this.updateSet
},{
text: _('quickstartbuttons.sets.duplicate')
,handler: this.duplicateSet
},'-',{
text: _('quickstartbuttons.sets.remove')
,handler: this.removeSet
Expand All @@ -110,6 +113,21 @@ Ext.extend(QuickstartButtons.grid.Sets, MODx.grid.Grid, {
Ext.isSafari ? w.setPosition(null,30) : w.center();
}, this);
}
,duplicateSet: function(btn, e) {
MODx.Ajax.request({
url: QuickstartButtons.config.connector_url
,params: {
action: 'mgr/sets/duplicate'
,id: this.menu.record.id
}
,listeners: {
'success':{ fn: function() {
this.refresh();
}
,scope:this }
}
});
}
,removeSet: function(btn, e) {
MODx.msg.confirm({
title: _('quickstartbuttons.sets.remove'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
$_lang['quickstartbuttons.sets.buttonsperrow.five'] = "Five buttons";

$_lang['quickstartbuttons.sets.update'] = "Update set";
$_lang['quickstartbuttons.sets.duplicate'] = "Duplicate set";
$_lang['quickstartbuttons.sets.remove'] = "Remove set";
$_lang['quickstartbuttons.sets.remove_confirm'] = "Are you sure you want to remove this set and it's buttons? This is irreversible!";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

class QuickstartButtonsDuplicateSetProcessor extends modObjectDuplicateProcessor {
public $classKey = 'qsbSet';
public $languageTopics = array('quickstartbuttons:default');
public $objectType = 'quickstartbuttons.qsbset';

public function afterSave() {

$buttons = $this->object->getMany('Button');

/** @var qsbButton $button */
foreach($buttons as $button) {
$buttonArray = $button->toArray();
unset($buttonArray['id']);

/** @var qsbButton $newButton */
$newButton = $this->modx->newObject('qsbButton');
$newButton->fromArray($buttonArray);
$newButton->set('set', $this->newObject->get('id'));
$newButton->save();
}
return parent::afterSave();
}
}

return 'QuickstartButtonsDuplicateSetProcessor';

0 comments on commit 27e02d9

Please sign in to comment.