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