merging admin interface from the dojo-admin branch
[Evergreen.git] / Open-ILS / web / conify / global / actor / org_unit_type.html
1 <!--
2 # Copyright (C) 2008  Georgia Public Library Service / Equinox Software, Inc
3 # Mike Rylander <miker@esilibrary.com>
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 -->
15 <html xmlns="http://www.w3.org/1999/xhtml">
16         <head>
17                 <title>Confiy :: Global :: Actor :: Org Unit Types</title>
18
19                 <style type="text/css">
20                         @import url("/js/dojo/dojo/resources/dojo.css");
21                         @import url("/js/dojo/dijit/themes/tundra/tundra.css");
22                         @import url("/js/dojo/dojox/widget/Toaster/Toaster.css");
23                 </style>
24
25                 <style>
26                         html, body
27                         {
28                                 height: 100%;
29                                 width: 100%;
30                                 margin: 0px 0px 0px 0px;
31                                 padding: 0px 0px 0px 0px;
32                                 overflow: hidden;
33                         }
34
35                         th
36                         {
37                                 text-align: right;
38                                 font-weight: bold;
39                                 padding-left: 20px;
40                                 padding-right: 5px;
41                         }
42                 </style>
43
44                 <!-- The OpenSRF API writ JS -->
45                 <script language='javascript' src='/opac/common/js/utils.js' type='text/javascript'></script>
46                 <script language='javascript' src='/opac/common/js/Cookies.js' type='text/javascript'></script>
47                 <script language='javascript' src='/opac/common/js/CGI.js' type='text/javascript'></script>
48                 <script language='javascript' src='/opac/common/js/JSON_v1.js' type='text/javascript'></script>
49
50                 <!-- Fieldmapper objects -->
51                 <script language='javascript' src='/opac/common/js/fmall.js' type='text/javascript'></script>
52
53                 <!-- Dojo goodness -->
54                 <script type="text/javascript" src="/js/dojo/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
55                 <script type="text/javascript" src="/js/dojo/dijit/dijit.js"></script>
56
57                 <script type="text/javascript" src="org_unit_type.js"></script>
58
59         </head>
60
61         <body class="tundra" id='pagebody'>
62
63                 <div dojoType="dijit.layout.SplitContainer" orientation="horizontal" style="height: 100%">
64
65                         <div dojoType="dijit.layout.ContentPane" sizeShare="100">
66                                 <script type="dojo/method">
67                                         window.dirtyStore = [];
68
69                     pCRUD.request({
70                         method : 'open-ils.permacrud.search.aout.atomic',
71                         timeout : 10,
72                         params : [ ses, { id : { "!=" : null } }, { order_by : { aout : 'name' } } ],
73                         onerror : function (r) { status_update('Problem fetching types') },
74                         oncomplete : function (r) {
75                             ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( r.recv().content() ) });
76                             ou_type_store.onSet = function (item, attr, o, n) {
77                                 if (attr == 'ischanged') return;
78                                 if (n == o) return;
79                                 this.setValue( item, 'ischanged', 1);
80                             };
81                             dojo.addOnUnload( function (event) {
82
83                                 ou_type_store.fetch({
84                                     query : { ischanged : 1 },
85                                     queryOptions : { deep : true },
86                                     onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
87                                     scope : ou_type_store
88                                 });
89
90                                 if (dirtyStore.length > 0) {
91                                     var confirmation = confirm(
92                                         'There are unsaved modified Organization Types!  '+
93                                         'OK to save these changes, Cancel to abandon them.'
94                                     );
95
96                                     if (confirmation) {
97                                         for (var i in window.dirtyStore) {
98                                             window.current_type = window.dirtyStore[i];
99                                             save_type(true);
100                                         }
101                                     }
102                                 }
103
104                             });
105                         }
106                     }).send();
107
108                                 </script>
109                                 <div
110                                   id="type_tree"
111                                   label="Organization Types"
112                                   query="{'_top':'true'}"
113                                   dojoType="dijit.Tree"
114                                   store="ou_type_store"
115                                   minSize="200"
116                                   jsId="type_tree"
117                                 >
118
119                                         <script type="dojo/method" event="onClick" args="item,node">
120
121                                                 right_pane_toggler.show();
122                                                 current_type = item;
123
124                                                 highlighter.editor_pane.green.play();
125                                                 status_update( 'Now editing ' + this.store.getValue( item, 'name' ) );
126
127                                                 new_kid_button.disabled = false;
128                                                 save_out_button.disabled = false;
129                                                 delete_out_button.disabled = false;
130
131                                                 var main_settings_fields = [ 'name', 'opac_label'];
132                                                 for ( var i in main_settings_fields ) {
133                                                         var field = main_settings_fields[i];
134                                                         var value = this.store.getValue( current_type, field );
135
136                                                         if (!value) {
137                                                                 window["editor_pane_" + field].setValue( '' ); // unset the value
138                                                                 window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
139                                                         } else window["editor_pane_" + field].setValue( value );
140                                                 }
141
142                                                 if ( this.store.getValue( current_type, '_trueRoot' ) == 'true' ) {
143                                                         editor_pane_parent.disabled = true;
144                                                         editor_pane_parent.setValue(null);
145                                                         editor_pane_parent.setDisplayedValue('');
146                                                         editor_pane_parent.validate(false);
147                                                 } else {
148                                                         editor_pane_parent.disabled = false;
149                                                         editor_pane_parent.validate(true);
150                                                         editor_pane_parent.setValue( this.store.getValue( current_type, 'parent' ) );
151                                                 }
152
153                                                 editor_pane_can_have_vols.setChecked( this.store.getValue( current_type, 'can_have_vols' ) == 't' ? true : false );
154                                                 editor_pane_can_have_users.setChecked( this.store.getValue( current_type, 'can_have_users' ) == 't' ? true : false );
155
156                                         </script>
157
158                                         <script type="dojo/method" event="getLabel" args="item,pI">
159                                                 var label = this.store.getValue(item,'name');
160                                                 if (this.store.getValue(item,'ischanged') == 1) label = '* ' + label;
161                                                 return label;
162                                         </script>
163
164                                 </div>
165                         </div>
166
167                         <div id="right_pane" dojoType="dijit.layout.ContentPane"  sizeShare="200">
168                                 <script type="dojo/method">
169                                         window.right_pane_toggler = new dojo.fx.Toggler({ node: 'right_pane'});
170                                         window.right_pane_toggler.hide();
171                                 </script>
172
173                                         <div id="editor_pane" dojoType="dijit.layout.ContentPane">
174                                                 <script type="dojo/method">
175                                                         highlighter.type_tree = {};
176                                                         highlighter.editor_pane = {};
177                                                         highlighter.type_tree.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'type_tree', duration : 500 } );
178                                                         highlighter.type_tree.red = dojox.fx.highlight( { color : '#FF2018', node : 'type_tree', duration : 500 } );
179                                                         highlighter.editor_pane.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'editor_pane', duration : 500 } );
180                                                         highlighter.editor_pane.red = dojox.fx.highlight( { color : '#FF2018', node : 'editor_pane', duration : 500 } );
181                                                 </script>
182         
183                                                 <table class="tundra" style="margin:10px;">
184                                                         <tr>
185                                                                 <th>Type Name</th>
186                                                                 <td>
187                                                                         <span id="editor_pane_name" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_name" regExp=".+" required="true">
188                                                                                 <script type="dojo/connect" event="onChange">
189                                                                                         if (current_type) {
190                                                                                                 ou_type_store.setValue( current_type, "name", this.getValue() );
191                                                                                         }
192                                                                                 </script>
193                                                                         </span>
194                                                                 </td>
195                                                         </tr>
196                                                         <tr>
197                                                                 <th>OPAC Label</th>
198                                                                 <td>
199                                                                         <span id="editor_pane_opac_label" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_opac_label" regExp=".+" required="true">
200                                                                                 <script type="dojo/connect" event="onChange">
201                                                                                         if (current_type) {
202                                                                                                 ou_type_store.setValue( current_type, "opac_label", this.getValue() );
203                                                                                         }
204                                                                                 </script>
205                                                                         </span>
206                                                                 </td>
207                                                         </tr>
208                                                         <tr>
209                                                                 <th>Parent Type</th>
210                                                                 <td>
211                                                                         <div
212                                                                           id="editor_pane_parent"
213                                                                           dojoType="dijit.form.FilteringSelect"
214                                                                           jsId="editor_pane_parent"
215                                                                           store="ou_type_store"
216                                                                           searchAttr="name"
217                                                                           ignoreCase="true"
218                                                                           required="true"
219                                                                         >
220                                                                                 <script type="dojo/method" event="onChange" args=>
221                                                                                         if (current_type && this.getValue()) {
222                                                                                                 if ( this.store.getValue( current_type, 'parent' ) == this.getValue() ) return;
223
224                                                                                                 this.store.setValue( current_type, "parent", this.getValue() );
225                                                                                                 this.store.fetch({
226                                                                                                         query : { "parent" : this.getValue() },
227                                                                                                         onItem: function (parent_item) {
228                                                                                                                 this.setValue( current_type, 'depth', 1 + parseInt(this.getValue( parent_item, 'depth' ) ));
229                                                                                                         },
230                                                                                                         scope : ou_type_store
231                                                                                                 });
232                                                                                         }
233                                                                                 </script>
234                                                                         </div>
235                                                                 </td>
236                                                         </tr>
237                                                         <tr>
238                                                                 <th>Can have Volumes/Copies</th>
239                                                                 <td>
240                                                                         <input
241                                                                           id="editor_pane_can_have_vols"
242                                                                           jsId="editor_pane_can_have_vols"
243                                                                           type="checkbox"
244                                                                           dojoType="dijit.form.CheckBox"
245                                                                           onChange='if (current_type) ou_type_store.setValue( current_type, "can_have_vols", this.checked ? "t" : "f" );'
246                                                                         />
247                                                                 </td>
248                                                         </tr>
249                                                         <tr>
250                                                                 <th>Can have Users</th>
251                                                                 <td>
252                                                                         <input
253                                                                           id="editor_pane_can_have_users"
254                                                                           jsId="editor_pane_can_have_users"
255                                                                           type="checkbox"
256                                                                           dojoType="dijit.form.CheckBox"
257                                                                           onChange='if (current_type) ou_type_store.setValue( current_type, "can_have_users", this.checked ? "t" : "f" );'
258                                                                         />
259                                                                 </td>
260                                                         </tr>
261                                                 </table>
262         
263                                                 <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 20px;">
264         
265                                                         <button jsId="save_out_button" dojoType="dijit.form.Button" label="Save" onClick="save_type()">
266                                                                 <script type="dojo/connect" event="startup">
267                                                                         this.disabled = true;
268                                                                 </script>
269                                                         </button>
270         
271                                                         <button jsId="delete_out_button" dojoType="dijit.form.Button" label="Delete">
272                                                                 <script type="dojo/connect" event="startup">
273                                                                         this.disabled = true;
274                                                                 </script>
275                                                                 <script type="dojo/connect" event="onClick">
276         
277                                                                         if (ou_type_store.getValue( current_type, '_trueRoot' ) == 'true') {
278                                                                                 highlighter.editor_pane.red.play();
279                                                                                 status_update( 'Cannot delete' + ou_type_store.getValue( current_type, 'name' ) + ', you need at least one.' );
280                                                                                 return false;
281                                                                         }
282
283                                                                         if ( current_type.children ) {
284                                                                                 var kids = current_type.children;
285                                                                                 if (!dojo.isArray(kids)) kids = [kids];
286         
287                                                                                 var existing_kids = dojo.filter(
288                                                                                         kids,
289                                                                                         function(kid){ return kid.isdeleted[0] != 1 }
290                                                                                 );
291                                                                                 if ( existing_kids.length > 0) {
292                                                                                         highlighter.editor_pane.red.play();
293                                                                                         status_update( 'Cannot delete' + ou_type_store.getValue( current_type, 'name' ) + ', ' + existing_kids.length + ' subordinates still exist.' );
294                                                                                         return;
295                                                                                 }
296                                                                         }
297         
298                                                                         if ( confirm('Are you sure you want to delete ' + current_type.name + '?')) {
299                                                                                 ou_type_store.setValue( current_type, 'isdeleted', 1 );
300         
301                                                                                 var modified_aout = new aout().fromStoreItem( current_type );
302                                                                                 modified_aout.isdeleted( 1 );
303         
304                                                                                 pCRUD.request({
305                                                                                         method : 'open-ils.permacrud.delete.aout',
306                                                                                         timeout : 10,
307                                                                                         params : [ ses, modified_aout ],
308                                                                                         onerror : function (r) {
309                                                                                                 highlighter.editor_pane.red.play();
310                                                                                                 status_update( 'Problem deleting ' + ou_type_store.getValue( current_type, 'name' ) );
311                                                                                         },
312                                                                                         oncomplete : function (r) {
313                                                                                                 var res = r.recv();
314                                                                                                 if ( res && res.content() ) {
315         
316                                                                                                         var old_name = ou_type_store.getValue( current_type, 'name' );
317
318                                                                                                         ou_type_store.fetch({
319                                                                                                                 query : { id : ou_type_store.getValue( current_type, 'id' ) },
320                                                                                                                 queryOptions : { deep : true },
321                                                                                                                 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
322                                                                                                                 scope : ou_type_store
323                                                                                                         });
324         
325                                                                                                         current_type = null;
326         
327                                                                                                         new_kid_button.disabled = true;
328                                                                                                         save_out_button.disabled = true;
329                                                                                                         delete_out_button.disabled = true;
330                         
331                                                                                                         var main_settings_fields = [ 'name', 'opac_label' ];
332                                                                                                         for ( var i in main_settings_fields ) {
333                                                                                                                 var field = main_settings_fields[i];
334                                                                                                                 window["editor_pane_" + field].setValue( '' ); // unset the value
335                                                                                                                 window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
336                                                                                                         }
337
338                                                                                                         window["editor_pane_can_have_vols"].setChecked( false ); // unset the value
339                                                                                                         window["editor_pane_can_have_users"].setChecked( false ); // unset the value
340                         
341                                                                                                         highlighter.editor_pane.green.play();
342                                                                                                         status_update( old_name + ' deleted' );
343                                                                                                 } else {
344                                                                                                         highlighter.editor_pane.red.play();
345                                                                                                         status_update( 'Problem deleting ' + old_name );
346                                                                                                 }
347                                                                                         }
348                                                                                 }).send();
349         
350                                                                         }
351         
352                                                                 </script>
353                                                         </button>
354         
355                                                 </div>
356         
357                                                 <button jsId="new_kid_button" dojoType="dijit.form.Button" label="New Child">
358                                                         <script type="dojo/connect" event="startup">
359                                                                 this.disabled = true;
360                                                         </script>
361                                                         <script type="dojo/connect" event="onClick">
362         
363                                                                 var new_fm_obj = new aout().fromHash({
364                                                                         isnew                   : 1,
365                                                                         name                    : 'New Type',
366                                                                         can_have_vols   : 'f',
367                                                                         can_have_users  : 'f',
368                                                                         depth                   : 1 + parseInt(ou_type_store.getValue( current_type, 'depth' )),
369                                                                         opac_label              : ou_type_store.getValue( current_type, 'opac_label' ) + ' child' + virgin_out_id--,
370                                                                         parent                  : ou_type_store.getValue( current_type, 'id' )
371                                                                 });
372         
373                                                                 var err = false;
374                                                                 pCRUD.request({
375                                                                         method : 'open-ils.permacrud.create.aout',
376                                                                         timeout : 10,
377                                                                         params : [ ses, new_fm_obj ],
378                                                                         onerror : function (r) {
379                                                                                 highlighter.editor_pane.red.play();
380                                                                                 status_update( 'Problem calling method to create child Org Type' );
381                                                                                 err = true;
382                                                                         },
383                                                                         oncomplete : function (r) {
384                                                                                 var res = r.recv();
385                                                                                 if ( res && res.content() ) {
386                                                                                         ou_type_store.newItem(
387                                                                                                 res.content().toHash(),
388                                                                                                 { parent : current_type, attribute : 'children' }
389                                                                                         );
390                                                                                 } else {
391                                                                                         highlighter.editor_pane.red.play();
392                                                                                         status_update( 'Problem creating child Org Type' );
393                                                                                         err = true;
394                                                                                 }
395                                                                         },
396                                                                 }).send();
397         
398                                                                 if (!err) {
399                                                                         highlighter.editor_pane.green.play();
400                                                                         highlighter.type_tree.green.play();
401                                                                         status_update( 'New child Organization Type created for ' + ou_type_store.getValue( current_type, 'name' ) );
402                                                                 }
403         
404                                                         </script>
405                                                 </button>
406         
407                                         </div>
408                                 </div>
409                         </div>
410                 </div>
411         </body>
412 </html>