Skip to content

Commit

Permalink
Added a method to remove an aside from any resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain committed Aug 12, 2011
1 parent 065c232 commit 9421d4b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 19 deletions.
20 changes: 20 additions & 0 deletions assets/components/asides/js/mgr/widgets/asides.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ Ext.extend(Asides.grid.Items,MODx.grid.Grid,{
,handler: this.updateAside
});
m.push('-');
m.push({
text: _('asides.aside_clear')
,handler: this.clearAside
});
m.push('-');
m.push({
text: _('asides.aside_remove')
,handler: this.removeAside
Expand Down Expand Up @@ -125,7 +130,22 @@ Ext.extend(Asides.grid.Items,MODx.grid.Grid,{
this.windows.updateAside.fp.getForm().setValues(r);
this.windows.updateAside.show(e.target);
}
,clearAside: function(btn,e) {
if (!this.menu.record) return false;

MODx.msg.confirm({
title: _('asides.aside_clear')
,text: _('asides.aside_clear_confirm')
,url: this.config.url
,params: {
action: 'mgr/asides/clear'
,id: this.menu.record.id
}
,listeners: {
'success': {fn:function(r) { this.refresh(); },scope:this}
}
});
}
,removeAside: function(btn,e) {
if (!this.menu.record) return false;

Expand Down
4 changes: 3 additions & 1 deletion core/components/asides/controllers/mgr/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
* @package asides
* @subpackage controllers
*/
$modx->regClientCSS($asides->config['cssUrl'].'mgr.css');

//$modx->regClientCSS($asides->config['cssUrl'].'mgr.css');
$modx->regClientStartupScript($asides->config['jsUrl'].'mgr/asides.js');

$modx->regClientStartupScript($modx->config['assets_url'].'components/tinymce/jscripts/tiny_mce/tiny_mce.js');
Expand All @@ -40,5 +41,6 @@
Asides.action = "'.(!empty($_REQUEST['a']) ? $_REQUEST['a'] : 0).'";
});
</script>');
//$modx->loadRichTextEditor();

return '';
16 changes: 9 additions & 7 deletions core/components/asides/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@
* @package asides
* @subpackage lexicon
*/
$_lang['asides.menu'] = 'Asides';
$_lang['asides.menu_desc'] = 'Manage your asides.';
$_lang['asides.intro_msg'] = 'Manage your asides.';

$_lang['asides.items'] = 'Asides';

$_lang['asides.aside_clear'] = 'Clear this aside';
$_lang['asides.aside.content'] = 'Content';
$_lang['asides.aside_clear_confirm'] = 'Are you sure you want to remove this aside from any resource?';
$_lang['asides.aside_create'] = 'Create an aside';
$_lang['asides.aside_err_ae'] = 'An aside already exists with that name.';
$_lang['asides.aside_err_nf'] = 'Aside not found.';
$_lang['asides.aside_err_ns'] = 'Aside not specified.';
$_lang['asides.aside_err_remove'] = 'An error occurred while trying to remove the aside.';
$_lang['asides.aside_err_remove_in_use'] = 'This aside is still used in the following(s) resource(s):<br /><br />[[+ids]].<br /><br />Please remove it from those resource(s) before deleting it.';
$_lang['asides.aside_err_remove_not_in_use'] = 'This aside isn\'t used in any resource.';
$_lang['asides.aside_err_save'] = 'An error occurred while trying to save the aside.';
$_lang['asides.aside_remove'] = 'Remove this aside';
$_lang['asides.aside_remove_confirm'] = 'Are you sure you want to remove this aside?';
$_lang['asides.aside_remove_not_in_use'] = 'This aside isn\'t used in any resource';
$_lang['asides.aside_update'] = 'Update this aside';
$_lang['asides.aside.content'] = 'Content';
$_lang['asides.menu'] = 'Asides';
$_lang['asides.menu_desc'] = 'Manage your asides.';
$_lang['asides.intro_msg'] = 'Manage your asides.';
$_lang['asides.items'] = 'Asides';

// sortable check box TV
$_lang['cbs_name'] = 'Name';
Expand Down
14 changes: 8 additions & 6 deletions core/components/asides/lexicon/fr/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@
* @package asides
* @subpackage lexicon
*/
$_lang['asides.menu'] = 'Asides';
$_lang['asides.menu_desc'] = 'Gérez vos « modules » de colonne';
$_lang['asides.intro_msg'] = 'Gérez vos « modules » de colonne.';

$_lang['asides.items'] = 'Asides';

$_lang['asides.aside_clear'] = 'Enlever ce module';
$_lang['asides.aside_clear_confirm'] = 'Êtes-vous sûr de vouloir supprimer ce module de toute ressource ?';
$_lang['asides.aside_create'] = 'Créer un module';
$_lang['asides.aside_err_ae'] = 'Un module portant ce nom existe déjà.';
$_lang['asides.aside_err_nf'] = 'Module non trouvé.';
$_lang['asides.aside_err_ns'] = 'Module non indiqué.';
$_lang['asides.aside_err_remove'] = 'Une erreur est survenue lors de la suppression du module.';
$_lang['asides.aside_err_remove_in_use'] = 'Ce module est toujours utilisé dans les ressources suivantes :<br /><br />[[+ids]].<br /><br />Veuillez retirer ce module des ressources avant de le supprimer.';
$_lang['asides.aside_err_remove_not_in_use'] = 'Ce module n\'est utilisé dans aucune ressource.';
$_lang['asides.aside_err_save'] = 'Une erreur est survenue lors de la sauvegarde du module.';
$_lang['asides.aside_remove'] = 'Supprimer ce module';
$_lang['asides.aside_remove_confirm'] = 'Êtes-vous sûr de vouloir supprimer ce module ?';
$_lang['asides.aside_remove_not_in_use'] = 'Ce module n\'est utilisé dans aucune ressource';
$_lang['asides.aside_update'] = 'Mettre à jour ce module';
$_lang['asides.aside.content'] = 'Contenu';
$_lang['asides.menu'] = 'Asides';
$_lang['asides.menu_desc'] = 'Gérez vos « modules » de colonne';
$_lang['asides.intro_msg'] = 'Gérez vos « modules » de colonne.';
$_lang['asides.items'] = 'Asides';

// sortable check box TV
$_lang['cbs_name'] = 'Nom';
Expand Down
30 changes: 28 additions & 2 deletions core/components/asides/model/asides/asides.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@ public function initialize($ctx = 'web') {
* Returns a string of resources using a given aside
*
* @access public
* @param string $aside The aside (chunk) object
* @param array $aside The aside (chunk) object
*/
public function inResource($aside) {
// grab the TV
$asideTV = $this->modx->getObject('modTemplateVar',array('name' => 'aside'));
$asideTVid = $asideTV->get('id');
$asideTVid = '';
if ($asideTV) {
$asideTVid = $asideTV->get('id');
} else {
//@TODO: what if it's been renamed ?
}

// target the modTemplates with this TV
$asideTpls = $this->modx->getCollection('modTemplateVarTemplate',array('tmplvarid' => $asideTVid));
Expand Down Expand Up @@ -128,4 +133,25 @@ public function inResource($aside) {

return trim($o,',');
}

/**
* Removes an aside from any existing resource using it
*
* @acces public
* @param string $aside the aside (chunk) name
* @param string $ids a list of comma separated ids using this aside
*/
public function cleanAside($aside, $ids) {
$resIds = explode(',',$ids);
$tv = $this->modx->getObject('modTemplateVar',array('name' => 'aside'));
//@TODO: what if the tv has been renamed ?
foreach ($resIds as $resourceId) {
$tvValue = $this->modx->getObject('modTemplateVarResource',array('tmplvarid' => $tv->get('id'), 'contentid' => $resourceId));
$value = str_replace($aside,'',$tvValue->get('value'));
$value = str_replace('||||','||',$value);
$value = trim($value,'||');
$tv->setValue($resourceId,$value);
$tv->save();
}
}
}
44 changes: 44 additions & 0 deletions core/components/asides/processors/mgr/asides/clear.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Asides
*
* Copyright 2011 by Romain Tripault // Melting Media <[email protected]>
*
* Asides is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* Asides is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Asides; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package asides
*/
/**
* Remove an aside chunk from any resource (clears its name from the aside TV).
*
* @package asides
* @subpackage processors
*/

$Asides = $modx->getService('asides','Asides',$modx->getOption('asides.core_path',null,$modx->getOption('core_path').'components/asides/').'model/asides/',$scriptProperties);
if (!($Asides instanceof Asides)) return '';

if (empty($scriptProperties['id'])) return $modx->error->failure($modx->lexicon('asides.aside_err_ns'));
$aside = $modx->getObject('modChunk',$scriptProperties['id']);
if (!$aside) return $modx->error->failure($modx->lexicon('asides.aside_err_nf'));

// grabs the resources where this aside is
$resources = $Asides->inResource($aside);
if (!$resources) {
return $modx->error->failure($modx->lexicon('asides.aside_err_remove_not_in_use'));
}
$Asides->cleanAside($aside->get('name'), $resources);

// output
return $modx->error->success('',$aside);
8 changes: 5 additions & 3 deletions core/components/asides/processors/mgr/asides/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/
/**
* Update an aside chunk
*
*
* @package asides
* @subpackage processors
*/
/* get board */

if (empty($scriptProperties['id'])) return $modx->error->failure($modx->lexicon('asides.aside_err_ns'));
$aside = $modx->getObject('modChunk',$scriptProperties['id']);
if (!$aside) return $modx->error->failure($modx->lexicon('asides.aside_err_nf'));
Expand All @@ -36,6 +36,8 @@
return $modx->error->failure($modx->lexicon('asides.aside_err_save'));
}

/* output */
// output
$asideArray = $aside->toArray('',true);

//@TODO: optimum cache clearing
return $modx->error->success('',$asideArray);

0 comments on commit 9421d4b

Please sign in to comment.