CAT-188 3.2 catalog fixes search templates WIP
authorKatlyn Beck <kbeck@catalyte.io>
Tue, 23 Oct 2018 16:19:01 +0000 (16:19 +0000)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Signed-off-by: Katlyn Beck <kbeck@catalyte.io>
 Changes to be committed:
modified:   KCLS/openils/var/templates_kcls/opac/parts/advanced/search.tt2
modified:   Open-ILS/web/js/ui/kcls/conify/global/config/search_templates.js

KCLS/openils/var/templates_kcls/opac/parts/advanced/search.tt2
Open-ILS/web/js/ui/kcls/conify/global/config/search_templates.js

index 37732d7..9133c82 100644 (file)
@@ -55,7 +55,7 @@
                                     <input type='checkbox' name="modifier"
                                         value="available"[% CGI.param('modifier').grep('available').size ? ' checked="checked"' : '' %]
                                         id='opac.result.limit2avail' />
-                                    <label style="position:relative;top:-2px;"
+                                    <label id="modifier" style="position:relative;top:-2px;"
                                         for='opac.result.limit2avail'>
                                         [% l("Limit to Available") %]</label>
                                 </div>
                     <br/>
                     <strong>[% l('Select Template') %]</strong>
                     <br/>
-                    <select id="templateList" onChange="selectSearchTemplateOrClearAll(this.value);">
+                    <select id="templateList" onClick="" onChange="selectSearchTemplateOrClearAll(this.value);">
                     </select>
+                    <br><br><br>
+                    <strong>[% l('Template Name') %]</strong>
+                    <br>
+                    <input id="nameInput" type="text">
+                    <button style="padding-left:5px;" onClick="templateActionSave();">[% l('Save Template') %]</button>
+                    <br><br>
+                    <button onClick="templateActionDelete();">[% l('Delete Template') %]</button>
                 </td>
-                    <td valign="top" class="hide_me">
-                   <select id="resultViewSel" name="detail_record_view" >
-                    <option value="0" selected="selected">Simple View</option>
-                    <option value="1">Detail View</option>
-                   </select>
+                <td valign="top" class="hide_me">
+                    <select id="resultViewSel" name="detail_record_view" >
+                        <option value="0" selected="selected">Simple View</option>
+                        <option value="1">Detail View</option>
+                    </select>
                 </td>
             [% END %]
         </tr>
index f4a0e09..0208227 100644 (file)
@@ -1,13 +1,13 @@
 
 
 var g = {};
-var templateList;
+var templateList = [];
 var template;
 var DEFAULT = "--Default--";
 var myPackageDir = 'open_ils_staff_client';
 
 function getSearchStash() {
-    return window.localStorage.getItem('eg.catalog.staff.search_templates') || [];
+    return JSON.parse(window.localStorage.getItem('eg.catalog.staff.search_templates')) || [];
 }
 
 function getXULSearchStash() {
@@ -43,9 +43,28 @@ function getXULSearchStash() {
     }
 }
 
+function templateActionSave() {
+    var nameInput = document.getElementById('nameInput').value;
+    create_template(nameInput);
+}
+
+function templateActionDelete() {
+    var nameInput = document.getElementById('nameInput').value;
+    var templateList = getSearchStash();
+    var tempTemplate = getTemplateByName(nameInput, templateList);
+    if (tempTemplate) {
+        if (confirm("Are you sure you want to delete Template '" + nameInput + "'?")) {
+            deleteTemplatefromTemplateList(nameInput, templateList);
+        }
+    } else {
+        alert("Template '" + nameInput + "' does not exist.");
+    }
+}
+
 //Creates, or edits, a search template based off the currently selected values
 function create_template(tName) {
     var template;
+    var templateList = getSearchStash();
     if (!tName || tName == DEFAULT)
     {
         alert("That is not a valid name.");
@@ -58,7 +77,7 @@ function create_template(tName) {
         var isNew = 1;
         template = new Object();
         populateTemplate(template);
-        this.template = template;
+        // this.template = template;
         templateList.push(template);
         templateList.sort(compareTemplateNames)
     }
@@ -72,8 +91,10 @@ function create_template(tName) {
         else
         { return;}
     }
-    saveCurrentTemplate( template );
-    saveTemplateList(templateList);
+    // saveCurrentTemplate( template );
+    saveCurrentTemplateToLocal(template);
+    // saveTemplateList(templateList);
+    saveTemplateListToLocal(templateList);
 
     //Add to templateSel and select if new template
     if(isNew)
@@ -113,6 +134,12 @@ function selectOptionValues(elmnt, values){
     }
 }
 
+//Saves templateList to local storage in JSON format
+function saveTemplateListToLocal(templateList) {
+    window.localStorage.setItem('eg.catalog.staff.search_templates', JSON.stringify(templateList));
+    alert("Template List has been updated.");
+}
+
 //Saves templateList to File in JSON format.
 function saveTemplateListToFile( templateList ) {
     try {
@@ -126,6 +153,11 @@ function saveTemplateListToFile( templateList ) {
         }
 }
 
+//Saves current template name to local storage
+function saveCurrentTemplateToLocal(template) {
+    window.localStorage.setItem('eg.catalog.staff.search_templates', JSON.stringify(template));
+}
+
 //Saves current template name to file
 function saveCurrentTemplateToFile( template ) {
     try {
@@ -140,6 +172,7 @@ function saveCurrentTemplateToFile( template ) {
 
 //Populates template dropdown from given template list
 function populateTemplateOptions(templateList)  {
+    var templateList = getSearchStash();
     templateSel.options.length = 0;
     templateSel.options[0]= new Option(DEFAULT, "");
 
@@ -262,8 +295,10 @@ function clearSearchFilters() {
 //Given a template name, saves template as the current search template if name found in TemplateList
 //Populates options, or not, accordingly
 function selectSearchTemplateOrClear(tName) {
+    var templateList = getSearchStash();
     template = getTemplateByName(tName, templateList);
-    saveCurrentTemplate( template )
+    // saveCurrentTemplate( template )
+    // saveCurrentTemplateToLocal(template);
 
     if (template)
     {
@@ -356,7 +391,8 @@ function compareTemplateNames(templateA,templateB) {
 function deleteTemplatefromTemplateList(tName, templateList) {
     var index = getTemplateIndex(tName, templateList);
     templateList.splice(index,1);
-    saveTemplateList(templateList);
+    // saveTemplateList(templateList);
+    saveTemplateListToLocal(templateList);
     return templateList;
 }
 
@@ -373,7 +409,8 @@ function removeTemplate(templateList, currentTemplate)  {
             //deleted template is the current template in use
             if (currentTemplate.name == tempTemplate.name)
             {
-                saveCurrentTemplate(null);
+                // saveCurrentTemplate(null);
+                saveCurrentTemplateToLocal(null);
                 clearOptions();
                 templateSel.selectedIndex = 0;
             }
@@ -402,7 +439,7 @@ function saveTemplateList(templateList) {
 function saveCurrentTemplate(template)  {
     g.data.current_search_template = template;
     g.data.stash('current_search_template');
-    saveCurrentTemplateToFile(template)
+    saveCurrentTemplateToFile(template);
 }
 
 //clears all global row input fields