admin wrapper with status display; separation of JS and HTML where useful
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 26 Mar 2008 15:58:44 +0000 (15:58 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 26 Mar 2008 15:58:44 +0000 (15:58 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/dojo-admin@9138 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/conify/global/actor/org_unit.html
Open-ILS/web/conify/global/actor/org_unit.js [new file with mode: 0644]
Open-ILS/web/conify/global/admin.html [new file with mode: 0644]

index cffb6da..8d2b8b3 100644 (file)
                <script language='javascript' src='/opac/common/js/OrgTree.js' type='text/javascript'></script>
 
                <!-- Dojo goodness -->
-               <script type="text/javascript" src="/conify/js/dojo/dojo.js.uncompressed.js" djConfig="parseOnLoad: true"></script>
-               <script type="text/javascript" src="/conify/js/dijit/dijit.js.uncompressed.js"></script>
-
-               <script type="text/javascript">
-                       dojo.require('conify.fieldmapper.addToHash', true);
-                       dojo.require('conify.fieldmapper.addFromHash', true);
-                       dojo.require('conify.fieldmapper.addToStoreData', true);
-                       dojo.require('conify.fieldmapper.addFromStoreItem', true);
-                       dojo.require('dojo.parser');
-                       dojo.require('dojo.data.ItemFileWriteStore');
-                       dojo.require('dojo.date.stamp');
-                       dojo.require('dijit.form.TextBox');
-                       dojo.require('dijit.form.TimeTextBox');
-                       dojo.require('dijit.form.ValidationTextBox');
-                       dojo.require('dijit.form.CheckBox');
-                       dojo.require('dijit.form.FilteringSelect');
-                       dojo.require('dijit.Tree');
-                       dojo.require('dijit.layout.ContentPane');
-                       dojo.require('dijit.layout.TabContainer');
-                       dojo.require('dijit.layout.LayoutContainer');
-                       dojo.require('dijit.layout.SplitContainer');
-                       dojo.require('dojox.widget.Toaster');
-                       dojo.require('dojox.fx');
-               </script>
-
-               <script type="text/javascript">
-                       // some handy globals
-
-                       var cgi = new CGI();
-                       var cookieManager = new HTTP.Cookies();
-                       var ses = cookieManager.read('ses') || cgi.param('ses');
-                       var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
-
-                       var current_ou, current_ou_hoo;
-                       var virgin_ou_id = -1;
-
-                       var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
-
-                       var highlighter = {};
-
-                       function save_org () {
-                               var modified_ou = new aou().fromStoreItem( current_ou );
-                               modified_ou.ischanged( 1 );
-
-                               new_kid_button.disabled = false;
-                               save_ou_button.disabled = false;
-                               delete_ou_button.disabled = false;
-
-                               pCRUD.request({
-                                       method : 'open-ils.permacrud.update.aou',
-                                       timeout : 10,
-                                       params : [ ses, modified_ou ],
-                                       onerror : function (r) {
-                                               highlighter.editor_pane.red.play();
-                                               throw 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' );
-                                       },
-                                       oncomplete : function (r) {
-                                               var res = r.recv();
-                                               if ( res && res.content() ) {
-                                                       highlighter.editor_pane.green.play();
-                                               } else {
-                                                       highlighter.editor_pane.red.play();
-                                                       throw 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' );
-                                               }
-                                       },
-                               }).send();
-                       }
-       
-                       function hoo_load () {
-                               // empty result not coming through ...
-                               current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
-                               current_ou_hoo.isnew(1);
-
-                               pCRUD.request({
-                                       method : 'open-ils.permacrud.retrieve.aouhoo',
-                                       params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
-                                       onerror : function (r) { throw 'Problem fetching hours of operation for ' + ou_list_store.getValue( current_ou, 'name' );},
-                                       oncomplete : function (r) {
-                                               current_ou_hoo = null;
-
-                                               var res = r.recv();
-                                               if (res) {
-                                                       if (res.content()) current_ou_hoo = res.content();
-                                               }
-
-                                               if (!current_ou_hoo) {
-                                                       current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
-                                                       current_ou_hoo.isnew(1);
-                                                       for (var i = 0; i < 7; i++) {
-                                                               current_ou_hoo['dow_' + i + '_open']('09:00:00');
-                                                               current_ou_hoo['dow_' + i + '_close']('17:00:00');
-                                                       }
-                                               }
-
-                                               for (var i = 0; i < 7; i++) {
-                                                       window['dow_' + i + '_open'].setValue(
-                                                               dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
-                                                       );
-                                                       window['dow_' + i + '_close'].setValue(
-                                                               dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
-                                                       );
-                                               }
-
-                                               highlighter.hoo_pane.green.play();
-                                       }
-                               }).send();
-
-                       }
-
-                       function addr_load () {
-                               // empty result not coming through ...
-
-                               save_ill_address.disabled = false;
-                               save_holds_address.disabled = false;
-                               save_mailing_address.disabled = false;
-                               save_billing_address.disabled = false;
-
-                               if (ou_list_store.getValue( current_ou, 'billing_address' )) {
-                                       pCRUD.request({
-                                               method : 'open-ils.permacrud.retrieve.aoa',
-                                               params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
-                                               onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
-                                               oncomplete : function (r) {
-                                                       current_billing_address = null;
-
-                                                       var res = r.recv();
-                                                       if (res) {
-                                                               if (res.content()) current_billing_address = res.content();
-                                                       }
-
-                                                       if (!current_billing_address) {
-                                                               current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
-                                                               current_billing_address.isnew(1);
-                                                       }
-
-                                                       set_addr_inputs('billing');
-                                                       highlighter.addresses_pane.green.play();
-                                               }
-                                       }).send();
-                               } else {
-                                       current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
-                                       current_billing_address.isnew(1);
-                                       set_addr_inputs('billing');
-                               }
-
-                               if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
-                                       pCRUD.request({
-                                               method : 'open-ils.permacrud.retrieve.aoa',
-                                               params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
-                                               onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
-                                               oncomplete : function (r) {
-                                                       current_mailing_address = null;
-
-                                                       var res = r.recv();
-                                                       if (res) {
-                                                               if (res.content()) current_mailing_address = res.content();
-                                                       }
-
-                                                       if (!current_mailing_address) {
-                                                               current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
-                                                               current_mailing_address.isnew(1);
-                                                       }
-
-                                                       set_addr_inputs('mailing');
-                                                       highlighter.addresses_pane.green.play();
-                                               }
-                                       }).send();
-                               } else {
-                                       current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
-                                       current_mailing_address.isnew(1);
-                                       set_addr_inputs('mailing');
-                               }
-
-                               if (ou_list_store.getValue( current_ou, 'holds_address' )) {
-                                       pCRUD.request({
-                                               method : 'open-ils.permacrud.retrieve.aoa',
-                                               params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
-                                               onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
-                                               oncomplete : function (r) {
-                                                       current_holds_address = null;
+               <script type="text/javascript" src="/conify/js/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
+               <script type="text/javascript" src="/conify/js/dijit/dijit.js"></script>
 
-                                                       var res = r.recv();
-                                                       if (res) {
-                                                               if (res.content()) current_holds_address = res.content();
-                                                       }
-
-                                                       if (!current_holds_address) {
-                                                               current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
-                                                               current_holds_address.isnew(1);
-                                                       }
-
-                                                       set_addr_inputs('holds');
-                                                       highlighter.addresses_pane.green.play();
-                                               }
-                                       }).send();
-                               } else {
-                                       current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
-                                       current_holds_address.isnew(1);
-                                       set_addr_inputs('holds');
-                               }
-
-                               if (ou_list_store.getValue( current_ou, 'ill_address' )) {
-                                       pCRUD.request({
-                                               method : 'open-ils.permacrud.retrieve.aoa',
-                                               params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
-                                               onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
-                                               oncomplete : function (r) {
-                                                       current_ill_address = null;
-
-                                                       var res = r.recv();
-                                                       if (res) {
-                                                               if (res.content()) current_ill_address = res.content();
-                                                       }
-
-                                                       if (!current_ill_address) {
-                                                               current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
-                                                               current_ill_address.isnew(1);
-                                                       }
-
-                                                       set_addr_inputs('ill');
-                                                       highlighter.addresses_pane.green.play();
-                                               }
-                                       }).send();
-                               } else {
-                                       current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
-                                       current_ill_address.isnew(1);
-                                       set_addr_inputs('ill');
-                               }
-
-                       }
-
-                       function set_addr_inputs (type) {
-                               window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
-                               window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
-                               window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
-                               window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
-                               window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
-                               window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
-                               window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
-                               window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
-                               window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );
-                       }
-
-               </script>
+               <script type="text/javascript" src="org_unit.js"></script>
 
        </head>
 
                                <script type="dojo/method">
 
                                        var ou_list_data = { label : 'shortname', identifier : 'id' };
