load fmall.js via dojo in fieldmapper.Fieldmapper
[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                 <!-- Dojo goodness -->
51                 <script type="text/javascript" src="../admin.js"></script>
52                 <script type="text/javascript" src="/js/dojo/dojo/dojo.js"</script>
53                 <script type="text/javascript" src="/js/dojo/dijit/dijit.js"></script>
54
55                 <script type="text/javascript" src="org_unit_type.js"></script>
56
57         </head>
58
59         <body class="tundra" id='pagebody'>
60
61                 <div dojoType="dijit.layout.SplitContainer" orientation="horizontal" style="height: 100%">
62
63                         <div dojoType="dijit.layout.ContentPane" sizeShare="100">
64                                 <script type="dojo/method">
65                                         window.dirtyStore = [];
66
67                     pCRUD.request({
68                         method : 'open-ils.permacrud.search.aout.atomic',
69                         timeout : 10,
70                         params : [ ses, { id : { "!=" : null } }, { order_by : { aout : 'name' } } ],
71                         onerror : function (r) { status_update('Problem fetching types') },
72                         oncomplete : function (r) {
73                             ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( r.recv().content() ) });
74                             ou_type_store.onSet = function (item, attr, o, n) {
75                                 if (attr == 'ischanged') return;
76                                 if (n == o) return;
77                                 this.setValue( item, 'ischanged', 1);
78                             };
79                             dojo.addOnUnload( function (event) {
80
81                                 ou_type_store.fetch({
82                                     query : { ischanged : 1 },
83                                     queryOptions : { deep : true },
84                                     onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
85                                     scope : ou_type_store
86                                 });
87
88                                 if (dirtyStore.length > 0) {
89                                     var confirmation = confirm(
90                                         'There are unsaved modified Organization Types!  '+
91                                         'OK to save these changes, Cancel to abandon them.'
92                                     );
93
94                                     if (confirmation) {
95                                         for (var i in window.dirtyStore) {
96                                             window.current_type = window.dirtyStore[i];
97                                             save_type(true);
98                                         }
99                                     }
100                                 }
101
102                             });
103                         }
104                     }).send();
105
106                                 </script>
107                                 <div
108                                   id="type_tree"
109                                   label="Organization Types"
110                                   query="{'_top':'true'}"
111                                   dojoType="dijit.Tree"
112                                   store="ou_type_store"
113                                   minSize="200"
114                                   jsId="type_tree"
115                                 >
116
117                                         <script type="dojo/method" event="onClick" args="item,node">
118
119                                                 right_pane_toggler.show();
120                                                 current_type = item;
121                                                 current_fm_type = new aout().fromStoreItem(item);
122
123                                                 highlighter.editor_pane.green.play();
124                                                 status_update( 'Now editing ' + this.store.getValue( item, 'name' ) );
125
126                                                 new_kid_button.disabled = false;
127                                                 save_out_button.disabled = false;
128                                                 delete_out_button.disabled = false;
129
130                                                 var main_settings_fields = [ 'name', 'opac_label'];
131                                                 for ( var i in main_settings_fields ) {
132                                                         var field = main_settings_fields[i];
133                                                         var value = this.store.getValue( current_type, field );
134
135                                                         if (!value) {
136                                                                 window["editor_pane_" + field].setValue( '' ); // unset the value
137                                                                 window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
138                                                         } else window["editor_pane_" + field].setValue( value );
139                                                 }
140
141                                                 if ( this.store.getValue( current_type, '_trueRoot' ) == 'true' ) {
142                                                         editor_pane_parent.disabled = true;
143                                                         editor_pane_parent.setValue(null);
144                                                         editor_pane_parent.setDisplayedValue('');
145                                                         editor_pane_parent.validate(false);
146                                                 } else {
147                                                         editor_pane_parent.disabled = false;
148                                                         editor_pane_parent.validate(true);
149                                                         editor_pane_parent.setValue( this.store.getValue( current_type, 'parent' ) );
150                                                 }
151
152                                                 editor_pane_can_have_vols.setChecked( this.store.getValue( current_type, 'can_have_vols' ) == 't' ? true : false );
153                                                 editor_pane_can_have_users.setChecked( this.store.getValue( current_type, 'can_have_users' ) == 't' ? true : false );
154
155                                         </script>
156
157                                         <script type="dojo/method" event="getLabel" args="item,pI">
158                                                 var label = this.store.getValue(item,'name');
159                                                 if (this.store.getValue(item,'ischanged') == 1) label = '* ' + label;
160                                                 return label;
161                                         </script>
162
163                                 </div>
164                         </div>
165
166                         <div id="right_pane" dojoType="dijit.layout.ContentPane"  sizeShare="200">
167                                 <script type="dojo/method">
168                                         window.right_pane_toggler = new dojo.fx.Toggler({ node: 'right_pane'});
169                                         window.right_pane_toggler.hide();
170                                 </script>
171
172                                         <div id="editor_pane" dojoType="dijit.layout.ContentPane">
173                                                 <script type="dojo/method">
174                                                         highlighter.type_tree = {};
175                                                         highlighter.editor_pane = {};
176                                                         highlighter.type_tree.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'type_tree', duration : 500 } );
177                                                         highlighter.type_tree.red = dojox.fx.highlight( { color : '#FF2018', node : 'type_tree', duration : 500 } );
178                                                         highlighter.editor_pane.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'editor_pane', duration : 500 } );
179                                                         highlighter.editor_pane.red = dojox.fx.highlight( { color : '#FF2018', node : 'editor_pane', duration : 500 } );
180                                                 </script>
181         
182                                                 <table class="tundra" style="margin:10px;">
183                                                         <tr>
184                                                                 <th>Type Name</th>
185                                                                 <td>
186                                                                         <span id="editor_pane_name" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_name" regExp=".+" required="true">
187                                                                                 <script type="dojo/connect" event="onChange">
188                                                                                         if (current_type) {
189                                                                                                 ou_type_store.setValue( current_type, "name", this.getValue() );
190                                                                                         }
191                                                                                 </script>
192                                                                         </span>
193                                                                         <span dojoType="openils.I18N.translationWidget" targetObject="current_fm_type" field="name"></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                                                                         <span dojoType="openils.I18N.translationWidget" targetObject="current_fm_type" field="opac_label"></span>
207                                                                 </td>
208                                                         </tr>
209                                                         <tr>
210                                                                 <th>Parent Type</th>
211                                                                 <td>
212                                                                         <div
213                                                                           id="editor_pane_parent"
214                                                                           dojoType="dijit.form.FilteringSelect"
215                                                                           jsId="editor_pane_parent"
216                                                                           store="ou_type_store"
217                                                                           searchAttr="name"
218                                                                           ignoreCase="true"
219                                                                           required="true"
220                                                                         >
221                                                                                 <script type="dojo/method" event="onChange" args=>
222                                                                                         if (current_type && this.getValue()) {
223                                                                                                 if ( this.store.getValue( current_type, 'parent' ) == this.getValue() ) return;
224
225                                                                                                 this.store.setValue( current_type, "parent", this.getValue() );
226                                                                                                 this.store.fetch({
227                                                                                                         query : { "parent" : this.getValue() },
228                                                                                                         onItem: function (parent_item) {
229                                                                                                                 this.setValue( current_type, 'depth', 1 + parseInt(this.getValue( parent_item, 'depth' ) ));
230                                                                                                         },
231                                                                                                         scope : ou_type_store
232                                                                                                 });
233                                                                                         }
234                                                                                 </script>
235                                                                         </div>
236                                                                 </td>
237                                                         </tr>
238                                                         <tr>
239                                                                 <th>Can have Volumes/Copies</th>
240                                                                 <td>
241                                                                         <input
242                                                                           id="editor_pane_can_have_vols"
243                                                                           jsId="editor_pane_can_have_vols"
244                                                                           type="checkbox"
245                                                                           dojoType="dijit.form.CheckBox"
246                                                                           onChange='if (current_type) ou_type_store.setValue( current_type, "can_have_vols", this.checked ? "t" : "f" );'
247                                                                         />
248                                                                 </td>
249                                                         </tr>
250                                                         <tr>
251                                                                 <th>Can have Users</th>
252                                                                 <td>
253                                                                         <input
254                                                                           id="editor_pane_can_have_users"
255                                                                           jsId="editor_pane_can_have_users"
256                                                                           type="checkbox"
257                                                                           dojoType="dijit.form.CheckBox"
258                                                                           onChange='if (current_type) ou_type_store.setValue( current_type, "can_have_users", this.checked ? "t" : "f" );'
259                                                                         />
260                                                                 </td>
261                                                         </tr>
262                                                 </table>
263         
264                                                 <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 20px;">
265         
266                                                         <button jsId="save_out_button" dojoType="dijit.form.Button" label="Save" onClick="save_type()">
267                                                                 <script type="dojo/connect" event="startup">
268                                                                         this.disabled = true;
269                                                                 </script>
270                                                         </button>
271         
272                                                         <button jsId="delete_out_button" dojoType="dijit.form.Button" label="Delete">
273                                                                 <script type="dojo/connect" event="startup">
274                                                                         this.disabled = true;
275                                                                 </script>
276                                                                 <script type="dojo/connect" event="onClick">
277         
278                                                                         if (ou_type_store.getValue( current_type, '_trueRoot' ) == 'true') {
279                                                                                 highlighter.editor_pane.red.play();
280                                                                                 status_update( 'Cannot delete' + ou_type_store.getValue( current_type, 'name' ) + ', you need at least one.' );
281                                                                                 return false;
282                                                                         }
283
284                                                                         if ( current_type.children ) {
285                                                                                 var kids = current_type.children;
286                                                                                 if (!dojo.isArray(kids)) kids = [kids];
287         
288                                                                                 var existing_kids = dojo.filter(
289                                                                                         kids,
290                                                                                         function(kid){ return kid.isdeleted[0] != 1 }
291                                                                                 );
292                                                                                 if ( existing_kids.length > 0) {
293                                                                                         highlighter.editor_pane.red.play();
294                                                                                         status_update( 'Cannot delete' + ou_type_store.getValue( current_type, 'name' ) + ', ' + existing_kids.length + ' subordinates still exist.' );
295                                                                                         return;
296                                                                                 }
297                                                                         }
298         
299                                                                         if ( confirm('Are you sure you want to delete ' + current_type.name + '?')) {
300                                                                                 ou_type_store.setValue( current_type, 'isdeleted', 1 );
301         
302                                                                                 var modified_aout = new aout().fromStoreItem( current_type );
303                                                                                 modified_aout.isdeleted( 1 );
304         
305                                                                                 pCRUD.request({
306                                                                                         method : 'open-ils.permacrud.delete.aout',
307                                                                                         timeout : 10,
308                                                                                         params : [ ses, modified_aout ],
309                                                                                         onerror : function (r) {
310                                                                                                 highlighter.editor_pane.red.play();
311                                                                                                 status_update( 'Problem deleting ' + ou_type_store.getValue( current_type, 'name' ) );
312                                                                                         },
313                                                                                         oncomplete : function (r) {
314                                                                                                 var res = r.recv();
315                                                                                                 if ( res && res.content() ) {
316         
317                                                                                                         var old_name = ou_type_store.getValue( current_type, 'name' );
318
319                                                                                                         ou_type_store.fetch({
320                                                                                                                 query : { id : ou_type_store.getValue( current_type, 'id' ) },
321                                                                                                                 queryOptions : { deep : true },
322                                                                                                                 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
323                                                                                                                 scope : ou_type_store
324                                                                                                         });
325         
326                                                                                                         current_type = null;
327         
328                                                                                                         new_kid_button.disabled = true;
329                                                                                                         save_out_button.disabled = true;
330                                                                                                         delete_out_button.disabled = true;
331                         
332                                                                                                         var main_settings_fields = [ 'name', 'opac_label' ];
333                                                                                                         for ( var i in main_settings_fields ) {
334                                                                                                                 var field = main_settings_fields[i];
335                                                                                                                 window["editor_pane_" + field].setValue( '' ); // unset the value
336                                                                                                                 window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
337                                                                                                         }
338
339                                                                                                         window["editor_pane_can_have_vols"].setChecked( false ); // unset the value
340                                                                                                         window["editor_pane_can_have_users"].setChecked( false ); // unset the value
341                         
342                                                                                                         highlighter.editor_pane.green.play();
343                                                                                                         status_update( old_name + ' deleted' );
344                                                                                                 } else {
345                                                                                                         highlighter.editor_pane.red.play();
346                                                                                                         status_update( 'Problem deleting ' + old_name );
347                                                                                                 }
348                                                                                         }
349                                                                                 }).send();
350         
351                                                                         }
352         
353                                                                 </script>
354                                                         </button>
355         
356                                                 </div>
357         
358                                                 <button jsId="new_kid_button" dojoType="dijit.form.Button" label="New Child">
359                                                         <script type="dojo/connect" event="startup">
360                                                                 this.disabled = true;
361                                                         </script>
362                                                         <script type="dojo/connect" event="onClick">
363         
364                                                                 var new_fm_obj = new aout().fromHash({
365                                                                         isnew                   : 1,
366                                                                         name                    : 'New Type',
367                                                                         can_have_vols   : 'f',
368                                                                         can_have_users  : 'f',
369                                                                         depth                   : 1 + parseInt(ou_type_store.getValue( current_type, 'depth' )),
370                                                                         opac_label              : ou_type_store.getValue( current_type, 'opac_label' ) + ' child' + virgin_out_id--,
371                                                                         parent                  : ou_type_store.getValue( current_type, 'id' )
372                                                                 });
373         
374                                                                 var err = false;
375                                                                 pCRUD.request({
376                                                                         method : 'open-ils.permacrud.create.aout',
377                                                                         timeout : 10,
378                                                                         params : [ ses, new_fm_obj ],
379                                                                         onerror : function (r) {
380                                                                                 highlighter.editor_pane.red.play();
381                                                                                 status_update( 'Problem calling method to create child Org Type' );
382                                                                                 err = true;
383                                                                         },
384                                                                         oncomplete : function (r) {
385                                                                                 var res = r.recv();
386                                                                                 if ( res && res.content() ) {
387                                                                                         ou_type_store.newItem(
388                                                                                                 res.content().toHash(),
389                                                                                                 { parent : current_type, attribute : 'children' }
390                                                                                         );
391                                                                                 } else {
392                                                                                         highlighter.editor_pane.red.play();
393                                                                                         status_update( 'Problem creating child Org Type' );
394                                                                                         err = true;
395                                                                                 }
396                                                                         },
397                                                                 }).send();
398         
399                                                                 if (!err) {
400                                                                         highlighter.editor_pane.green.play();
401                                                                         highlighter.type_tree.green.play();
402                                                                         status_update( 'New child Organization Type created for ' + ou_type_store.getValue( current_type, 'name' ) );
403                                                                 }
404         
405                                                         </script>
406                                                 </button>
407         
408                                         </div>
409                                 </div>
410                         </div>
411                 </div>
412         </body>
413 </html>