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>Confiy :: 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 <!-- Fieldmapper objects -->
51 <script language='javascript' src='/opac/common/js/fmall.js' type='text/javascript'></script>
53 <!-- Dojo goodness -->
54 <script type="text/javascript">
55 var djConfig = { parseOnLoad : true };
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"-->';
63 <script type="text/javascript" src="/js/dojo/dojo/dojo.js"</script>
64 <script type="text/javascript" src="/js/dojo/dijit/dijit.js"></script>
66 <script type="text/javascript" src="org_unit_type.js"></script>
70 <body class="tundra" id='pagebody'>
72 <div dojoType="dijit.layout.SplitContainer" orientation="horizontal" style="height: 100%">
74 <div dojoType="dijit.layout.ContentPane" sizeShare="100">
75 <script type="dojo/method">
76 window.dirtyStore = [];
79 method : 'open-ils.permacrud.search.aout.atomic',
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;
88 this.setValue( item, 'ischanged', 1);
90 dojo.addOnUnload( function (event) {
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 */ } },
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.'
106 for (var i in window.dirtyStore) {
107 window.current_type = window.dirtyStore[i];
120 label="Organization Types"
121 query="{'_top':'true'}"
122 dojoType="dijit.Tree"
123 store="ou_type_store"
128 <script type="dojo/method" event="onClick" args="item,node">
130 right_pane_toggler.show();
132 current_fm_type = new aout().fromStoreItem(item);
134 highlighter.editor_pane.green.play();
135 status_update( 'Now editing ' + this.store.getValue( item, 'name' ) );
137 new_kid_button.disabled = false;
138 save_out_button.disabled = false;
139 delete_out_button.disabled = false;
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 );
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 );
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);
158 editor_pane_parent.disabled = false;
159 editor_pane_parent.validate(true);
160 editor_pane_parent.setValue( this.store.getValue( current_type, 'parent' ) );
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 );
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;
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();
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 } );
193 <table class="tundra" style="margin:10px;">
197 <span id="editor_pane_name" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_name" regExp=".+" required="true">
198 <script type="dojo/connect" event="onChange">
200 ou_type_store.setValue( current_type, "name", this.getValue() );
204 <span dojoType="openils.I18N.translationWidget" targetObject="current_fm_type" field="name"></span>
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">
213 ou_type_store.setValue( current_type, "opac_label", this.getValue() );
217 <span dojoType="openils.I18N.translationWidget" targetObject="current_fm_type" field="opac_label"></span>
224 id="editor_pane_parent"
225 dojoType="dijit.form.FilteringSelect"
226 jsId="editor_pane_parent"
227 store="ou_type_store"
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;
236 this.store.setValue( current_type, "parent", this.getValue() );
238 query : { "parent" : this.getValue() },
239 onItem: function (parent_item) {
240 this.setValue( current_type, 'depth', 1 + parseInt(this.getValue( parent_item, 'depth' ) ));
242 scope : ou_type_store
250 <th>Can have Volumes/Copies</th>
253 id="editor_pane_can_have_vols"
254 jsId="editor_pane_can_have_vols"
256 dojoType="dijit.form.CheckBox"
257 onChange='if (current_type) ou_type_store.setValue( current_type, "can_have_vols", this.checked ? "t" : "f" );'
262 <th>Can have Users</th>
265 id="editor_pane_can_have_users"
266 jsId="editor_pane_can_have_users"
268 dojoType="dijit.form.CheckBox"
269 onChange='if (current_type) ou_type_store.setValue( current_type, "can_have_users", this.checked ? "t" : "f" );'
275 <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 20px;">
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;
283 <button jsId="delete_out_button" dojoType="dijit.form.Button" label="Delete">
284 <script type="dojo/connect" event="startup">
285 this.disabled = true;
287 <script type="dojo/connect" event="onClick">
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.' );
295 if ( current_type.children ) {
296 var kids = current_type.children;
297 if (!dojo.isArray(kids)) kids = [kids];
299 var existing_kids = dojo.filter(
301 function(kid){ return kid.isdeleted[0] != 1 }
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.' );
310 if ( confirm('Are you sure you want to delete ' + current_type.name + '?')) {
311 ou_type_store.setValue( current_type, 'isdeleted', 1 );
313 var modified_aout = new aout().fromStoreItem( current_type );
314 modified_aout.isdeleted( 1 );
317 method : 'open-ils.permacrud.delete.aout',
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' ) );
324 oncomplete : function (r) {
326 if ( res && res.content() ) {
328 var old_name = ou_type_store.getValue( current_type, 'name' );
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
339 new_kid_button.disabled = true;
340 save_out_button.disabled = true;
341 delete_out_button.disabled = true;
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
350 window["editor_pane_can_have_vols"].setChecked( false ); // unset the value
351 window["editor_pane_can_have_users"].setChecked( false ); // unset the value
353 highlighter.editor_pane.green.play();
354 status_update( old_name + ' deleted' );
356 highlighter.editor_pane.red.play();
357 status_update( 'Problem deleting ' + old_name );
369 <button jsId="new_kid_button" dojoType="dijit.form.Button" label="New Child">
370 <script type="dojo/connect" event="startup">
371 this.disabled = true;
373 <script type="dojo/connect" event="onClick">
375 var new_fm_obj = new aout().fromHash({
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' )
387 method : 'open-ils.permacrud.create.aout',
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' );
395 oncomplete : function (r) {
397 if ( res && res.content() ) {
398 ou_type_store.newItem(
399 res.content().toHash(),
400 { parent : current_type, attribute : 'children' }
403 highlighter.editor_pane.red.play();
404 status_update( 'Problem creating child Org Type' );
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' ) );