+                                       window.dirtyStore = [];
                
                                        pCRUD.request({
                                                method : 'open-ils.permacrud.search.aou.atomic',
                                                timeout : 10,
                                                params : [ ses, { id : { "!=" : null } }, { order_by : { aou : 'shortname' } } ],
                                                onerror : function (r) { throw 'Problem fetching org units';},
-                                               oncomplete : function (r) { window.ou_list_store = new dojo.data.ItemFileWriteStore({ data : aou.toStoreData( r.recv().content() ) }); }
+                                               oncomplete : function (r) {
+                                                       window.ou_list_store = new dojo.data.ItemFileWriteStore({ data : aou.toStoreData( r.recv().content() ) });
+                                                       window.ou_list_store.onSet = function (item, attr, n, o) {
+                                                               if (attr == 'ischanged') return;
+                                                               if (n == o) return;
+                                                               this.setValue( item, 'ischanged', 1);
+                                                       };
+                                                       dojo.addOnUnload( function (event) {
+
+                                                               ou_list_store.fetch({
+                                                                       query : { ischanged : 1 },
+                                                                       queryOptions : { deep : true },
+                                                                       onItem : function (item, req) { try { if (this.isItem( item )) window.dirtyStore.push( item ); } catch (e) { /* meh */ } },
+                                                                       scope : ou_list_store
+                                                               });
+
+                                                               if (dirtyStore.length > 0) {
+                                                                       var confirmation = confirm(
+                                                                               'There are unsaved modified Organizational Units!  '+
+                                                                               'OK to save these changes, Cancel to abandon them.'
+                                                                       );
+
+                                                                       if (confirmation) {
+                                                                               for (var i in window.dirtyStore) {
+                                                                                       window.current_ou = window.dirtyStore[i];
+                                                                                       save_org(true);
+                                                                               }
+                                                                       }
+                                                               }
+
+                                                       });
+                                               }
                                        }).send();
