]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/conify/global/actor/org_unit_type.html
4b1e8438074ae5f96a7735472bc947df062bf516
[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
16 <!DOCTYPE html PUBLIC 
17         "-//W3C//DTD XHTML 1.0 Transitional//EN" 
18         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
19         <!--#include virtual="/opac/locale/${locale}/conify.dtd"-->
20 ]>
21
22 <html xmlns="http://www.w3.org/1999/xhtml">
23         <head>
24                 <title>&conify.org_unit_type.title;</title>
25
26                 <style type="text/css">
27                         @import url('/js/dojo/dojo/resources/dojo.css');
28                         @import url('/js/dojo/dijit/themes/tundra/tundra.css');
29                         @import url('/js/dojo/dojox/widget/Toaster/Toaster.css');
30                 </style>
31
32                 <style type="text/css">
33                         html, body
34                         {
35                                 height: 100%;
36                                 width: 100%;
37                                 margin: 0px 0px 0px 0px;
38                                 padding: 0px 0px 0px 0px;
39                                 overflow: hidden;
40                         }
41
42                         th
43                         {
44                                 text-align: right;
45                                 font-weight: bold;
46                                 padding-left: 20px;
47                                 padding-right: 5px;
48                         }
49                 </style>
50
51                 <!-- The OpenSRF API writ JS -->
52                 <script language='javascript' src='/IDL2js' type='text/javascript'></script>
53                 <script language='javascript' src='/opac/common/js/utils.js' type='text/javascript'></script>
54                 <script language='javascript' src='/opac/common/js/CGI.js' type='text/javascript'></script>
55                 <script language='javascript' src='/opac/common/js/JSON_v1.js' type='text/javascript'></script>
56
57                 <!-- Dojo goodness -->
58                 <script type="text/javascript" src="../admin.js"></script>
59                 <script type="text/javascript" src="/js/dojo/dojo/dojo.js"></script>
60                 <script type="text/javascript" src="/js/dojo/dojo/openils_dojo.js"></script>
61                 <script type="text/javascript" src="/js/dojo/dijit/dijit.js"></script>
62
63                 <script type="text/javascript" src="org_unit_type.js"></script>
64
65         <script type="text/javascript">
66 <![CDATA[
67             var dirtyStore = [];
68
69             var _out_type_list = pCRUD.retrieveAll('aout', { order_by : { aout : 'name' } });
70
71             var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( _out_type_list ) });
72
73             ou_type_store.onSet = function (item, attr, o, n) {
74                 if (attr == 'ischanged') return;
75                 if (n == o) return;
76                 this.setValue( item, 'ischanged', 1);
77             };
78
79             dojo.addOnUnload( function (event) {
80
81                 ou_type_store.fetch({
82                     query : { ischanged : 1 },
83                     queryOptions : { deep : true },
84                     onItem : function (item, req) { try { if (this.isItem( item )) dirtyStore.push( item ); } catch (e) { /* meh */ } },
85                     scope : ou_type_store
86                 });
87
88                 if (dirtyStore.length > 0) {
89                     var confirmation = confirm(
90                         aout_strings.CONFIRM_UNSAVED_CHANGES
91                     );
92
93                     if (confirmation) {
94                         for (var i in dirtyStore) {
95                             current_type = dirtyStore[i];
96                             save_type(true);
97                         }
98                     }
99                 }
100
101             });
102 ]]>
103         </script>
104
105         </head>
106
107         <body class="tundra" id='pagebody'>
108
109                 <div dojoType="dijit.layout.SplitContainer" orientation="horizontal" style="height: 100%">
110
111                         <div dojoType="dijit.layout.ContentPane" sizeShare="100">
112                                 <div
113                                   id="type_tree"
114                                   label="&conify.org_unit_type.type_tree.label;"
115                                   query="{'_top':'true'}"
116                                   dojoType="dijit.Tree"
117                                   store="ou_type_store"
118                                   minSize="200"
119                                   jsId="type_tree"
120                                 >
121
122                                         <script type="dojo/method" event="onClick" args="item,node">
123 <![CDATA[
124                                                 right_pane_toggler.show();
125                                                 current_type = item;
126                                                 current_fm_type = new aout().fromStoreItem(item);
127
128                                                 highlighter.editor_pane.green.play();
129                                                 status_update( dojo.string.substitute( aout_strings.STATUS_EDITING, [this.store.getValue( item, 'name' )] ) );
130
131                                                 new_kid_button.disabled = false;
132                                                 save_out_button.disabled = false;
133                                                 delete_out_button.disabled = false;
134
135                                                 var main_settings_fields = [ 'name', 'opac_label'];
136                                                 for ( var i in main_settings_fields ) {
137                                                         var field = main_settings_fields[i];
138                                                         var value = this.store.getValue( current_type, field );
139
140                                                         if (!value) {
141                                                                 window["editor_pane_" + field].setValue( '' ); // unset the value
142                                                                 window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
143                                                         } else window["editor_pane_" + field].setValue( value );
144                                                 }
145
146                                                 if ( this.store.getValue( current_type, '_trueRoot' ) == 'true' ) {
147                                                         editor_pane_parent.disabled = true;
148                                                         editor_pane_parent.setValue(null);
149                                                         editor_pane_parent.setDisplayedValue('');
150                                                         editor_pane_parent.validate(false);
151                                                 } else {
152                                                         editor_pane_parent.disabled = false;
153                                                         editor_pane_parent.validate(true);
154                                                         editor_pane_parent.setValue( this.store.getValue( current_type, 'parent' ) );
155                                                 }
156
157                                                 editor_pane_can_have_vols.setChecked( this.store.getValue( current_type, 'can_have_vols' ) == 't' ? true : false );
158                                                 editor_pane_can_have_users.setChecked( this.store.getValue( current_type, 'can_have_users' ) == 't' ? true : false );
159 ]]>
160                                         </script>
161
162                                         <script type="dojo/method" event="getLabel" args="item,pI">
163                                                 var label = this.store.getValue(item,'name');
164                                                 if (this.store.getValue(item,'ischanged') == 1) label = '* ' + label;
165                                                 return label;
166                                         </script>
167
168                                 </div>
169                         </div>
170
171                         <div id="right_pane" dojoType="dijit.layout.ContentPane"  sizeShare="200">
172                                 <script type="dojo/method">
173                                         window.right_pane_toggler = new dojo.fx.Toggler({ node: 'right_pane'});
174                                         window.right_pane_toggler.hide();
175                                 </script>
176
177                                         <div id="editor_pane" dojoType="dijit.layout.ContentPane">
178                                                 <script type="dojo/method">
179                                                         highlighter.type_tree = {};
180                                                         highlighter.editor_pane = {};
181                                                         highlighter.type_tree.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'type_tree', duration : 500 } );
182                                                         highlighter.type_tree.red = dojox.fx.highlight( { color : '#FF2018', node : 'type_tree', duration : 500 } );
183                                                         highlighter.editor_pane.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'editor_pane', duration : 500 } );
184                                                         highlighter.editor_pane.red = dojox.fx.highlight( { color : '#FF2018', node : 'editor_pane', duration : 500 } );
185                                                 </script>
186         
187                                                 <table class="tundra" style="margin:10px;">
188                                                         <tr>
189                                                                 <th>&conify.org_unit_type.type_name;</th>
190                                                                 <td>
191                                                                         <span id="editor_pane_name" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_name" regExp=".+" required="true">
192                                                                                 <script type="dojo/connect" event="onChange">
193                                                                                         if (current_type) {
194                                                                                                 ou_type_store.setValue( current_type, "name", this.getValue() );
195                                                                                         }
196                                                                                 </script>
197                                                                         </span>
198                                                                         <span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_type" field="name"></span>
199                                                                 </td>
200                                                         </tr>
201                                                         <tr>
202                                                                 <th>&conify.org_unit_type.opac_label;</th>
203                                                                 <td>
204                                                                         <span id="editor_pane_opac_label" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_opac_label" regExp=".+" required="true">
205                                                                                 <script type="dojo/connect" event="onChange">
206                                                                                         if (current_type) {
207                                                                                                 ou_type_store.setValue( current_type, "opac_label", this.getValue() );
208                                                                                         }
209                                                                                 </script>
210                                                                         </span>
211                                                                         <span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_type" field="opac_label"></span>
212                                                                 </td>
213                                                         </tr>
214                                                         <tr>
215                                                                 <th>&conify.org_unit_type.parent_type;</th>
216                                                                 <td>
217                                                                         <div
218                                                                           id="editor_pane_parent"
219                                                                           dojoType="dijit.form.FilteringSelect"
220                                                                           jsId="editor_pane_parent"
221                                                                           store="ou_type_store"
222                                                                           searchAttr="name"
223                                                                           ignoreCase="true"
224                                                                           required="true"
225                                                                         >
226                                                                                 <script type="dojo/method" event="onChange">
227 <![CDATA[
228                                                                                         if (current_type && this.getValue()) {
229                                                                                                 if ( this.store.getValue( current_type, 'parent' ) == this.getValue() ) return;
230
231                                                                                                 this.store.setValue( current_type, "parent", this.getValue() );
232                                                                                                 this.store.fetch({
233                                                                                                         query : { "parent" : this.getValue() },
234                                                                                                         onItem: function (parent_item) {
235                                                                                                                 this.setValue( current_type, 'depth', 1 + parseInt(this.getValue( parent_item, 'depth' ) ));
236                                                                                                         },
237                                                                                                         scope : ou_type_store
238                                                                                                 });
239                                                                                         }
240 ]]>
241                                                                                 </script>
242                                                                         </div>
243                                                                 </td>
244                                                         </tr>
245                                                         <tr>
246                                                                 <th>&conify.org_unit_type.can_have_volumes;</th>
247                                                                 <td>
248                                                                         <input
249                                                                           id="editor_pane_can_have_vols"
250                                                                           jsId="editor_pane_can_have_vols"
251                                                                           type="checkbox"
252                                                                           dojoType="dijit.form.CheckBox"
253                                                                           onChange="if (current_type) ou_type_store.setValue( current_type, 'can_have_vols', this.checked ? 't' : 'f' );"
254                                                                         />
255                                                                 </td>
256                                                         </tr>
257                                                         <tr>
258                                                                 <th>&conify.org_unit_type.can_have_users;</th>
259                                                                 <td>
260                                                                         <input
261                                                                           id="editor_pane_can_have_users"
262                                                                           jsId="editor_pane_can_have_users"
263                                                                           type="checkbox"
264                                                                           dojoType="dijit.form.CheckBox"
265                                                                           onChange="if (current_type) ou_type_store.setValue( current_type, 'can_have_users', this.checked ? 't' : 'f' );"
266                                                                         />
267                                                                 </td>
268                                                         </tr>
269                                                 </table>
270         
271                                                 <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 20px;">
272         
273                                                         <button jsId="save_out_button" dojoType="dijit.form.Button" label="&conify.save_button.label;" onClick="save_type()">
274                                                                 <script type="dojo/connect" event="startup">
275                                                                         this.disabled = true;
276                                                                 </script>
277                                                         </button>
278         
279                                                         <button jsId="delete_out_button" dojoType="dijit.form.Button" label="&conify.delete_button.label;">
280                                                                 <script type="dojo/connect" event="startup">
281                                                                         this.disabled = true;
282                                                                 </script>
283                                                                 <script type="dojo/connect" event="onClick">
284 <![CDATA[
285         
286                                                                         if (ou_type_store.getValue( current_type, '_trueRoot' ) == 'true') {
287                                                                                 highlighter.editor_pane.red.play();
288                                                                                 status_update( dojo.string.substitute( aout_strings.ERROR_DELETING_LAST_AOUT, [ou_type_store.getValue( current_type, 'name' )] ) );
289                                                                                 return false;
290                                                                         }
291
292                                                                         if ( current_type.children ) {
293                                                                                 var kids = current_type.children;
294                                                                                 if (!dojo.isArray(kids)) kids = [kids];
295         
296                                                                                 var existing_kids = dojo.filter(
297                                                                                         kids,
298                                                                                         function(kid){ return kid.isdeleted[0] != 1 }
299                                                                                 );
300                                                                                 if ( existing_kids.length > 0) {
301                                                                                         highlighter.editor_pane.red.play();
302                                                                                         status_update( dojo.string.substitute( aout_strings.ERROR_ORPHANS, [ou_type_store.getValue( current_type, 'name' ), existing_kids.length] ) );
303                                                                                         return;
304                                                                                 }
305                                                                         }
306         
307                                                                         if ( confirm( dojo.string.substitute ( aout_strings.CONFIRM_DELETE, [current_type.name] ))) {
308                                                                                 ou_type_store.setValue( current_type, 'isdeleted', 1 );
309         
310                                                                                 var modified_aout = new aout().fromStoreItem( current_type );
311                                                                                 modified_aout.isdeleted( 1 );
312         
313                                                                                 pCRUD.eliminate(modified_aout, {
314                                                                                         onerror : function (r) {
315                                                                                                 highlighter.editor_pane.red.play();
316                                                                                                 status_update( dojo.string.substitute ( aout_strings.ERROR_DELETING, [ou_type_store.getValue( current_type, 'name' )] ) );
317                                                                                         },
318                                                                                         oncomplete : function (r) {
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( dojo.string.substitute( aout_strings.STATUS_DELETED, [old_name] ) );
347                                                                                         }
348                                                                                 });
349         
350                                                                         }
351 ]]>
352                                                                 </script>
353                                                         </button>
354         
355                                                 </div>
356         
357                                                 <button jsId="new_kid_button" dojoType="dijit.form.Button" label="&conify.new_kid_button.label;">
358                                                         <script type="dojo/connect" event="startup">
359                                                                 this.disabled = true;
360                                                         </script>
361                                                         <script type="dojo/connect" event="onClick">
362 <![CDATA[
363                                                                 var new_fm_obj = new aout().fromHash({
364                                                                         isnew                   : 1,
365                                                                         name                    : aout_strings.LABEL_NEW_TYPE,
366                                                                         can_have_vols   : 'f',
367                                                                         can_have_users  : 'f',
368                                                                         depth                   : 1 + parseInt(ou_type_store.getValue( current_type, 'depth' )),
369                                                                         opac_label              : ou_type_store.getValue( current_type, 'opac_label' ) + ' child' + virgin_out_id--,
370                                                                         parent                  : ou_type_store.getValue( current_type, 'id' )
371                                                                 });
372                                                                 var err = false;
373                                                                 pCRUD.create(new_fm_obj, {
374                                                                         onerror : function (r) {
375                                                                                 highlighter.editor_pane.red.play();
376                                                                                 status_update( aout_strings.ERROR_CALLING_METHOD_AOUT );
377                                                                                 err = true;
378                                                                         },
379                                                                         oncomplete : function (r, list) {
380                                                                                 ou_type_store.newItem(
381                                                                                         list[0].toHash(),
382                                                                                         { parent : current_type, attribute : 'children' }
383                                                                                 );
384                                                                         },
385                                                                 });
386         
387                                                                 if (!err) {
388                                                                         highlighter.editor_pane.green.play();
389                                                                         highlighter.type_tree.green.play();
390                                                                         status_update( dojo.string.substitute( aout_strings.SUCCESS_CREATING_CHILD_AOUT, [ou_type_store.getValue( current_type, 'name' )] ) );
391                                                                 }
392 ]]>
393                                                         </script>
394                                                 </button>
395         
396                                         </div>
397                                 </div>
398                         </div>
399         </body>
400 </html>