Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1726521
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Size
9 KB
Subscribers
None
View Options
diff --git a/action.php b/action.php
--- a/action.php
+++ b/action.php
@@ -1,140 +1,163 @@
<?php
/**
* DokuWiki Plugin metaeditor (Action Component)
*
* Simple Meta Data Editor, heavily AJAX/jQuery based.
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Böhler <dev@aboehler.at>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class action_plugin_metaeditor extends DokuWiki_Action_Plugin {
// Load the helper plugin
public function action_plugin_metaeditor() {
}
// Register our hooks
function register(&$controller) {
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
}
function handle_ajax_call_unknown($event, $param) {
if($event->data != 'plugin_metaeditor') return;
$event->preventDefault();
$event->stopPropagation();
global $INPUT;
//global $auth; // FIXME: Add auth check for admin user here
$action = trim($INPUT->post->str('q'));
$pageid = trim($INPUT->post->str('r'));
$key = $INPUT->post->arr('k');
$data = array();
$json = false;
switch($action)
{
case 'getMeta':
$data = $this->getMetaForPage($pageid);
$json = true;
break;
case 'getMetaValue':
$data = $this->getMetaValueForPage($pageid, $key);
break;
case 'setMetaValue':
$oldval = $key['oldval'];
$newval = $key['newval'];
$key = $key['key'];
$data = $this->setMetaValueForPage($pageid, $key, $oldval, $newval);
- breka;
+ break;
+ case 'deleteMetaValue':
+ $json = true;
+ $key = $key['key'];
+ $data = $this->deleteMetaValueForPage($pageid, $key);
+ break;
}
//$data = $_SERVER['REMOTE_USER'];
if($json)
{
//json library of DokuWiki
require_once DOKU_INC . 'inc/JSON.php';
$json = new JSON();
//set content type
header('Content-Type: application/json');
echo $json->encode($data);
}
else
{
echo $data;
}
}
function setMetaValueForPage($pageid, $key, $oldval, $newval)
{
$cache = false;
$meta = p_read_metadata($pageid, $cache);
$m = &$meta;
foreach($key as $k)
$m = &$m[$k];
if($m == $oldval)
{
$m = $newval;
if(p_save_metadata($pageid, $meta))
return "Successfully saved: $newval";
else
return "Error saving value: $newval";
}
else
{
return "Key has changed in the meantime, expected $oldval but got $m. Nothing was saved!";
}
}
+ function deleteMetaValueForPage($pageid, $key)
+ {
+ $cache = false;
+ $meta = p_read_metadata($pageid, $cache);
+ $m = &$meta;
+ for($i=0;$i<count($key);$i++)
+ {
+ if($i == count($key)-1)
+ unset($m[$key[$i]]);
+ else
+ $m = &$m[$key[$i]];
+ }
+ if(p_save_metadata($pageid, $meta))
+ return array(true, "Successfully deleted key: $key");
+ else
+ return array(false, "Error deleting key: $key");
+ }
+
function parseMetaTree($meta)
{
$out = array();
foreach($meta as $k => $v)
{
$a = array();
$a['text'] = $k;
if(is_array($v))
{
$a['children'] = $this->parseMetaTree($v);
}
else
$a['icon'] = DOKU_URL."/lib/images/page.png";
$out[] = $a;
}
return $out;
}
function getMetaForPage($pageid)
{
$cache = false;
$meta = p_read_metadata($pageid, $cache);
$out = $this->parseMetaTree($meta);
return $out;
}
function getMetaValueForPage($pageid, $key)
{
$cache = false;
$meta = p_read_metadata($pageid, $cache);
foreach($key as $k)
{
$meta = $meta[$k];
}
return $meta;
}
}
diff --git a/script.js b/script.js
--- a/script.js
+++ b/script.js
@@ -1,99 +1,188 @@
/* DOKUWIKI:include_once jstree.js */
jQuery(function()
{
var selectedPageId = null;
var selectedNode = null;
+ var selectedNodePath = null;
var selectedNodeValue = null;
+ var jqConfirmModal = null;
jQuery('#event_save').click(function() {
var newVal = jQuery('#event_value').val()
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_metaeditor',
q: 'setMetaValue',
r: selectedPageId,
k: {
key : selectedNode,
oldval : selectedNodeValue,
newval : newVal
}
},
function(data) {
alert(data);
}
);
});
+ jqConfirmModal = jQuery(document.createElement('div'))
+ .dialog({
+ autoOpen: false,
+ draggable: true,
+ //title: LANG.plugins.signpage.signpage,
+ title: "Confirmation",
+ resizable: true,
+ buttons: {
+ Yes: function() {
+ jQuery.post(
+ DOKU_BASE + 'lib/exe/ajax.php',
+ jqConfirmModal.data,
+ function(data) {
+ alert(data);
+ }
+ );
+ jQuery( this ).parent().hide("scale", {percentage: 0}, 750);
+ },
+ Cancel: function() {
+ jQuery( this ).parent().hide("scale", {percentage: 0}, 750);
+ }
+ }
+ })
+ .html(
+ '<div>Really proceed with the requested action? It cannot be undone.</div>'
+ )
+ .parent()
+ .attr('id','metaeditor__confirm')
+ .hide()
+ .appendTo('.dokuwiki:first');
+
+
+
+ // attach event handlers
+ jQuery('#metaeditor__confirm .ui-dialog-titlebar-close').click(function(){
+ jqConfirmModal.hide("scale", {percentage: 0}, 750);
+ });
+
jQuery('#metaTree').on('changed.jstree', function (e, data) {
var i, j, r;
if(data.selected.length != 1)
return;
var node = data.instance.get_node(data.selected[0]);
+ r = data.instance.get_path(data.selected[0]);
+ selectedNodePath = r;
if(!data.instance.is_leaf(node))
return;
- r = data.instance.get_path(data.selected[0]);
selectedNode = r;
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_metaeditor',
q: 'getMetaValue',
r: selectedPageId,
k: r
},
function(data) {
jQuery('#event_path').html(selectedNode.join(':'));
jQuery('#event_value').val(data);
selectedNodeValue = data;
}
);
})
+ .on('delete_node.jstree', function (e, data) {
+
+ jQuery.post(
+ DOKU_BASE + 'lib/exe/ajax.php',
+ {
+ call : 'plugin_metaeditor',
+ q: 'deleteMetaValue',
+ r: selectedPageId,
+ k: {
+ key: selectedNodePath,
+ oldval: selectedNodeValue
+ },
+ },
+ function(data) {
+ alert(data[1]);
+ if(!data[0])
+ {
+ jQuery.post(
+ DOKU_BASE + 'lib/exe/ajax.php',
+ {
+ call: 'plugin_metaeditor',
+ q: 'getMeta',
+ r: selectedPageId
+ },
+ function(data) {
+ jQuery('#metaTree').jstree(true).settings.core.data = data;
+ jQuery('#metaTree').jstree(true).refresh();
+ }
+ );
+ }
+ }
+ );
+ })
+ .on('create_node.jstree', function (e, data) {
+ alert('Create Node CB');
+ })
+ .on('rename_node.jstree', function (e, data) {
+ alert('Rename Node CB');
+ })
+ .on('move_node.jstree', function (e, data) {
+ alert('Move Node CB');
+ })
+ .on('copy_node.jstree', function (e, data) {
+ alert('Copy node CB');
+ })
// create the instance
.jstree({
core : {
- multiple: false
+ multiple: false,
+ check_callback: function (op, node, par, pos, more) {
+ if(op === "delete_node") { return confirm("Are you sure you want to delete?"); }
+ }
},
- plugins: ["wholerow"]
+ plugins: ["wholerow", "contextmenu"]
});
jQuery('#fileTree').on('changed.jstree', function (e, data) {
var i, j, r;
if(data.selected.length != 1)
return;
var node = data.instance.get_node(data.selected[0]);
if(!data.instance.is_leaf(node))
return;
r = node.text;
selectedPageId = r;
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_metaeditor',
q: 'getMeta',
r: r
},
function(data) {
jQuery('#metaTree').jstree(true).settings.core.data = data;
jQuery('#metaTree').jstree(true).refresh();
}
);
})
// create the instance
.jstree({
core : {
multiple: false
},
plugins: ["wholerow"]
});
});
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Dec 4, 5:21 PM (10 h, 19 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
533948
Default Alt Text
(9 KB)
Attached To
rMETAEDITOR DokuWiki MetaData Editor
Event Timeline
Log In to Comment