Patch from Warren Layton at Laurentian university which addresses some issues
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 25 Sep 2009 01:16:05 +0000 (01:16 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 25 Sep 2009 01:16:05 +0000 (01:16 +0000)
saving org unit data via the conify interfaces.

Thanks, Warren, and sorry for the delay.

M    Open-ILS/web/conify/global/actor/org_unit.js
M    Open-ILS/web/conify/global/actor/org_unit.html
M    Open-ILS/examples/fm_IDL.xml

git-svn-id: svn://svn.open-ils.org/ILS/trunk@14165 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/web/conify/global/actor/org_unit.html
Open-ILS/web/conify/global/actor/org_unit.js

index 79bd435..fe7fd4e 100644 (file)
@@ -1511,14 +1511,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field name="org_unit" oils_persist:virtual="true" reporter:datatype="org_unit"/>
                </fields>
                <links>
-                       <link field="org_unit" reltype="might_have" key="id" map="" class="aou"/>
+                       <link field="id" reltype="might_have" key="id" map="" class="aou"/>
                </links>
         <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
             <actions>
-                <create permission="CREATE_HOURS_OF_OPERATION" context_field="org_unit"/>
+                <create permission="CREATE_HOURS_OF_OPERATION" context_field="id"/>
                 <retrieve/>
-                <update permission="UPDATE_HOURS_OF_OPERATION" context_field="org_unit"/>
-                <delete permission="DELETE_HOURS_OF_OPERATION" context_field="org_unit"/>
+                <update permission="UPDATE_HOURS_OF_OPERATION" context_field="id"/>
+                <delete permission="DELETE_HOURS_OF_OPERATION" context_field="id"/>
             </actions>
         </permacrud>
        </class>
index 5f08602..d0d85d1 100644 (file)
                                                                                var modified_ou = new aou().fromStoreItem( current_ou );
                                                                                modified_ou.isdeleted( 1 );
        
-                                                                               pCRUD.request({
-                                                                                       method : 'open-ils.pcrud.delete.aou',
+                                                                               pcrud.eliminate( modified_ou, {
                                                                                        timeout : 10,
-                                                                                       params : [ ses, modified_ou ],
                                                                                        onerror : function (r) {
                                                                                                highlighter.editor_pane.red.play();
                                                                                                status_update(dojo.string.substitute(aou_strings.ERROR_DELETING, [old_name]));
                                                                                        },
                                                                                        oncomplete : function (r) {
-                                                                                               var res = r.recv();
-                                                                                               if ( res && res.content() ) {
-       
-                                                                                                       ou_list_store.fetch({
-                                                                                                               query : { id : ou_list_store.getValue( current_ou, 'id' ) },
-                                                                                                               queryOptions : { deep : true },
-                                                                                                               onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
-                                                                                                               scope : ou_list_store
-                                                                                                       });
-       
-                                                                                                       current_ou = null;
-       
-                                                                                                       new_kid_button.disabled = true;
-                                                                                                       save_ou_button.disabled = true;
-                                                                                                       delete_ou_button.disabled = true;
-                       
-                                                                                                       var main_settings_fields = [ 'name', 'shortname', 'email', 'phone', 'ou_type', 'parent_ou' ];
-                                                                                                       for ( var i in main_settings_fields ) {
-                                                                                                               var field = main_settings_fields[i];
-                                                                                                               window["editor_pane_" + field].setValue( '' ); // unset the value
-                                                                                                               window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
-                                                                                                       }
-                       
-                                                                                                       highlighter.editor_pane.green.play();
-                                                                                                       status_update(dojo.string.substitute(aou_strings.STATUS_DELETED, [old_name]));
-                                                                                               } else {
-                                                                                                       highlighter.editor_pane.red.play();
-                                                                                                       status_update(dojo.string.substitute(aou_strings.ERROR_DELETING, [old_name]));
+                                                                                               ou_list_store.fetch({
+                                                                                                       query : { id : ou_list_store.getValue( current_ou, 'id' ) },
+                                                                                                       queryOptions : { deep : true },
+                                                                                                       onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
+                                                                                                       scope : ou_list_store
+                                                                                               });
+
+                                                                                               current_ou = null;
+
+                                                                                               new_kid_button.disabled = true;
+                                                                                               save_ou_button.disabled = true;
+                                                                                               delete_ou_button.disabled = true;
+
+                                                                                               var main_settings_fields = [ 'name', 'shortname', 'email', 'phone', 'ou_type', 'parent_ou' ];
+                                                                                               for ( var i in main_settings_fields ) {
+                                                                                                       var field = main_settings_fields[i];
+                                                                                                       window["editor_pane_" + field].setValue( '' ); // unset the value
+                                                                                                       window["editor_pane_" + field].setDisplayedValue( '' ); // unset the value
                                                                                                }
+
+                                                                                               highlighter.editor_pane.green.play();
+                                                                                               status_update(dojo.string.substitute(aou_strings.STATUS_DELETED, [old_name]));
                                                                                        }
-                                                                               }).send();
-       
+                                                                               });
                                                                        }
 ]]>
                                                                </script>
        
                                                                var new_obj;
        