-               
 
                                </script>
                                <div
-                                 id="dijit_ou_tree"
+                                 id="ou_tree"
                                  label="Oragnizational Units"
                                  query="{'_top':'true'}"
                                  dojoType="dijit.Tree"
                                                current_ou = item;
 
                                                highlighter.editor_pane.green.play();
+                                               status_update( 'Now editing' + this.store.getValue( item, 'name' ) );
 
                                                new_kid_button.disabled = false;
                                                save_ou_button.disabled = false;
                                        </script>
 
                                        <script type="dojo/method" event="getLabel" args="item,pI">
-                                               return this.store.getValue(item,'shortname') + ' : ' + this.store.getValue(item,'name');
+                                               var label = this.store.getValue(item,'shortname') + ' : ' + this.store.getValue(item,'name');
+                                               if (this.store.getValue(item,'ischanged') == 1) label = '* ' + label;
+                                               return label;
                                        </script>
 
                                </div>
                        </div>
 
                        <div id="right_pane" dojoType="dijit.layout.ContentPane"  sizeMin="200" sizeShare="300">
-                               <div><span style="font-weight:bold; margin-right:10px;">Now editing:</span><span id="current_ou_name"></span></div>
 
                                <div id="right_tabpane" dojoType="dijit.layout.TabContainer">
        
                                        <div id="editor_pane" dojoType="dijit.layout.ContentPane" title="Main Settings">
                                                <script type="dojo/method">
