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