tree and core edit widgets are interacting; added FM object array to dojo data store...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 22 Mar 2008 04:41:55 +0000 (04:41 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 22 Mar 2008 04:41:55 +0000 (04:41 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/dojo-admin@9110 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 1e54680..3b1afe1 100644 (file)
@@ -5,6 +5,7 @@
                <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>
@@ -29,6 +30,7 @@
                <!-- Fieldmapper objects -->
                <script language='javascript' src='/opac/common/js/fmall.js' type='text/javascript'></script>
                <script language='javascript' src='/opac/common/js/fmgen.js' type='text/javascript'></script>
+               <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">
                        dojo.require('conify.fieldmapper.addToHash', true);
+                       dojo.require('conify.fieldmapper.addFromHash', true);
+                       dojo.require('conify.fieldmapper.addToStoreData', true);
                        dojo.require('dojo.parser');
-                       dojo.require('dojo.data.ItemFileReadStore');
+                       dojo.require('dojo.data.ItemFileWriteStore');
                        dojo.require('dijit.form.TextBox');
+                       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');
                </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');
 
-                       function ouTreeOnClick (m) {
-                               if (m.event != 'execute') return;
-
-                               editor_pane_name.setValue( m.item.name );
-                               editor_pane_shortname.setValue( m.item.shortname );
-                               editor_pane_email.setValue( m.item.email );
-                               editor_pane_phone.setValue( m.item.phone );
-                               editor_pane_parent_ou.setValue( m.item.parent_ou );
-                               editor_pane_opac_visible.setChecked( m.item.opac_visible == 't' ? true : false );
-                       }
+                       var current_ou;
+                       var virgin_ou_id = -1;
 
                </script>
 
@@ -75,7 +76,7 @@
                        <div dojoType="dijit.layout.ContentPane" sizeMin="200" sizeShare="100">
                                <script type="dojo/method">
 
-                                       var ou_list_data = { label : 'displayLabel', identifier : 'id' };
+                                       var ou_list_data = { label : 'shortname', identifier : 'id' };
                
                                        var req = pCRUD.request({
                                                method : 'open-ils.permacrud.search.aou.atomic',
                                        });
                                        req.send();
                
-                                       var _data = req.recv().content();
-                                       var ou_hash_list = [];
-                                       for (var i in _data) ou_hash_list.push( _data[i].toHash() );
-
-                                       var _find_root = {};
-                                       for (var i in ou_hash_list) {
-                                               _find_root[ou_hash_list[i].id] = ou_hash_list[i]; 
-                                               ou_hash_list[i].displayLabel = ou_hash_list[i].shortname + ' (' + ou_hash_list[i].name + ')';
-                                       }
-               
-                                       var item_data = [];
-                                       for (var i in ou_hash_list) {
-                                               var ou = ou_hash_list[i]
-                                               ou.children = [];
-               
-                                               for (var j in ou_hash_list) {
-                                                       var kid = ou_hash_list[j];
-                                                       if (kid.parent_ou == ou.id) {
-                                                               ou.children.push( { _reference : kid.id } );
-                                                               kid.iskid = true;
-                                                               if (_find_root[kid.id]) delete _find_root[kid.id];
-                                                       }
-                                               }
-
-                                               item_data.push( ou );
-                                       }
-
-                                       for (var j in _find_root) {
-                                               _find_root[j]['top'] = 'true';
-                                       }
-
-                                       ou_list_data.items = item_data;
-
-                                       window.ou_list_store = new dojo.data.ItemFileReadStore({ data : ou_list_data });
+                                       window.ou_type_store = new dojo.data.ItemFileWriteStore({ data : aout.toStoreData( globalOrgTypes ) });
+                                       window.ou_list_store = new dojo.data.ItemFileWriteStore({ data : aou.toStoreData( req.recv().content() ) });
 
                                </script>
                                <div
                                  id="dijit_ou_tree"
                                  label="Oragnizational Units"
-                                 query="{'top':'true'}"
+                                 query="{'_top':'true'}"
                                  dojoType="dijit.Tree"
                                  store="ou_list_store"
                                  minSize="200"
                                  jsId="ou_tree"
                                >
-                                       <script type="dojo/method">
-                                               tree_execute_sub = dojo.subscribe('dijit_ou_tree',null,ouTreeOnClick);
+
+                                       <script type="dojo/method" event="onClick" args="item,node">
+
+
+                                               new_kid_button.disabled = false;
+                                               save_ou_button.disabled = false;
+                                               delete_ou_button.disabled = false;
+
+                                               current_ou = item;
+
+                                               var main_settings_fields = [ 'name', 'shortname', 'email', 'phone', 'ou_type' ];
+                                               for ( var i in main_settings_fields ) {
+                                                       var field = main_settings_fields[i];
+                                                       var value = this.store.getValue( current_ou, field );
+
+                                                       if (!value) window["editor_pane_" + field].setValue( '' ); // unset the value
+                                                       else window["editor_pane_" + field].setValue( value );
+                                               }
+
+                                               if ( this.store.getValue( current_ou, '_trueRoot' ) == 'true' ) {
+                                                       editor_pane_parent_ou.disabled = true;
+                                                       editor_pane_parent_ou.setValue(null);
+                                                       editor_pane_parent_ou.setDisplayedValue('');
+                                               } else {
+                                                       editor_pane_parent_ou.disabled = false;
+                                                       editor_pane_parent_ou.setValue( this.store.getValue( current_ou, 'parent_ou' ) );
+                                               }
+
+                                               editor_pane_opac_visible.setChecked( this.store.getValue( current_ou, 'opac_visible' ) == 't' ? true : false );
+
                                        </script>
-                                       <script type="dojo/connect" event="destroy">
-                                               dojo.unsubscribe(tree_execute_sub);
+
+                                       <script type="dojo/method" event="getLabel" args="item,pI">
+                                               return this.store.getValue(item,'shortname') + ' : ' + this.store.getValue(item,'name');
                                        </script>
+
                                </div>
                        </div>
 
                        <div id="right_tabpane" dojoType="dijit.layout.TabContainer" sizeMin="200" sizeShare="300">
+
                                <div id="editor_pane" dojoType="dijit.layout.ContentPane" title="Main Settings">
-                                       <table class="tundra">
+                                       <table class="tundra" style="margin:10px;">
+                                               <tr>
+                                                       <th>Org Unit Name</th>
+                                                       <td>
+                                                               <span id="editor_pane_name" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_name" regExp=".+">
+                                                                       <script type="dojo/connect" event="onChange">
+                                                                               ou_list_store.setValue( current_ou, "name", this.getValue() );
+                                                                       </script>
+                                                               </span>
+                                                       </td>
+                                               </tr>
+                                               <tr>
+                                                       <th>Org Unit Policy Code</th>
+                                                       <td>
+                                                               <span id="editor_pane_shortname" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_shortname" uppercase="true" regExp=".+">
+                                                                       <script type="dojo/connect" event="onChange">
+                                                                               ou_list_store.setValue( current_ou, "shortname", this.getValue() );
+                                                                       </script>
+                                                               </span>
+                                                       </td>
+                                               </tr>
+                                               <tr>
+                                                       <th>Main Email Address</th>
+                                                       <td>
+                                                               <span id="editor_pane_email" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_email" regExp="^\w+\@\w+(?:\.\w+)+$">
+                                                                       <script type="dojo/connect" event="onChange">
+                                                                               ou_list_store.setValue( current_ou, "email", this.getValue() );
+                                                                       </script>
+                                                               </span>
+                                                       </td>
+                                               </tr>
+                                               <tr>
+                                                       <th>Main Phone Number</th>
+                                                       <td>
+                                                               <span id="editor_pane_phone" dojoType="dijit.form.ValidationTextBox" jsId="editor_pane_phone" regExp="^(?:(?:\d{1}[ -\.])?\(?\d{3}\)?[ -\.]{1})?\d{3}[ -\.]{1}\d{4}(| \S+.*)$">
+                                                                       <script type="dojo/connect" event="onChange">
+                                                                               ou_list_store.setValue( current_ou, "phone", this.getValue() );
+                                                                       </script>
+                                                               </span>
+                                                       </td>
+                                               </tr>
                                                <tr>
-                                                       <th>Parent</th>
+                                                       <th>Org Unit Type</th>
+                                                       <td>
+                                                               <div
+                                                                 id="editor_pane_ou_type"
+                                                                 dojoType="dijit.form.FilteringSelect"
+                                                                 jsId="editor_pane_ou_type"
+                                                                 store="ou_type_store"
+                                                                 searchAttr="name"
+                                                                 ignoreCase="true"
+                                                               >
+                                                                       <script type="dojo/method" event="onChange">
+                                                                               ou_list_store.setValue( current_ou, "ou_type", this.getValue() );
+                                                                       </script>
+                                                               </div>
+                                                       </td>
+                                               </tr>
+                                               <tr>
+                                                       <th>Parent Org Unit</th>
                                                        <td>
                                                                <div
                                                                  id="editor_pane_parent_ou"
                                                                  dojoType="dijit.form.FilteringSelect"
                                                                  jsId="editor_pane_parent_ou"
                                                                  store="ou_list_store"
-                                                                 searchAttr="displayLabel"
+                                                                 searchAttr="shortname"
                                                                  ignoreCase="true"
-                                                               />
+                                                               >
+                                                                       <script type="dojo/method" event="onChange">
+                                                                               this.store.setValue( current_ou, "parent_ou", this.getValue() );
+                                                                       </script>
+                                                               </div>
                                                        </td>
+                                               </tr>
+                                               <tr>
                                                        <th>OPAC Visible</th>
                                                        <td>
                                                                <input
                                                                  type="checkbox"
                                                                  dojoType="dijit.form.CheckBox"
                                                                  value='t'
-                                                               />
-                                                       </td>
-                                               </tr>
-                                               <tr>
-                                                       <th>Library Name</th>
-                                                       <td>
-                                                               <span id="editor_pane_name" dojoType="dijit.form.TextBox" jsId="editor_pane_name"/>
-                                                       </td>
-                                                       <th>Library Policy Code</th>
-                                                       <td>
-                                                               <span id="editor_pane_shortname" dojoType="dijit.form.TextBox" jsId="editor_pane_shortname"/>
-                                                       </td>
-                                               </tr>
-                                               <tr>
-                                                       <th>Main Email Address</th>
-                                                       <td>
-                                                               <span id="editor_pane_email" dojoType="dijit.form.TextBox" jsId="editor_pane_email"/>
-                                                       </td>
-                                                       <th>Main Phone Number</th>
-                                                       <td>
-                                                               <span id="editor_pane_phone" dojoType="dijit.form.TextBox" jsId="editor_pane_phone"/>
+                                                               >
+                                                                       <script type="dojo/connect" event="onChange">
+                                                                               ou_list_store.setValue( current_ou, "opac_visible", this.isChecked() ? "t":"f" );
+                                                                       </script>
+                                                               </input>
                                                        </td>
                                                </tr>
                                        </table>
+
+                                       <div dojoType="dijit.layout.ContentPane" orientation="horizontal" style="margin-bottom: 50px;">
+
+                                               <button jsId="save_ou_button" dojoType="dijit.form.Button" label="Save">
+                                                       <script type="dojo/connect" event="startup">
+                                                               this.disabled = true;
+                                                       </script>
+                                                       <script type="dojo/connect" event="onClick">
+
+                                                               var modified_ou = new aou().fromHash( current_ou );
+                                                               modified_ou.ischanged( 1 );
+                                                               modified_ou.isnew( ou_list_store.getValue( current_ou, 'isnew' ) );
+
+                                                       </script>
+                                               </button>
+
+                                               <button jsId="delete_ou_button" dojoType="dijit.form.Button" label="Delete">
+                                                       <script type="dojo/connect" event="startup">
+                                                               this.disabled = true;
+                                                       </script>
+                                                       <script type="dojo/connect" event="onClick">
+
+                                                               var modified_ou = new aou().fromHash( current_ou );
+                                                               modified_ou.isdeleted( 1 );
+
+                                                               ou_list_store.deleteItem( current_ou );
+                                                               current_ou = null;
+
+                                                       </script>
+                                               </button>
+
+                                       </div>
+
+                                       <button jsId="new_kid_button" dojoType="dijit.form.Button" label="New Child">
+                                               <script type="dojo/connect" event="startup">
+                                                       this.disabled = true;
+                                               </script>
+                                               <script type="dojo/connect" event="onClick">
+
+                                                       var new_ou = ou_list_store.newItem(
+                                                               { id            : virgin_ou_id--,
+                                                                 isnew         : 1,
+                                                                 parent_ou     : ou_list_store.getValue( current_ou, 'id' ),
+                                                               },
+                                                               { parent : current_ou, attribute : 'children' }
+                                                       );
+
+                                                       current_ou = new_ou;
+
+                                               </script>
+                                       </button>
+
                                </div>
+
+                               <div id="hoo_pane" dojoType="dijit.layout.ContentPane" title="Hours of Operation">
+                               </div>
+
                        </div>
 
                </div>
diff --git a/Open-ILS/web/conify/js/conify/fieldmapper/addFromHash.js b/Open-ILS/web/conify/js/conify/fieldmapper/addFromHash.js
new file mode 100644 (file)
index 0000000..c742378
--- /dev/null
@@ -0,0 +1,12 @@
+
+function _fromHash (_hash) {
+       var _fields = fmclasses[this.classname];
+       for ( var i=0; i < _fields.length; i++) {
+               if (_hash[_fields[i]] != null)
+                       this[_fields[i]]( _hash[_fields[i]] );
+       }
+       return this;
+}
+
+for (var i in fmclasses) window[i].prototype.fromHash = _fromHash;
+
diff --git a/Open-ILS/web/conify/js/conify/fieldmapper/addToStoreData.js b/Open-ILS/web/conify/js/conify/fieldmapper/addToStoreData.js
new file mode 100644 (file)
index 0000000..e5d097e
--- /dev/null
@@ -0,0 +1,66 @@
+
+function _toStoreData (list, label, params) {
+
+       // a sane default
+       if (!params.identifier) params.identifier = 'id';
+
+       var data = { label : 'shortname', identifier : 'id', items : [] };
+
+       for (var i in list) data.items.push( list[i].toHash() );
+
+       if (params.children && params['parent']) {
+               var _hash_list = data.items;
+
+               var _find_root = {};
+               for (var i in _hash_list) {
+                       _find_root[_hash_list[i][params.identifier]] = _hash_list[i]; 
+               }
+
+               var item_data = [];
+               for (var i in _hash_list) {
+                       var obj = _hash_list[i]
+                       obj[params.children] = [];
+
+                       for (var j in _hash_list) {
+                               var kid = _hash_list[j];
+                               if (kid[params['parent']] == obj[params.identifier]) {
+                                       obj[params.children].push( { _reference : kid[params.identifier] } );
+                                       kid._iskid = true;
+                                       if (_find_root[kid[params.identifier]]) delete _find_root[kid[params.identifier]];
+                               }
+                       }
+
+                       item_data.push( obj );
+               }
+
+               for (var j in _find_root) {
+                       _find_root[j]['_top'] = 'true';
+                       if (!_find_root[j][params['parent']])
+                               _find_root[j]['_trueRoot'] = 'true';
+               }
+
+               data.items = item_data;
+       }
+
+       return data;
+}
+
+// set up the defaults
+for (var i in fmclasses) window[i].toStoreData = _toStoreData;
+
+aou.toStoreData = function (list, label) {
+       if (!label) label = 'shortname';
+       return _toStoreData(list, label, { 'parent' : 'parent_ou', 'children' : 'children' });
+}
+
+aout.toStoreData = function (list, label) {
+       if (!label) label = 'name';
+       return _toStoreData(list, label, { 'parent' : 'parent', 'children' : 'children' });
+}
+
+pgt.toStoreData = function (list, label) {
+       if (!label) label = 'name';
+       return _toStoreData(list, label, { 'parent' : 'parent', 'children' : 'children' });
+}
+
+