]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/conify/global/config/coded_value_map.tt2
LP#1284864 coded value map cloning
[working/Evergreen.git] / Open-ILS / src / templates / conify / global / config / coded_value_map.tt2
1 [% WRAPPER base.tt2 %]
2 <h1>[% l('Coded Value Maps') %]</h1> <br/>
3
4 <div dojoType="dijit.layout.ContentPane" layoutAlign="client" class='oils-header-panel'>
5     <div>[% l('Coded Value Maps') %]</div>
6     <div>
7         <button dojoType='dijit.form.Button' onClick='ccvmGrid.showCreateDialog()'>[% l('New Map') %]</button>
8         <button dojoType='dijit.form.Button' onClick='ccvmGrid.deleteSelected()'>[% l('Delete Selected') %]</button>
9         <button dojoType='dijit.form.Button' onClick='ccvmGrid.showClonePane(handleClone)'>[% l('Clone Selected') %]</button>
10     </div>
11 </div>
12
13 <div dojoType="dijit.layout.ContentPane" layoutAlign="client">
14     <span>[% l('Record Attribute Type: ') %]</span><div id='attr-def-div'></div>
15 </div>
16
17 <div dojoType="dijit.layout.ContentPane" layoutAlign="client">
18     <table  jsId="ccvmGrid"
19             autoHeight='true'
20             dojoType="openils.widget.AutoGrid"
21             fieldOrder="['ctype', 'code', 'value', 'description', 'opac_visible', 'search_label', 'is_simple', 'composite_def']"
22             query="{code: '*'}"
23             defaultCellWidth='"25%"'
24             fmClass='ccvm'
25             showPaginator='true'
26             editOnEnter='true'>
27       <thead>
28         <tr><th field='composite_def' 
29                 get='getCompositeDefLink' 
30                 formatter='formatCompositeDefLink'>
31             [% l('Composite Definition') %]</th></tr>
32       </thead>
33     </table>
34  </div>
35
36 <script type ="text/javascript">
37
38     dojo.require('dijit.form.FilteringSelect');
39     dojo.require('openils.widget.AutoGrid');
40     dojo.require('openils.widget.AutoFieldWidget');
41     dojo.require('openils.PermaCrud');
42
43     function getCompositeDefLink(rowId, item) {
44       if (!item) return '';
45       return this.grid.store.getValue(item, 'id');
46     }
47
48     var isComposite = false;
49     function formatCompositeDefLink(id) {
50       if (id && isComposite) {
51         return "<a href='" + oilsBasePath +
52           "/conify/global/config/composite_attr_entry_definition/" 
53           + id + "'>[% l('Manage') %]</a>";
54         } else {
55           return "";
56       }
57     }
58
59     var cradName = '[% ctx.page_args.0 %]';
60
61     function handleClone(oldObj, newObj) {
62       if (!isComposite) return; // vanilla, non-composite clone
63
64       // fetch the composite def for the clone source object
65       var pcrud = new openils.PermaCrud();
66       pcrud.search('ccraed', {coded_value : oldObj.id}, {
67
68         oncomplete : function(r) {
69           composite_def = openils.Util.readResponse(r).pop();
70
71           // after cloning, jump to the composite def page
72           var dest = oilsBasePath
73             + '/conify/global/config/composite_attr_entry_definition/' 
74             + newObj.id();
75
76           if (!composite_def || !composite_def.definition()) {
77             // nothing to copy
78             location.href = dest;
79             return;
80           }
81
82           // copy the composite definition from the clone
83           // source object into the clone destination object
84           var new_def = new fieldmapper.ccraed();
85           new_def.coded_value(newObj.id());
86           new_def.definition(composite_def.definition());
87           pcrud.create(new_def, {
88             oncomplete : function(r) {
89               openils.Util.readResponse(r); // test for alerts
90               location.href = dest;
91             }
92           });
93         }
94       });
95     }
96
97     openils.Util.addOnLoad(
98         function() {
99
100             var selector = new openils.widget.AutoFieldWidget({
101                 fmClass : 'ccvm',
102                 fmField : 'ctype',
103                 parentNode : dojo.byId('attr-def-div')
104             });
105
106             selector.build(
107                 function(w, ww) {
108                     dojo.connect(w, 'onChange', 
109                         function(newVal) {
110
111                             // see if this attr def supports composite entries
112                             w.store.fetch({
113                               onComplete : function(list) {
114                                 if (!list.length) return;
115                                 var comp = w.store.getValue(list[0], 'composite');
116                                 if (comp == 't') {
117                                   isComposite = true;
118                                 } else {
119                                   isComposite = false;
120                                 }
121                               },
122                               query : {name : ''+newVal}
123                             });
124                             
125                             ccvmGrid.resetStore();
126                             ccvmGrid.loadAll({order_by : {ccvm : 'code'}}, {ctype : newVal});
127                             ccvmGrid.overrideWidgetArgs.ctype = {dijitArgs : {value : newVal}};
128                             // ^-- why is this not working?
129                         }
130                     );
131
132                     // if a crad is already selected via URL, fetch the ccvm's
133                     if (cradName) w.attr('value', cradName);
134                 }
135             );
136
137             // hide the progress indicator since we're not loading any data up front
138             dojo.style(ccvmGrid.loadProgressIndicator, 'visibility', 'hidden');
139         }
140     );
141
142 </script>
143
144 [% END %]