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