+                                                       highlighter.ou_tree = {};
                                                        highlighter.editor_pane = {};
                                                        highlighter.hoo_pane = {};
                                                        highlighter.addresses_pane = {};
+                                                       highlighter.ou_tree.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'ou_tree', duration : 500 } );
+                                                       highlighter.ou_tree.red = dojox.fx.highlight( { color : '#FF2018', node : 'ou_tree', duration : 500 } );
                                                        highlighter.editor_pane.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'editor_pane', duration : 500 } );
                                                        highlighter.editor_pane.red = dojox.fx.highlight( { color : '#FF2018', node : 'editor_pane', duration : 500 } );
                                                        highlighter.hoo_pane.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'hoo_pane', duration : 500 } );
                                                                                );
                                                                                if ( existing_kids.length > 0) {
                                                                                        highlighter.editor_pane.red.play();
-                                                                                       alert(existing_kids.length + ' kids still exist');
+                                                                                       status_update( 'Cannot delete' + ou_list_store.getValue( current_ou, 'name' ) + ', ' + existing_kids.length + ' subordinates still exist.' );
                                                                                        return;
                                                                                }
                                                                        }
                                                                                        params : [ ses, modified_ou ],
                                                                                        onerror : function (r) {
                                                                                                highlighter.editor_pane.red.play();
-                                                                                               throw 'Problem deleting ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                               status_update( 'Problem deleting ' + ou_list_store.getValue( current_ou, 'name' ) );
                                                                                        },
                                                                                        oncomplete : function (r) {
                                                                                                var res = r.recv();
                                                                                                        ou_list_store.fetch({
                                                                                                                query : { id : ou_list_store.getValue( current_ou, 'id' ) },
                                                                                                                queryOptions : { deep : true },
-                                                                                                               onItem : function (item, req) { try { this.deleteItem( item ); } catch (e) { /* meh */ } },
+                                                                                                               onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
                                                                                                                scope : ou_list_store
                                                                                                        });
        
                                                                                                        }
                        
                                                                                                        highlighter.editor_pane.green.play();
+                                                                                                       status_update( ou_list_store.getValue( current_ou, 'name' ) + ' deleted' );
                                                                                                } else {
                                                                                                        highlighter.editor_pane.red.play();
-                                                                                                       throw 'Problem deleting ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                                       status_update( 'Problem deleting ' + ou_list_store.getValue( current_ou, 'name' ) );
                                                                                                }
                                                                                        },
                                                                                }).send();
                                                                        params : [ ses, new_fm_obj ],
                                                                        onerror : function (r) {
                                                                                highlighter.editor_pane.red.play();
-                                                                               throw 'Problem creating child Org Unit';
+                                                                               status_update( 'Problem creating child Org Unit' );
                                                                        },
                                                                        oncomplete : function (r) {
                                                                                var res = r.recv();
                                                                                        );
                                                                                } else {
                                                                                        highlighter.editor_pane.red.play();
-                                                                                       throw 'Problem creating child Org Unit';
+                                                                                       status_update( 'Problem creating child Org Unit' );
                                                                                }
                                                                        },
                                                                }).send();
        
                                                                highlighter.editor_pane.green.play();
