From 2e985d173352487f96984577ac512a3639267edf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 11:34:57 +0300 Subject: [PATCH] move some label helper functions to prefLabelTree --- classes/pref/labels.php | 4 +-- js/PrefLabelTree.js | 55 ++++++++++++++++++++++++++++++++++++++++- js/prefs.js | 54 ---------------------------------------- 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/classes/pref/labels.php b/classes/pref/labels.php index 1dbe3e18c..ae68a6eb7 100644 --- a/classes/pref/labels.php +++ b/classes/pref/labels.php @@ -278,10 +278,10 @@ class Pref_Labels extends Handler_Protected { print" "; - print " "; - print ""; diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 7321b80d8..c4c3ea103 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -37,7 +37,60 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f getIconClass: function (item, opened) { return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible"; }, - }); + getSelectedLabels: function() { + const tree = dijit.byId("labelTree"); + const items = tree.model.getCheckedItems(); + const rv = []; + + items.each(function(item) { + rv.push(tree.model.store.getValue(item, 'bare_id')); + }); + + return rv; + }, + resetColors: function() { + const labels = this.getSelectedLabels(); + + if (labels.length > 0) { + if (confirm(__("Reset selected labels to default colors?"))) { + + const query = { + op: "pref-labels", method: "colorreset", + ids: labels.toString() + }; + + xhrPost("backend.php", query, () => { + updateLabelList(); + }); + } + + } else { + alert(__("No labels are selected.")); + } + }, + removeSelected: function() { + const sel_rows = this.getSelectedLabels(); + + if (sel_rows.length > 0) { + if (confirm(__("Remove selected labels?"))) { + notify_progress("Removing selected labels..."); + + const query = { + op: "pref-labels", method: "remove", + ids: sel_rows.toString() + }; + + xhrPost("backend.php", query, () => { + updateLabelList(); + }); + } + } else { + alert(__("No labels are selected.")); + } + + return false; + } +}); }); diff --git a/js/prefs.js b/js/prefs.js index c2ff01d47..05023b053 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -316,19 +316,6 @@ function editFilter(id) { dialog.show(); } - -function getSelectedLabels() { - const tree = dijit.byId("labelTree"); - const items = tree.model.getCheckedItems(); - const rv = []; - - items.each(function(item) { - rv.push(tree.model.store.getValue(item, 'bare_id')); - }); - - return rv; -} - function getSelectedUsers() { return Tables.getSelected("prefUserList"); } @@ -372,28 +359,6 @@ function getSelectedFilters() { } -function removeSelectedLabels() { - - const sel_rows = getSelectedLabels(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected labels?"))) { - notify_progress("Removing selected labels..."); - - const query = { op: "pref-labels", method: "remove", - ids: sel_rows.toString() }; - - xhrPost("backend.php", query, () => { - updateLabelList(); - }); - } - } else { - alert(__("No labels are selected.")); - } - - return false; -} - function removeSelectedUsers() { const sel_rows = getSelectedUsers(); @@ -906,25 +871,6 @@ function opmlRegenKey() { return false; } -function labelColorReset() { - const labels = getSelectedLabels(); - - if (labels.length > 0) { - if (confirm(__("Reset selected labels to default colors?"))) { - - const query = { op: "pref-labels", method: "colorreset", - ids: labels.toString() }; - - xhrPost("backend.php", query, () => { - updateLabelList(); - }); - } - - } else { - alert(__("No labels are selected.")); - } -} - function editProfiles() { if (dijit.byId("profileEditDlg"))