implement filter drag and drop sorting
This commit is contained in:
parent
da46d21e88
commit
a86ba0a67a
|
@ -3,11 +3,47 @@ class Pref_Filters extends Handler_Protected {
|
||||||
|
|
||||||
function csrf_ignore($method) {
|
function csrf_ignore($method) {
|
||||||
$csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
|
$csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
|
||||||
"newaction");
|
"newaction", "savefilterorder");
|
||||||
|
|
||||||
return array_search($method, $csrf_ignored) !== false;
|
return array_search($method, $csrf_ignored) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filtersortreset() {
|
||||||
|
db_query($this->link, "UPDATE ttrss_filters2
|
||||||
|
SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function savefilterorder() {
|
||||||
|
$data = json_decode($_POST['payload'], true);
|
||||||
|
|
||||||
|
#file_put_contents("/tmp/saveorder.json", $_POST['payload']);
|
||||||
|
#$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
|
||||||
|
|
||||||
|
if (!is_array($data['items']))
|
||||||
|
$data['items'] = json_decode($data['items'], true);
|
||||||
|
|
||||||
|
$index = 0;
|
||||||
|
|
||||||
|
if (is_array($data) && is_array($data['items'])) {
|
||||||
|
foreach ($data['items'][0]['items'] as $item) {
|
||||||
|
$filter_id = (int) str_replace("FILTER:", "", $item['_reference']);
|
||||||
|
|
||||||
|
if ($filter_id > 0) {
|
||||||
|
|
||||||
|
db_query($this->link, "UPDATE ttrss_filters2 SET
|
||||||
|
order_id = $index WHERE id = '$filter_id' AND
|
||||||
|
owner_uid = " .$_SESSION["uid"]);
|
||||||
|
|
||||||
|
++$index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function testFilter() {
|
function testFilter() {
|
||||||
$filter = array();
|
$filter = array();
|
||||||
|
|
||||||
|
@ -623,6 +659,10 @@ class Pref_Filters extends Handler_Protected {
|
||||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
|
||||||
__('Edit')."</button> ";
|
__('Edit')."</button> ";
|
||||||
|
|
||||||
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"return resetFilterOrder()\">".
|
||||||
|
__('Reset sort order')."</button> ";
|
||||||
|
|
||||||
|
|
||||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
|
||||||
__('Remove')."</button> ";
|
__('Remove')."</button> ";
|
||||||
|
|
||||||
|
@ -639,14 +679,16 @@ class Pref_Filters extends Handler_Protected {
|
||||||
<img src='images/indicator_tiny.gif'>".
|
<img src='images/indicator_tiny.gif'>".
|
||||||
__("Loading, please wait...")."</div>";
|
__("Loading, please wait...")."</div>";
|
||||||
|
|
||||||
print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"filterStore\"
|
print "<div dojoType=\"fox.PrefFilterStore\" jsId=\"filterStore\"
|
||||||
url=\"backend.php?op=pref-filters&method=getfiltertree\">
|
url=\"backend.php?op=pref-filters&method=getfiltertree\">
|
||||||
</div>
|
</div>
|
||||||
<div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
|
<div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
|
||||||
query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
|
query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Filters\"
|
||||||
childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
|
childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
|
||||||
</div>
|
</div>
|
||||||
<div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
|
<div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
|
||||||
|
dndController=\"dijit.tree.dndSource\"
|
||||||
|
betweenThreshold=\"5\"
|
||||||
model=\"filterModel\" openOnClick=\"true\">
|
model=\"filterModel\" openOnClick=\"true\">
|
||||||
<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
|
<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
|
||||||
Element.hide(\"filterlistLoading\");
|
Element.hide(\"filterlistLoading\");
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
dojo.provide("fox.PrefFilterTree");
|
dojo.provide("fox.PrefFilterTree");
|
||||||
|
|
||||||
dojo.require("lib.CheckBoxTree");
|
dojo.require("lib.CheckBoxTree");
|
||||||
|
dojo.require("dojo.data.ItemFileWriteStore");
|
||||||
|
|
||||||
|
dojo.declare("fox.PrefFilterStore", dojo.data.ItemFileWriteStore, {
|
||||||
|
|
||||||
|
_saveEverything: function(saveCompleteCallback, saveFailedCallback,
|
||||||
|
newFileContentString) {
|
||||||
|
|
||||||
|
dojo.xhrPost({
|
||||||
|
url: "backend.php",
|
||||||
|
content: {op: "pref-filters", method: "savefilterorder",
|
||||||
|
payload: newFileContentString},
|
||||||
|
error: saveFailedCallback,
|
||||||
|
load: saveCompleteCallback});
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
dojo.declare("fox.PrefFilterTree", lib.CheckBoxTree, {
|
dojo.declare("fox.PrefFilterTree", lib.CheckBoxTree, {
|
||||||
_createTreeNode: function(args) {
|
_createTreeNode: function(args) {
|
||||||
|
@ -48,5 +64,17 @@ dojo.declare("fox.PrefFilterTree", lib.CheckBoxTree, {
|
||||||
return (!item.error || item.error == '') ? "dijitTreeRow" :
|
return (!item.error || item.error == '') ? "dijitTreeRow" :
|
||||||
"dijitTreeRow Error";
|
"dijitTreeRow Error";
|
||||||
},
|
},
|
||||||
|
checkItemAcceptance: function(target, source, position) {
|
||||||
|
var item = dijit.getEnclosingWidget(target).item;
|
||||||
|
|
||||||
|
// disable copying items
|
||||||
|
source.copyState = function() { return false; };
|
||||||
|
|
||||||
|
return position != 'over';
|
||||||
|
},
|
||||||
|
onDndDrop: function() {
|
||||||
|
this.inherited(arguments);
|
||||||
|
this.tree.model.store.save();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
18
js/prefs.js
18
js/prefs.js
|
@ -1563,6 +1563,24 @@ function clearArticleAccessKeys() {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetFilterOrder() {
|
||||||
|
try {
|
||||||
|
notify_progress("Loading, please wait...");
|
||||||
|
|
||||||
|
new Ajax.Request("backend.php", {
|
||||||
|
parameters: "?op=pref-filters&method=filtersortreset",
|
||||||
|
onComplete: function(transport) {
|
||||||
|
updateFilterList();
|
||||||
|
} });
|
||||||
|
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
exception_error("resetFilterOrder");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function resetFeedOrder() {
|
function resetFeedOrder() {
|
||||||
try {
|
try {
|
||||||
notify_progress("Loading, please wait...");
|
notify_progress("Loading, please wait...");
|
||||||
|
|
Loading…
Reference in New Issue