Change order: filter set loading works. still need saving.
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 11 Sep 2012 22:34:02 +0000 (18:34 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 21 Sep 2012 15:07:01 +0000 (11:07 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/templates/url_verify/select_urls.tt2
Open-ILS/web/js/dojo/openils/widget/FlattenerGrid.js
Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js
Open-ILS/web/js/dojo/openils/widget/nls/PCrudFilterPane.js

index 95c91a1..2751e7e 100644 (file)
@@ -37,6 +37,7 @@
         autoCoreFields="true"
         autoCoreFieldsFilter="true"
         autoCoreFieldsUnsorted="true"
+        savedFiltersInterface="'url_verify'"
         fetchLock="true"
         mapExtras="{session_id: {path: 'session.id', filter: true}}"
         showLoadFilter="true"
index e97a918..a0756d9 100644 (file)
@@ -29,6 +29,7 @@ if (!dojo._hasResource["openils.widget.FlattenerGrid"]) {
             "filterWidgetBuilders": null,
             "filterSemaphore": null,
             "filterSemaphoreCallback": null,
+            "savedFiltersInterface": null,
 
             /* These potential constructor arguments may be useful to
              * FlattenerGrid in their own right, and are passed to
@@ -510,10 +511,10 @@ if (!dojo._hasResource["openils.widget.FlattenerGrid"]) {
                             "fmClass": this.fmClass,
                             "mapTerminii": this.mapTerminii,
                             "useDiv": this.filterAlwaysInDiv,
-                            "compact": true,
                             "initializers": this.filterInitializers,
                             "widgetBuilders": this.filterWidgetBuilders,
-                            "suppressFilterFields": this.suppressFilterFields
+                            "suppressFilterFields": this.suppressFilterFields,
+                            "savedFiltersInterface": this.savedFiltersInterface
                         });
 
                     this.filterUi.onApply = dojo.hitch(
index 205deb4..08a2641 100644 (file)
@@ -35,6 +35,8 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) {
     dojo.require('openils.widget.AutoFieldWidget');
     dojo.require('dijit.form.FilteringSelect');
     dojo.require('dijit.form.Button');
+    dojo.require('dijit.form.DropDownButton');
+    dojo.require('dijit.TooltipDialog');
     dojo.require('dojo.data.ItemFileReadStore');
     dojo.require('openils.Util');
 
@@ -570,6 +572,7 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) {
         };
 
         this.initialize = function(initializer) {
+            console.log("initializer is "  + dojo.toJson(initializer));
             this.field_selector.attr("value", initializer.field);
             this.operator_selector.attr("value", initializer.operator);
 
@@ -593,15 +596,16 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) {
         {
             "useDiv": null, /* should always be null for subclass dialogs */
             "initializers": null,
-            "compact": false,
             "widgetBuilders": null,
             "suppressFilterFields": null,
+            "savedFiltersInterface": null,
 
             "constructor": function(args) {
                 for(var k in args)
                     this[k] = args[k];
                 this.widgetIndex = 0;
                 this.widgetCache = {};
+                this.compact = Boolean(this.useDiv);
 
                 /* Meaningless in a pane, but better here than in
                  * PCrudFilterDialog so that we don't need to load i18n
@@ -609,6 +613,120 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) {
                 this.title = this.title || pcFilterLocaleStrings.DEFAULT_DIALOG_TITLE;
             },
 
+            "_buildSavedFilterControlsIfPerms": function(holder) {
+                (new openils.User()).getPermOrgList(
+                    "SAVED_FILTER_DIALOG_FILTERS",
+                    dojo.hitch(this, function(id_list) {
+                        this._buildSavedFilterControls(id_list, holder);
+                    }),
+                    true, true
+                );
+            },
+
+            "_buildSavedFilterControls": function(id_list, holder) {
+                if (!id_list || !id_list.length) {
+                    console.info("Not showing saved filter controls; no perm");
+                    return;
+                }
+
+                var fs_list = (new openils.PermaCrud()).search(
+                    "cfdfs", {
+                        "owning_lib": id_list,
+                        "interface": this.savedFiltersInterface
+                    }, {
+                        "order_by": [
+                            {"class": "cfdfs", "field": "owning_lib"},
+                            {"class": "cfdfs", "field": "name"}
+                        ],
+                        "async": true,
+                        "oncomplete": dojo.hitch(this, function(r) {
+                            if (r = openils.Util.readResponse(r)) {
+                                this._buildSavedFilterLoader(r, holder);
+                            }
+                        })
+                    }
+                );
+
+                this._buildSavedFilterSaver(holder);
+            },
+
+            "_buildSavedFilterLoader": function(fs_list, holder) {
+                var self = this;
+                var load_content = dojo.create(
+                    "div", {
+                        "innerHTML": pcFilterLocaleStrings.CHOOSE_FILTER_TO_LOAD
+                    }
+                );
+
+                var selector = dojo.create(
+                    "select", {
+                        "multiple": "multiple",
+                        "size": 4,
+                        "style": {
+                            "verticalAlign": "middle", "margin": "0 0.75em"
+                        }
+                    }, load_content, "last"
+                );
+
+                dojo.forEach(
+                    fs_list, function(fs) {
+                        dojo.create(
+                            "option", {
+                                "innerHTML": fs.name(),
+                                "value": dojo.toJson([fs.id(),
+                                    dojo.fromJson(fs.filters())])
+                            }, selector
+                        );
+                    }
+                );
+
+                var applicator = dojo.create(
+                    "a", {
+                        "href": "javascript:void(0);",
+                        "onclick": function() {
+                            dojo.filter(
+                                selector.options,
+                                function(o){return o.selected;}
+                            ).map(
+                                function(o){return dojo.fromJson(o.value)[1];}
+                            ).forEach(
+                                function(o){
+                                    o.forEach(
+                                        function(p) {
+                                            self.filter_row_manager.add_row(p);
+                                        }
+                                    );
+                                }
+                            );
+                            dijit.popup.close(self.filter_set_loader.dropDown);
+                        },
+                        "innerHTML": pcFilterLocaleStrings.APPLY
+                    }, load_content, "last"
+                );
+
+                this.filter_set_loader = new dijit.form.DropDownButton({
+                    "dropDown": new dijit.TooltipDialog({
+                        "content": load_content
+                    }),
+                    "label": pcFilterLocaleStrings.LOAD_FILTERS
+                }, dojo.create("span", {}, holder));
+            },
+
+            "_buildSavedFilterSaver": function(holder) {
+
+                var save = new dijit.TooltipDialog({
+                    "content": pcFilterLocaleStrings.NAME_SAVED_FILTER_SET +
+                        " <span id='fd-save-hold-input'></span><span id='fd-save-hold-apply'></span>"
+                });
+                new dijit.form.DropDownButton(
+                    {
+                        "dropDown": save,
+                        "label": pcFilterLocaleStrings.SAVE_FILTERS
+                    }, dojo.create("button", {}, holder)
+                );
+
+            },
+
             "_buildButtons": function() {
                 var self = this;
 
@@ -649,6 +767,9 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) {
                         }, dojo.create("span", {}, button_holder)
                     );
                 }
+
+                if (this.savedFiltersInterface)
+                    this._buildSavedFilterControlsIfPerms(button_holder);
             },
 
             "_buildFieldStore": function() {
index 8e76dd5..7e7128d 100644 (file)
@@ -16,5 +16,9 @@
     "DEFAULT_DIALOG_TITLE": "Filter Results",
     "ADD_ROW": "Add Row",
     "APPLY": "Apply",
-    "CANCEL": "Cancel"
+    "CANCEL": "Cancel",
+    "LOAD_FILTERS": "Load Filters",
+    "SAVE_FILTERS": "Save Filters",
+    "CHOOSE_FILTER_TO_LOAD": "Choose filter sets to load",
+    "NAME_SAVED_FILTER_SET": "Enter a name for your saved filter set:"
 }