Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Update user meta plugin:
Browse files Browse the repository at this point in the history
> Fix sorting for selector based field
> Add ability to bulk-edit metadata for many nodes.
  • Loading branch information
cdujeu committed Nov 28, 2014
1 parent e8da765 commit 458324e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 11 deletions.
18 changes: 13 additions & 5 deletions core/src/plugins/meta.user/class.MetaCellRenderer.js
Expand Up @@ -57,13 +57,21 @@ Class.create("MetaCellRenderer", {
}
}
values = MetaCellRenderer.staticMetadataCache.get(metadataDef.attributeName);
if((type == 'row' || type == 'detail') && element != null){
var nodeMetaValue = ajxpNode.getMetadata().get(metadataDef.attributeName) || '';
if(nodeMetaValue){
nodeMetaValue = $H(values).keys().indexOf(nodeMetaValue);
}else{
nodeMetaValue = -1;
}
console.log(values);
if(element != null){
if(type == 'row'){
if(values[element.down('.text_label').innerHTML.stripTags()]){
element.down('.text_label').update(values[element.down('.text_label').innerHTML.stripTags()]);
}
element.writeAttribute("data-sorter_value", nodeMetaValue);
}else{

element.writeAttribute("data-"+metadataDef.attributeName+"-sorter_value", nodeMetaValue);
}
}
},
Expand Down Expand Up @@ -127,9 +135,9 @@ Class.create("MetaCellRenderer", {
if(content){
obj = new MetaCellRenderer();
rule = obj.findCssRule(content.strip());
if(rule && element.up('div')){
element.up('div').addClassName(rule.cssClass);
element.up('div').writeAttribute("data-"+attName+"-sorter_value", rule.sortValue);
if(rule && element){
element.addClassName(rule.cssClass);
element.writeAttribute("data-"+attName+"-sorter_value", rule.sortValue);
}
}

Expand Down
31 changes: 30 additions & 1 deletion core/src/plugins/meta.user/class.UserMetaManager.php
Expand Up @@ -226,6 +226,34 @@ public function editMeta($actionName, $httpVars, $fileVars)
$selection = new UserSelection();
$selection->initFromHttpVars($httpVars);
$currentFile = $selection->getUniqueFile();

$nodes = $selection->buildNodes($this->accessDriver);
$nodesDiffs = array();
$def = $this->getMetaDefinition();
foreach($nodes as $ajxpNode){

$newValues = array();
//$ajxpNode->setDriver($this->accessDriver);
AJXP_Controller::applyHook("node.before_change", array(&$ajxpNode));
foreach ($def as $key => $data) {
if (isSet($httpVars[$key])) {
$newValues[$key] = AJXP_Utils::decodeSecureMagic($httpVars[$key]);
} else {
if (!isset($original)) {
$original = $ajxpNode->retrieveMetadata("users_meta", false, AJXP_METADATA_SCOPE_GLOBAL);
}
if (isSet($original) && isset($original[$key])) {
$newValues[$key] = $original[$key];
}
}
}
$ajxpNode->setMetadata("users_meta", $newValues, false, AJXP_METADATA_SCOPE_GLOBAL);
AJXP_Controller::applyHook("node.meta_change", array($ajxpNode));

$nodesDiffs[$ajxpNode->getPath()] = $ajxpNode;

}
/*
$urlBase = $this->accessDriver->getResourceUrl($currentFile);
$ajxpNode = new AJXP_Node($urlBase);
Expand All @@ -247,8 +275,9 @@ public function editMeta($actionName, $httpVars, $fileVars)
}
$ajxpNode->setMetadata("users_meta", $newValues, false, AJXP_METADATA_SCOPE_GLOBAL);
AJXP_Controller::applyHook("node.meta_change", array($ajxpNode));
*/
AJXP_XMLWriter::header();
AJXP_XMLWriter::writeNodesDiff(array("UPDATE" => array($ajxpNode->getPath() => $ajxpNode)), true);
AJXP_XMLWriter::writeNodesDiff(array("UPDATE" => $nodesDiffs), true);
AJXP_XMLWriter::close();
}

Expand Down
29 changes: 24 additions & 5 deletions core/src/plugins/meta.user/manifest.xml
Expand Up @@ -35,24 +35,43 @@
</component_config>
</client_configs>
<actions>
<action name="edit_user_meta_mass">
<gui text="meta.user.1" title="meta.user.1" src="meta_user/ICON_SIZE/tag.png" iconClass="icon-tags" hasAccessKey="false">
<context selection="true" dir="" recycle="hidden"
actionBar="true" contextMenu="true" infoPanel="false"
actionBarGroup="info_panel" inZip="false">
</context>
<selectionContext dir="true" file="file" recycle="false" unique="false" multipleOnly="true"/>
</gui>
<rightsContext noUser="true" userLogged="only" read="true" write="true" adminOnly=""/>
<processing>
<clientCallback prepareModal="true"><![CDATA[
ajaxplorer.actionBar.fireAction("edit_user_meta");
]]></clientCallback>
</processing>
</action>
<action name="edit_user_meta">
<gui text="meta.user.1" title="meta.user.1" src="meta_user/ICON_SIZE/tag.png" iconClass="icon-tags" hasAccessKey="false">
<context selection="true" dir="" recycle="hidden"
actionBar="true" contextMenu="true" infoPanel="false"
actionBarGroup="more" inZip="false">
</context>
<selectionContext dir="true" file="file" recycle="false" unique="true"/>
<selectionContext dir="true" file="file" recycle="false" unique="false"/>
</gui>
<rightsContext noUser="true" userLogged="only" read="true" write="true" adminOnly=""/>
<processing>
<clientCallback prepareModal="true"><![CDATA[
var userSelection = ajaxplorer.getUserSelection();
var loadFunc = function(oForm){
var form = $(oForm).select('div[id="user_meta_form"]')[0];
var nodeMeta = userSelection.getUniqueNode().getMetadata();
var metaFields = nodeMeta.get('meta_fields').split(',');
var metaLabels = nodeMeta.get('meta_labels').split(',');
var metaTypes = nodeMeta.get('meta_types').split(',');
var nodeMeta = $H();
var firstNodeMeta = userSelection.getUniqueNode().getMetadata();
var metaFields = firstNodeMeta.get('meta_fields').split(',');
var metaLabels = firstNodeMeta.get('meta_labels').split(',');
var metaTypes = firstNodeMeta.get('meta_types').split(',');
if(userSelection.isUnique()){
nodeMeta = firstNodeMeta;
}
for(var i=0;i<metaFields.length;i++){
var value = nodeMeta.get(metaFields[i]) || '';
form.insert('<div class="SF_element"><div class="SF_label">'+metaLabels[i]+' : </div><input class="SF_input" name="'+metaFields[i]+'" value="'+value.replace(/"/g, '&quot;')+'"/></div>');
Expand Down

0 comments on commit 458324e

Please sign in to comment.