+                                                               highlighter.ou_tree.green.play();
+                                                               status_update( 'New child Organizational Unit created for ' + ou_list_store.getValue( current_ou, 'name' ) );
        
                                                        </script>
                                                </button>
                                                                        params : [ ses, current_ou_hoo ],
                                                                        onerror : function (r) {
                                                                                highlighter.editor_pane.red.play();
-                                                                               throw 'Problem saving Hours of Operation data for ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                               status_update( 'Problem saving Hours of Operation data for ' + ou_list_store.getValue( current_ou, 'name' ));
                                                                        },
                                                                        oncomplete : function (r) {
                                                                                var res = r.recv();
                                                                                if ( res && res.content() ) {
                                                                                        current_ou_hoo.isnew(0);
                                                                                        highlighter.editor_pane.green.play();
+                                                                                       status_update( 'Hours of Operation updated for ' + ou_list_store.getValue( current_ou, 'name' ) );
                                                                                } else {
                                                                                        highlighter.editor_pane.red.play();
-                                                                                       throw 'Problem saving Hours of Operation data for ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                       status_update( 'Problem saving Hours of Operation data for ' + ou_list_store.getValue( current_ou, 'name' ));
                                                                                }
                                                                        },
                                                                }).send();
                                                                                        params : [ ses, current_billing_address ],
                                                                                        onerror : function (r) {
                                                                                                highlighter.addresses_pane.red.play();
-                                                                                               throw 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                               status_update( 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' ) );
                                                                                        },
                                                                                        oncomplete : function (r) {
                                                                                                var res = r.recv();
                                                                                                        }
                                                                                                        current_billing_address.isnew(0);
                                                                                                        highlighter.addresses_pane.green.play();
+                                                                                                       status_update( 'Changes to the Physical Address of ' + ou_list_store.getValue( current_ou, 'name' ) + ' saved' );
                                                                                                } else {
                                                                                                        highlighter.addresses_pane.red.play();
-                                                                                                       throw 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                                       status_update( 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' ) );
                                                                                                }
                                                                                        },
                                                                                }).send();
                                                                                        params : [ ses, current_holds_address ],
                                                                                        onerror : function (r) {
                                                                                                highlighter.addresses_pane.red.play();
-                                                                                               throw 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                               throw 'Problem saving Holds Address data for ' + ou_list_store.getValue( current_ou, 'name' );
                                                                                        },
                                                                                        oncomplete : function (r) {
                                                                                                var res = r.recv();
                                                                                                        }
                                                                                                        current_holds_address.isnew(0);
                                                                                                        highlighter.addresses_pane.green.play();
+                                                                                                       status_update( 'Changes to the Holds Address of ' + ou_list_store.getValue( current_ou, 'name' ) + ' saved' );
                                                                                                } else {
                                                                                                        highlighter.addresses_pane.red.play();
-                                                                                                       throw 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                                       throw 'Problem saving Holds Address data for ' + ou_list_store.getValue( current_ou, 'name' );
                                                                                                }
                                                                                        },
                                                                                }).send();
                                                                                        params : [ ses, current_mailing_address ],
                                                                                        onerror : function (r) {
                                                                                                highlighter.addresses_pane.red.play();
-                                                                                               throw 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                               throw 'Problem saving Mailing Address data for ' + ou_list_store.getValue( current_ou, 'name' );
                                                                                        },
                                                                                        oncomplete : function (r) {
                                                                                                var res = r.recv();
                                                                                                        }
                                                                                                        current_mailing_address.isnew(0);
                                                                                                        highlighter.addresses_pane.green.play();
+                                                                                                       status_update( 'Changes to the Mailing Address of ' + ou_list_store.getValue( current_ou, 'name' ) + ' saved' );
                                                                                                } else {
                                                                                                        highlighter.addresses_pane.red.play();
-                                                                                                       throw 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' );
+                                                                                                       throw 'Problem saving Mailing Address data for ' + ou_list_store.getValue( current_ou, 'name' );
                                                                                                }
                                                                                        },
                                                                                }).send();
                                                                                                        }
                                                                                                        current_ill_address.isnew(0);
                                                                                                        highlighter.addresses_pane.green.play();