-                                                               pCRUD.request({
-                                                                       method : 'open-ils.pcrud.create.aou',
+                                                               pcrud.create( new_fm_obj, {
                                                                        timeout : 10,
-                                                                       params : [ ses, new_fm_obj ],
                                                                        onerror : function (r) {
                                                                                highlighter.editor_pane.red.play();
                                                                                status_update( aou_strings.ERROR_CREATING_CHILD_AOU );
                                                                                        highlighter.editor_pane.red.play();
                                                                                        status_update( aou_strings.ERROR_CREATING_CHILD_AOU );
                                                                                }
-                                                                       },
-                                                               }).send();
+                                                                       }
+                                                               });
        
                                                                highlighter.editor_pane.green.play();
                                                                highlighter.ou_tree.green.play();
                                                </table>
        
                                                <button jsId="save_hoo_button" dojoType="dijit.form.Button" label="&conify.save_button.label;">
+                            <script type="dojo/connect" event="startup">
+                                this.disabled = true;
+                            </script>
                                                        <script type="dojo/connect" event="onClick">
 <![CDATA[
-                                                               var method_name = 'open-ils.pcrud.update.aouhoo';
-                                                               if (current_ou_hoo.isnew() == 1) method_name = 'open-ils.pcrud.create.aouhoo';
-       
-                                                               pCRUD.request({
-                                                                       method : method_name,
-                                                                       params : [ ses, current_ou_hoo ],
-                                                                       onerror : function (r) {
-                                                                               highlighter.editor_pane.red.play();
-                                                                               status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_HOO, [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();
+                                                               if (hoo_id.length == 0) {
+                                                                       pcrud.create( current_ou_hoo, {
+                                                                               timeout : 10,
+                                                                               onerror : function (r) {
+                                                                                       highlighter.hoo_pane.red.play();
+                                                                                       status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_HOO, [ou_list_store.getValue( current_ou, 'name' )] ) );
+                                                                               },
+                                                                               oncomplete : function (r) {
+                                                                                       hoo_id = pcrud.search( 'aouhoo',{id:ou_list_store.getValue( current_ou, 'id' )});
+                                                                                       highlighter.hoo_pane.green.play();
                                                                                        status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVING_HOO, [ou_list_store.getValue( current_ou, 'name' )] ) );
-                                                                               } else {
-                                                                                       highlighter.editor_pane.red.play();
+                                                                               },
+                                                                       });
+                                                               } else {
+                                                                       pcrud.update( current_ou_hoo, {
+                                                                               timeout : 10,
+                                                                               onerror : function (r) {
+                                                                                       highlighter.hoo_pane.red.play();
                                                                                        status_update( dojo.string.substitute( aou_strings.ERROR_SAVING_HOO, [ou_list_store.getValue( current_ou, 'name' )] ) );
-                                                                               }
-                                                                       },
-                                                               }).send();
+                                                                               },
+                                                                               oncomplete : function (r) {
+                                                                                       highlighter.hoo_pane.green.play();
+                                                                                       status_update( dojo.string.substitute( aou_strings.SUCCESS_SAVING_HOO, [ou_list_store.getValue( current_ou, 'name' )] ) );
+                                                                               },
+                                                                       });
+                                                               }
+       
 ]]>
                                                        </script>
                                                </button>
index b139e1c..d923270 100644 (file)
@@ -42,7 +42,7 @@ var ses = cookieManager.read('ses') || cgi.param('ses');
 var pCRUD = new OpenSRF.ClientSession('open-ils.pcrud');
 var pcrud = new openils.PermaCrud({ authtoken : ses });
 
-var current_ou, current_ou_hoo, ou_list_store
+var current_ou, current_ou_hoo, ou_list_store, hoo_id;
 var dirtyStore = [];
 var virgin_ou_id = -1;
 
@@ -65,7 +65,7 @@ function save_org () {
        var modified_ou = new aou().fromStoreItem( current_ou );
        modified_ou.ischanged( 1 );
 
-    pcrud.apply( modified_ou, {
+       pcrud.update( modified_ou, {
         timeout : 10, // makes it synchronous
                onerror : function (r) {
                        highlighter.editor_pane.red.play();
@@ -87,46 +87,33 @@ function save_org () {
 }
        
 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.pcrud.retrieve.aouhoo',
-               params : [ ses, ou_list_store.getValue( current_ou, 'id' ) ],
-               onerror : function (r) { 
-                       throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOURS, [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']() )
-                               );
+       save_hoo_button.disabled = false;
+
+       hoo_id = pcrud.search( 'aouhoo',{id:ou_list_store.getValue( current_ou, 'id' )});
+       if (hoo_id.length == 0) {
+               current_ou_hoo = new aouhoo().fromHash({id:ou_list_store.getValue( current_ou, 'id' )});
+               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');
+               }
+       } else {
+               current_ou_hoo = pcrud.retrieve( 'aouhoo', ou_list_store.getValue( current_ou, 'id' ), {
+                       onerror : function (r) {
+                               throw dojo.string.substitute(aou_strings.ERROR_FETCHING_HOURS,[ou_list_store.getValue( current_ou, 'name' )]);
                        }
+               });
+       }
 
-                       highlighter.hoo_pane.green.play();
-               }
-       }).send();
+       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();
 }
 
 function addr_load () {