2 # Copyright (C) 2008 Georgia Public Library Service / Equinox Software, Inc
3 # Mike Rylander <miker@esilibrary.com>
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.
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.
15 <html xmlns="http://www.w3.org/1999/xhtml">
17 <title>Conify :: Global :: Actor :: Org Unit Types</title>
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');
30 margin: 0px 0px 0px 0px;
31 padding: 0px 0px 0px 0px;
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>
50 <!-- Dojo goodness -->
51 <script type="text/javascript" src="../admin.js"></script>
52 <script type="text/javascript" src="/js/dojo/dojo/dojo.js"></script>
53 <script type="text/javascript" src="/js/dojo/dijit/dijit.js"></script>
55 <script type="text/javascript" src="org_unit_type.js"></script>
59 <body class="tundra" id='pagebody'>
61 <div dojoType="dijit.layout.SplitContainer" orientation="horizontal" style="height: 100%">
63 <div dojoType="dijit.layout.ContentPane" sizeShare="100">
64 <script type="dojo/method">
66 window.dirtyStore = [];
69 method : 'open-ils.permacrud.search.aout.atomic',
71 params : [ ses, { id : { "!=" : null } }, { order_by : { aout : 'name' } } ],
72 onerror : function (r) { status_update('Problem fetching types') },
73 oncomplete : function (r) {
74 ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( r.recv().content() ) });
75 ou_type_store.onSet = function (item, attr, o, n) {
76 if (attr == 'ischanged') return;
78 this.setValue( item, 'ischanged', 1);
80 dojo.addOnUnload( function (event) {
83 query : { ischanged : 1 },
84 queryOptions : { deep : true },
85 onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
89 if (dirtyStore.length > 0) {
90 var confirmation = confirm(
91 'There are unsaved modified Organization Types! '+
92 'OK to save these changes, Cancel to abandon them.'
96 for (var i in window.dirtyStore) {
97 window.current_type = window.dirtyStore[i];
110 label="Organization Types"
111 query="{'_top':'true'}"
112 dojoType="dijit.Tree"
113 store="ou_type_store"
118 <script type="dojo/method" event="onClick" args="item,node">
120 right_pane_toggler.show();
122 current_fm_type = new aout().fromStoreItem(item);
124 highlighter.editor_pane.green.play();
125 status_update( 'Now editing ' + this.store.getValue( item, 'name' ) );
127 new_kid_button.disabled = false;
128 save_out_button.disabled = false;
129 delete_out_button.disabled = false;
131 var main_settings_fields = [ 'name', 'opac_label'];
132 for ( var i in main_settings_fields ) {
133 var field = main_settings_fields[i];
134 var value = this.store.getValue( current_type, field );
137 window["editor_pane_" + field].setValue( '' ); // unset the value
138 window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
139 } else window["editor_pane_" + field].setValue( value );
142 if ( this.store.getValue( current_type, '_trueRoot' ) == 'true' ) {
143 editor_pane_parent.disabled = true;
144 editor_pane_parent.setValue(null);
145 editor_pane_parent.setDisplayedValue('');
146 editor_pane_parent.validate(false);
148 editor_pane_parent.disabled = false;
149 editor_pane_parent.validate(true);
150 editor_pane_parent.setValue( this.store.getValue( current_type, 'parent' ) );
153 editor_pane_can_have_vols.setChecked( this.store.getValue( current_type, 'can_have_vols' ) == 't' ? true : false );
154 editor_pane_can_have_users.setChecked( this.store.getValue( current_type, 'can_have_users' ) == 't' ? true : false );
158 <script type="dojo/method" event="getLabel" args="item,pI">
159 var label = this.store.getValue(item,'name');
160 if (this.store.getValue(item,'ischanged') == 1) label = '* ' + label;
167 <div id="right_pane" dojoType="dijit.layout.ContentPane" sizeShare="200">
168 <script type="dojo/method">
169 window.right_pane_toggler = new dojo.fx.Toggler({ node: 'right_pane'});
170 window.right_pane_toggler.hide();
173 <div id="editor_pane" dojoType="dijit.layout.ContentPane">
174 <script type="dojo/method">
175 highlighter.type_tree = {};
176 highlighter.editor_pane = {};
177 highlighter.type_tree.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'type_tree', duration : 500 } );
178 highlighter.type_tree.red = dojox.fx.highlight( { color : '#FF2018', node : 'type_tree', duration : 500 } );
179 highlighter.editor_pane.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'editor_pane', duration : 500 } );
180 highlighter.editor_pane.red = dojox.fx.highlight( { color : '#FF2018', node : 'editor_pane', duration : 500 } );
183 <table class="tundra" style="margin:10px;">
187 <span id="editor_pane_name" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_name" regExp=".+" required="true">
188 <script type="dojo/connect" event="onChange">
190 ou_type_store.setValue( current_type, "name", this.getValue() );
194 <span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_type" field="name"></span>
200 <span id="editor_pane_opac_label" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_opac_label" regExp=".+" required="true">
201 <script type="dojo/connect" event="onChange">
203 ou_type_store.setValue( current_type, "opac_label", this.getValue() );
207 <span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_type" field="opac_label"></span>
214 id="editor_pane_parent"
215 dojoType="dijit.form.FilteringSelect"
216 jsId="editor_pane_parent"
217 store="ou_type_store"
222 <script type="dojo/method" event="onChange" args=>
224 if (current_type && this.getValue()) {
225 if ( this.store.getValue( current_type, 'parent' ) == this.getValue() ) return;
227 this.store.setValue( current_type, "parent", this.getValue() );
229 query : { "parent" : this.getValue() },
230 onItem: function (parent_item) {
231 this.setValue( current_type, 'depth', 1 + parseInt(this.getValue( parent_item, 'depth' ) ));
233 scope : ou_type_store
242 <th>Can have Volumes/Copies</th>
245 id="editor_pane_can_have_vols"
246 jsId="editor_pane_can_have_vols"
248 dojoType="dijit.form.CheckBox"
249 onChange='if (current_type) ou_type_store.setValue( current_type, "can_have_vols", this.checked ? "t" : "f" );'
254 <th>Can have Users</th>
257 id="editor_pane_can_have_users"
258 jsId="editor_pane_can_have_users"
260 dojoType="dijit.form.CheckBox"
261 onChange='if (current_type) ou_type_store.setValue( current_type, "can_have_users", this.checked ? "t" : "f" );'
267 <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 20px;">
269 <button jsId="save_out_button" dojoType="dijit.form.Button" label="Save" onClick="save_type()">
270 <script type="dojo/connect" event="startup">
271 this.disabled = true;
275 <button jsId="delete_out_button" dojoType="dijit.form.Button" label="Delete">
276 <script type="dojo/connect" event="startup">
277 this.disabled = true;
279 <script type="dojo/connect" event="onClick">
282 if (ou_type_store.getValue( current_type, '_trueRoot' ) == 'true') {
283 highlighter.editor_pane.red.play();
284 status_update( 'Cannot delete' + ou_type_store.getValue( current_type, 'name' ) + ', you need at least one.' );
288 if ( current_type.children ) {
289 var kids = current_type.children;
290 if (!dojo.isArray(kids)) kids = [kids];
292 var existing_kids = dojo.filter(
294 function(kid){ return kid.isdeleted[0] != 1 }
296 if ( existing_kids.length > 0) {
297 highlighter.editor_pane.red.play();
298 status_update( 'Cannot delete' + ou_type_store.getValue( current_type, 'name' ) + ', ' + existing_kids.length + ' subordinates still exist.' );
303 if ( confirm('Are you sure you want to delete ' + current_type.name + '?')) {
304 ou_type_store.setValue( current_type, 'isdeleted', 1 );
306 var modified_aout = new aout().fromStoreItem( current_type );
307 modified_aout.isdeleted( 1 );
310 method : 'open-ils.permacrud.delete.aout',
312 params : [ ses, modified_aout ],
313 onerror : function (r) {
314 highlighter.editor_pane.red.play();
315 status_update( 'Problem deleting ' + ou_type_store.getValue( current_type, 'name' ) );
317 oncomplete : function (r) {
319 if ( res && res.content() ) {
321 var old_name = ou_type_store.getValue( current_type, 'name' );
323 ou_type_store.fetch({
324 query : { id : ou_type_store.getValue( current_type, 'id' ) },
325 queryOptions : { deep : true },
326 onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
327 scope : ou_type_store
332 new_kid_button.disabled = true;
333 save_out_button.disabled = true;
334 delete_out_button.disabled = true;
336 var main_settings_fields = [ 'name', 'opac_label' ];
337 for ( var i in main_settings_fields ) {
338 var field = main_settings_fields[i];
339 window["editor_pane_" + field].setValue( '' ); // unset the value
340 window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
343 window["editor_pane_can_have_vols"].setChecked( false ); // unset the value
344 window["editor_pane_can_have_users"].setChecked( false ); // unset the value
346 highlighter.editor_pane.green.play();
347 status_update( old_name + ' deleted' );
349 highlighter.editor_pane.red.play();
350 status_update( 'Problem deleting ' + old_name );
362 <button jsId="new_kid_button" dojoType="dijit.form.Button" label="New Child">
363 <script type="dojo/connect" event="startup">
364 this.disabled = true;
366 <script type="dojo/connect" event="onClick">
367 var new_fm_obj = new aout().fromHash({
371 can_have_users : 'f',
372 depth : 1 + parseInt(ou_type_store.getValue( current_type, 'depth' )),
373 opac_label : ou_type_store.getValue( current_type, 'opac_label' ) + ' child' + virgin_out_id--,
374 parent : ou_type_store.getValue( current_type, 'id' )
379 method : 'open-ils.permacrud.create.aout',
381 params : [ ses, new_fm_obj ],
382 onerror : function (r) {
383 highlighter.editor_pane.red.play();
384 status_update( 'Problem calling method to create child Org Type' );
387 oncomplete : function (r) {
389 if ( res && res.content() ) {
390 ou_type_store.newItem(
391 res.content().toHash(),
392 { parent : current_type, attribute : 'children' }
395 highlighter.editor_pane.red.play();
396 status_update( 'Problem creating child Org Type' );
403 highlighter.editor_pane.green.play();
404 highlighter.type_tree.green.play();
405 status_update( 'New child Organization Type created for ' + ou_type_store.getValue( current_type, 'name' ) );