+                                                                                                       status_update( 'Changes to the ILL Address of ' + ou_list_store.getValue( current_ou, 'name' ) + ' saved' );
                                                                                                } else {
                                                                                                        highlighter.addresses_pane.red.play();
                                                                                                        throw 'Problem saving Physical Address data for ' + ou_list_store.getValue( current_ou, 'name' );
                                </div>
                        </div>
                </div>
+
+               <div id="status_bar"><span style="font-weight: bold; margin: 5px; margin-right: 10px;">Now editing:</span><span id="current_ou_name"></span></div>
        </body>
 </html>
diff --git a/Open-ILS/web/conify/global/actor/org_unit.js b/Open-ILS/web/conify/global/actor/org_unit.js
new file mode 100644 (file)
index 0000000..31ec66c
--- /dev/null
@@ -0,0 +1,242 @@
+dojo.require('conify.fieldmapper.addToHash', true);
+dojo.require('conify.fieldmapper.addFromHash', true);
+dojo.require('conify.fieldmapper.addToStoreData', true);
+dojo.require('conify.fieldmapper.addFromStoreItem', true);
+dojo.require('dojo.parser');
+dojo.require('dojo.data.ItemFileWriteStore');
+dojo.require('dojo.date.stamp');
+dojo.require('dijit.form.TextBox');
+dojo.require('dijit.form.TimeTextBox');
+dojo.require('dijit.form.ValidationTextBox');
+dojo.require('dijit.form.CheckBox');
+dojo.require('dijit.form.FilteringSelect');
+dojo.require('dijit.Tree');
+dojo.require('dijit.layout.ContentPane');
+dojo.require('dijit.layout.TabContainer');
+dojo.require('dijit.layout.LayoutContainer');
+dojo.require('dijit.layout.SplitContainer');
+dojo.require('dojox.widget.Toaster');
+dojo.require('dojox.fx');
+
+// some handy globals
+var cgi = new CGI();
+var cookieManager = new HTTP.Cookies();
+var ses = cookieManager.read('ses') || cgi.param('ses');
+var pCRUD = new OpenSRF.ClientSession('open-ils.permacrud');
+
+var current_ou, current_ou_hoo;
+var virgin_ou_id = -1;
+
+var ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
+
+var highlighter = {};
+
+function status_update (markup) {
+       if (parent.status_update) parent.status_update( markup );
+}
+
+function save_org () {
+       var modified_ou = new aou().fromStoreItem( current_ou );
+       modified_ou.ischanged( 1 );
+
+       new_kid_button.disabled = false;
+       save_ou_button.disabled = false;
+       delete_ou_button.disabled = false;
+
+       pCRUD.request({
+               method : 'open-ils.permacrud.update.aou',
+               timeout : 10,
+               params : [ ses, modified_ou ],
+               onerror : function (r) {
+                       highlighter.editor_pane.red.play();
+                       status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
+               },
+               oncomplete : function (r) {
+                       var res = r.recv();
+                       if ( res && res.content() ) {
+                               ou_list_store.setValue( current_ou, 'ischanged', 0 );
+                               highlighter.editor_pane.green.play();
+                               status_update( 'Saved changes to ' + ou_list_store.getValue( current_ou, 'name' ) );
+                       } else {
+                               highlighter.editor_pane.red.play();
+                               status_update( 'Problem saving data for ' + ou_list_store.getValue( current_ou, 'name' ) );
+                       }
+               },
+       }).send();
+}
+       
+function hoo_load () {
+       // empty result not coming through ...
+       current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
+       current_ou_hoo.isnew(1);
+
+       pCRUD.request({
+               method : 'open-ils.permacrud.retrieve.aouhoo',
+               params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
+               onerror : function (r) { throw 'Problem fetching hours of operation for ' + ou_list_store.getValue( current_ou, 'name' );},
+               oncomplete : function (r) {
+                       current_ou_hoo = null;
+
+                       var res = r.recv();
+                       if (res) {
+                               if (res.content()) current_ou_hoo = res.content();
+                       }
+
+                       if (!current_ou_hoo) {
+                               current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
+                               current_ou_hoo.isnew(1);
+                               for (var i = 0; i < 7; i++) {
+                                       current_ou_hoo['dow_' + i + '_open']('09:00:00');
+                                       current_ou_hoo['dow_' + i + '_close']('17:00:00');
+                               }
+                       }
+
+                       for (var i = 0; i < 7; i++) {
+                               window['dow_' + i + '_open'].setValue(
+                                       dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_open']() )
+                               );
+                               window['dow_' + i + '_close'].setValue(
+                                       dojo.date.stamp.fromISOString( 'T' + current_ou_hoo['dow_' + i + '_close']() )
+                               );
+                       }
+
+                       highlighter.hoo_pane.green.play();
+               }
+       }).send();
+
+}
+
+function addr_load () {
+       // empty result not coming through ...
+
+       save_ill_address.disabled = false;
+       save_holds_address.disabled = false;
+       save_mailing_address.disabled = false;
+       save_billing_address.disabled = false;
+
+       if (ou_list_store.getValue( current_ou, 'billing_address' )) {
+               pCRUD.request({
+                       method : 'open-ils.permacrud.retrieve.aoa',
+                       params : [ ses, ou_list_store.getValue( current_ou, 'billing_address' ) ],
+                       onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
+                       oncomplete : function (r) {
+                               current_billing_address = null;
+
+                               var res = r.recv();
+                               if (res) {
+                                       if (res.content()) current_billing_address = res.content();
+                               }
+
+                               if (!current_billing_address) {
+                                       current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
+                                       current_billing_address.isnew(1);
+                               }
+
+                               set_addr_inputs('billing');
+                               highlighter.addresses_pane.green.play();
+                       }
+               }).send();
+       } else {
+               current_billing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
+               current_billing_address.isnew(1);
+               set_addr_inputs('billing');
+       }
+
+       if (ou_list_store.getValue( current_ou, 'mailing_address' )) {
+               pCRUD.request({
+                       method : 'open-ils.permacrud.retrieve.aoa',
+                       params : [ ses, ou_list_store.getValue( current_ou, 'mailing_address' ) ],
+                       onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
+                       oncomplete : function (r) {
+                               current_mailing_address = null;
+
+                               var res = r.recv();
+                               if (res) {
+                                       if (res.content()) current_mailing_address = res.content();
+                               }
+
+                               if (!current_mailing_address) {
+                                       current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
+                                       current_mailing_address.isnew(1);
+                               }
+
+                               set_addr_inputs('mailing');
+                               highlighter.addresses_pane.green.play();
+                       }
+               }).send();
+       } else {
+               current_mailing_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
+               current_mailing_address.isnew(1);
+               set_addr_inputs('mailing');
+       }
+
+       if (ou_list_store.getValue( current_ou, 'holds_address' )) {
+               pCRUD.request({
+                       method : 'open-ils.permacrud.retrieve.aoa',
+                       params : [ ses, ou_list_store.getValue( current_ou, 'holds_address' ) ],
+                       onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
+                       oncomplete : function (r) {
+                               current_holds_address = null;
+
+                               var res = r.recv();
+                               if (res) {
+                                       if (res.content()) current_holds_address = res.content();
+                               }
+
+                               if (!current_holds_address) {
+                                       current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
+                                       current_holds_address.isnew(1);
+                               }
+
+                               set_addr_inputs('holds');
+                               highlighter.addresses_pane.green.play();
+                       }
+               }).send();
+       } else {
+               current_holds_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
+               current_holds_address.isnew(1);
+               set_addr_inputs('holds');
+       }
+
+       if (ou_list_store.getValue( current_ou, 'ill_address' )) {
+               pCRUD.request({
+                       method : 'open-ils.permacrud.retrieve.aoa',
+                       params : [ ses, ou_list_store.getValue( current_ou, 'ill_address' ) ],
+                       onerror : function (r) { throw 'Problem fetching Physical Address for ' + ou_list_store.getValue( current_ou, 'name' );},
+                       oncomplete : function (r) {
+                               current_ill_address = null;
+
+                               var res = r.recv();
+                               if (res) {
+                                       if (res.content()) current_ill_address = res.content();
+                               }
+
+                               if (!current_ill_address) {
+                                       current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
+                                       current_ill_address.isnew(1);
+                               }
+
+                               set_addr_inputs('ill');
+                               highlighter.addresses_pane.green.play();
+                       }
+               }).send();
+       } else {
+               current_ill_address = new aoa().fromHash({org_unit:ou_list_store.getValue( current_ou, 'id' )});
+               current_ill_address.isnew(1);
+               set_addr_inputs('ill');
+       }
+
+}
+
+function set_addr_inputs (type) {
+       window[type + '_addr_valid'].setChecked( window['current_' + type + '_address'].valid() == 't' ? true : false );
+       window[type + '_addr_type'].setValue( window['current_' + type + '_address'].address_type() || '' );
+       window[type + '_addr_street1'].setValue( window['current_' + type + '_address'].street1() || '' );
+       window[type + '_addr_street2'].setValue( window['current_' + type + '_address'].street2() || '' );
+       window[type + '_addr_city'].setValue( window['current_' + type + '_address'].city() || '' );
+       window[type + '_addr_county'].setValue( window['current_' + type + '_address'].county() || '' );
+       window[type + '_addr_country'].setValue( window['current_' + type + '_address'].country() || '' );
+       window[type + '_addr_state'].setValue( window['current_' + type + '_address'].state() || '' );
+       window[type + '_addr_post_code'].setValue( window['current_' + type + '_address'].post_code() || '' );
+}
+
diff --git a/Open-ILS/web/conify/global/admin.html b/Open-ILS/web/conify/global/admin.html
new file mode 100644 (file)
index 0000000..045aa0d
--- /dev/null
@@ -0,0 +1,57 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+       <head>
+               <title>Conify :: Global :: Admin</title>
+
+        <style type="text/css">
+            @import url("/conify/js/dojo/resources/dojo.css");
+            @import url("/conify/js/dijit/themes/tundra/tundra.css");
+            @import url("/conify/js/dojox/widget/Toaster/Toaster.css");
+        </style>
+
+        <style>
+            html, body
+            {
+                height: 100%;
+                width: 100%;
+                margin: 0px 0px 0px 0px;
+                padding: 0px 0px 0px 0px;
+                overflow: hidden;
+            }
+        </style>
+
+        <!-- Dojo goodness -->
+        <script type="text/javascript" src="/conify/js/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
+        <script type="text/javascript" src="/conify/js/dijit/dijit.js"></script>
+
+        <script type="text/javascript">
+            dojo.require('dojo.parser');
+            dojo.require('dijit.form.Button');
+            dojo.require('dijit.layout.ContentPane');
+            dojo.require('dijit.layout.LayoutContainer');
+
+            function status_update (markup) {
+                dojo.byId('status_text').innerHTML = markup;
+            }
+
+        </script>
+
+       </head>
+       <body class="tundra" id='pagebody'>
+               <div dojoType="dijit.layout.LayoutContainer" style="height: 100%; width: 100%; margin: 0; padding: 0; border: 0;">
+                       <div id="top_pane" jsId="top_pane" dojoType="dijit.layout.ContentPane" layoutAlign="top" orientation="horizontal" style="margin: 4px; width: 100%; text-align: middle;" title="Controls">
+                               <img src="/opac/images/small_logo.jpg"/>
+                               <span style="font-size: large; padding-left: 20px;"> Configure your ILS </span>
+                       </div>
+                       <div id="left_pane" jsId="left_pane" dojoType="dijit.layout.ContentPane" layoutAlign="left" orientation="vertical" style="height: 90%; margin: 4px" title="Controls">
+                               <button dojoType="dijit.form.Button" label="Organizational Units" onClick="dojo.byId('action_iframe').src = 'actor/org_unit.html';" />
+                       </div>
+                       <div id="content_pane" jsId="content_pane" dojoType="dijit.layout.ContentPane" layoutAlign="client" style="margin: 2px; border-top: 2px solid grey; border-bottom: 2px solid grey; border-left: 2px solid grey;">
+                               <iframe id="action_iframe" marginwidth="0" marginheight="0" style="border:0; height: 100%; width: 100%;"></iframe>
+                       </div>
+                       <div id="bottom_pane" jsId="bottom_pane" dojoType="dijit.layout.ContentPane" layoutAlign="bottom" orientation="horizontal" style="margin: 4px; height: 5%; width: 100%" title="Controls">
+                               <span id="status_text"/>
+                       </div>
+               </div>
+       </body>
+</html>
+