Re-went through and cleaned up dom, I must have missed a close bracket or
authorJoseph Lewis <joehms22@gmail.com>
Tue, 21 Jun 2011 21:04:42 +0000 (15:04 -0600)
committerJoseph Lewis <joehms22@gmail.com>
Tue, 21 Jun 2011 21:04:42 +0000 (15:04 -0600)
something earlier that made the whole thing show up as a blank page.

Signed-off-by: Joseph Lewis <joehms22@gmail.com>
Open-ILS/web/js/ui/default/conify/global/config/circ_matrix_matchpoint.js
Open-ILS/web/templates/default/conify/global/config/circ_matrix_matchpoint.tt2

index 1549e5c..edb9ad4 100644 (file)
@@ -207,6 +207,215 @@ function applyCircModChanges() {
 
 openils.Util.addOnLoad(load);
 
+dojo.require('dijit.layout.ContentPane');
+dojo.require('dijit.form.Button');
+dojo.require('openils.widget.AutoGrid');
+dojo.require('openils.widget.AutoFieldWidget');
+dojo.require('openils.PermaCrud');
+dojo.require('openils.widget.ProgressDialog');
+
+var circModEditor = null;
+var circModGroupTables = [];
+var circModGroupCache = {};
+var circModEntryCache = {};
+var matchPoint;
+
+function load(){
+    cmGrid.overrideWidgetArgs.grp = {hrbefore : true};
+    cmGrid.overrideWidgetArgs.is_renewal = {ternary : true};
+    cmGrid.overrideWidgetArgs.ref_flag = {ternary : true};
+    cmGrid.overrideWidgetArgs.juvenile_flag = {ternary : true};
+    cmGrid.overrideWidgetArgs.circulate = {inherits : true, hrbefore : true};
+    cmGrid.overrideWidgetArgs.duration_rule = {inherits : true};
+    cmGrid.overrideWidgetArgs.recurring_fine_rule = {inherits : true};
+    cmGrid.overrideWidgetArgs.max_fine_rule = {inherits : true};
+    cmGrid.overrideWidgetArgs.available_copy_hold_ratio = {inherits : true};
+    cmGrid.overrideWidgetArgs.total_copy_hold_ratio = {inherits : true};
+    cmGrid.overrideWidgetArgs.renewals = {inherits : true};
+    cmGrid.overrideWidgetArgs.grace_period = {inherits : true};
+    cmGrid.overrideWidgetArgs.hard_due_date = {inherits : true};
+    cmGrid.loadAll({order_by:{ccmm:'circ_modifier'}});
+    cmGrid.onEditPane = buildEditPaneAdditions;
+    circModEditor = dojo.byId('circ-mod-editor').parentNode.removeChild(dojo.byId('circ-mod-editor'));
+}
+
+function byName(name, ctxt) {
+    return dojo.query('[name=' + name + ']', ctxt)[0];
+}
+
+function buildEditPaneAdditions(editPane) {
+    if(!editPane.fmObject) return; 
+    var node = circModEditor.cloneNode(true);
+    var tableTmpl = node.removeChild(byName('circ-mod-group-table', node));
+    circModGroupTables = [];
+    matchPoint = editPane.fmObject.id();
+
+    byName('add-circ-mod-group', node).onclick = function() {
+        addCircModGroup(node, tableTmpl)
+    }
+
+    if(editPane.mode == 'update') {
+        var groups = new openils.PermaCrud().search('ccmcmt', {matchpoint: editPane.fmObject.id()});
+        dojo.forEach(groups, function(g) { addCircModGroup(node, tableTmpl, g); } );
+    } 
+
+    editPane.domNode.appendChild(node);
+}
+
+
+function addCircModGroup(node, tableTmpl, group) {
+
+    var table = tableTmpl.cloneNode(true);
+    var circModRowTmpl = byName('circ-mod-entry-tbody', table).removeChild(byName('circ-mod-entry-row', table));
+    circModGroupTables.push(table);
+
+    var entries = [];
+    if(group) {
+        entries = new openils.PermaCrud().search('ccmcmtm', {circ_mod_test : group.id()});
+        table.setAttribute('group', group.id());
+        circModGroupCache[group.id()] = group;
+        circModEntryCache[group.id()] = entries;
+    }
+
+    function addMod(code, name) {
+        name = name || code; // XXX
+        var row = circModRowTmpl.cloneNode(true);
+        byName('circ-mod', row).innerHTML = name;
+        byName('circ-mod', row).setAttribute('code', code);
+        byName('circ-mod-entry-tbody', table).appendChild(row);
+        byName('remove-circ-mod', row).onclick = function() {
+            byName('circ-mod-entry-tbody', table).removeChild(row);
+        }
+    }
+
+    dojo.forEach(entries, function(e) { addMod(e.circ_mod()); });
+
+    byName('circ-mod-count', table).value = (group) ? group.items_out() : 0;
+
+    var selector = new openils.widget.AutoFieldWidget({
+        fmClass : 'ccmcmtm',
+        fmField : 'circ_mod',
+        parentNode : byName('circ-mod-selector', table)
+    });
+    selector.build();
+
+    byName('add-circ-mod', table).onclick = function() {
+        addMod(selector.widget.attr('value'), selector.widget.attr('displayedValue'));
+    }
+
+    node.insertBefore(table, byName('add-circ-mod-group-span', node));
+    node.insertBefore(dojo.create('hr'), byName('add-circ-mod-group-span', node));
+}
+
+function applyCircModChanges() {
+    var pcrud = new openils.PermaCrud();
+    progressDialog.show(true);
+
+    for(var idx in circModGroupTables) {
+        var table = circModGroupTables[idx];
+        var gp = table.getAttribute('group');
+
+        var count = byName('circ-mod-count', table).value;
+        var mods = [];
+        var entries = [];
+
+        dojo.forEach(dojo.query('[name=circ-mod]', table), function(td) { 
+            mods.push(td.getAttribute('code'));
+        });
+
+        var group = circModGroupCache[gp];
+
+        if(!group) {
+
+            group = new fieldmapper.ccmcmt();
+            group.isnew(true);
+            dojo.forEach(mods, function(mod) {
+                var entry = new fieldmapper.ccmcmtm();
+                entry.isnew(true);
+                entry.circ_mod(mod);
+                entries.push(entry);
+            });
+
+
+        } else {
+
+            var existing = circModEntryCache[group.id()];
+            dojo.forEach(mods, function(mod) {
+                
+                // new circ mod for this group
+                if(!existing.filter(function(i){ return (i.circ_mod() == mod)})[0]) {
+                    var entry = new fieldmapper.ccmcmtm();
+                    entry.isnew(true);
+                    entry.circ_mod(mod);
+                    entries.push(entry);
+                    entry.circ_mod_test(group.id());
+                }
+            });
+
+            dojo.forEach(existing, function(eMod) {
+                if(!mods.filter(function(i){ return (i == eMod.circ_mod()) })[0]) {
+                    eMod.isdeleted(true);
+                    entries.push(eMod);
+                }
+            });
+        }
+
+        group.items_out(count);
+        group.matchpoint(matchPoint);
+
+        if(group.isnew()) {
+
+            pcrud.create(group, {
+                oncomplete : function(r, cudResults) {
+                    var group = cudResults[0];
+                    dojo.forEach(entries, function(e) { e.circ_mod_test(group.id()) } );
+                    pcrud.create(entries, {
+                        oncomplete : function() {
+                            progressDialog.hide();
+                        }
+                    });
+                }
+            });
+
+        } else {
+
+            pcrud.update(group, {
+                oncomplete : function(r, cudResults) {
+                    var newOnes = entries.filter(function(e) { return e.isnew() });
+                    var delOnes = entries.filter(function(e) { return e.isdeleted() });
+                    if(!delOnes.length && !newOnes.length) {
+                        progressDialog.hide();
+                        return;
+                    }
+                    if(newOnes.length) {
+                        pcrud.create(newOnes, {
+                            oncomplete : function() {
+                                if(delOnes.length) {
+                                    pcrud.eliminate(delOnes, {
+                                        oncomplete : function() {
+                                            progressDialog.hide();
+                                        }
+                                    });
+                                } else {
+                                    progressDialog.hide();
+                                }
+                            }
+                        });
+                    } else {
+                        pcrud.eliminate(delOnes, {
+                            oncomplete : function() {
+                                progressDialog.hide();
+                            }
+                        });
+                    }
+                }
+            });
+        }
+    }
+}
+
+openils.Util.addOnLoad(load);
+
 function format_hard_due_date(name, id) {
     var item=this.grid.getItem(id);
     if(!item) return name;
index 6941bce..b107e06 100644 (file)
@@ -1,14 +1,14 @@
 [% ctx.page_title = 'Circulation Policy Configuration' %]
 [% WRAPPER default/base.tt2 %]
-<script type='text/javascript' src='[% ctx.media_prefix %]/js/ui/default/conify/global/config/circ_matrix_matchpoint.js' />
-<div dojoType='dijit.layout.ContentPane' layoutAlign='top' class='oils-header-panel'>
+<script type="text/javascript" src='[% ctx.media_prefix %]/js/ui/default/conify/global/config/circ_matrix_matchpoint.js'> </script>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="top" class='oils-header-panel'>
     <div>Circulation Policy Configuration</div>
     <div><button dojoType='dijit.form.Button' onClick='cmGrid.showCreatePane()'>New</button></div>
 </div>
-<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
-    <table  jsId="cmGrid"
-            style="height: 600px;"
-            dojoType="openils.widget.AutoGrid"
+<div dojoType='dijit.layout.ContentPane' layoutAlign='client'>
+    <table  jsId='cmGrid'
+            style='height: 600px;'
+            dojoType='openils.widget.AutoGrid'
             fieldOrder="['id', 'active', 'grp', 'org_unit', 'copy_circ_lib', 'copy_owning_lib', 'user_home_ou', 'is_renewal', 'juvenile_flag', 'circ_modifier', 'marc_type', 'marc_form', 'marc_bib_level', 'marc_vr_format', 'ref_flag', 'usr_age_lower_bound', 'usr_age_upper_bound', 'circulate', 'duration_rule', 'renewals', 'hard_due_date', 'recurring_fine_rule', 'grace_period', 'max_fine_rule', 'available_copy_hold_ratio', 'total_copy_hold_ratio', 'script_test']"
             defaultCellWidth='"auto"'
             query="{id: '*'}"
@@ -19,7 +19,7 @@
             columnPickerPrefix='"conify.config.circ_matrix_matchpoint"'>
             <thead>
                 <tr>
-                    <th field="hard_due_date" formatter="format_hard_due_date" />
+                    <th field='hard_due_date' formatter='format_hard_due_date' />
                 </tr>
             </thead>
     </table>
@@ -32,7 +32,7 @@
             <tbody>
                 <tr>
                     <td>Total items out</td>
-                    <td><input type='text' size='3' name='circ-mod-count' /></div></td>
+                    <td><input type='text' size='3' name='circ-mod-count'/></td>
                 </tr>
             <tbody>
             <tbody name='circ-mod-entry-tbody'>
             </tbody>
             <tbody>
                 <tr>
-                    <td><div name='circ-mod-selector'></div></td>
+                    <td><div name='circ-mod-selector'/></td>
                     <td><a href='javascript:void(0);' name='add-circ-mod'>Add</a></td>
                 </tr>
             </tbody>
         </table>
         <span name='add-circ-mod-group-span'>
             <a href='javascript:void(0);' name='add-circ-mod-group'>Create New Group</a>
-        </span>
-        &nbsp;&nbsp;
+        </span>&nbsp;&nbsp;
         <span>
             <a href='javascript:void(0);' onclick='applyCircModChanges()'>Apply Circ Modifier Changes</a>
         </span>
@@ -61,4 +60,3 @@
 <div class='hidden'><div dojoType='openils.widget.ProgressDialog' jsId='progressDialog'/></div>
 
 [% END %]
-