added some more utility code and css
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 3 Feb 2006 20:43:22 +0000 (20:43 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 3 Feb 2006 20:43:22 +0000 (20:43 +0000)
copy locations editor now functions

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

Open-ILS/xul/staff_client/server/admin/admin.css
Open-ILS/xul/staff_client/server/admin/adminlib.js
Open-ILS/xul/staff_client/server/admin/copy_locations.js
Open-ILS/xul/staff_client/server/admin/copy_locations.xml
Open-ILS/xul/staff_client/server/admin/non_cat_types.js

index 2979b0e..8f7acf9 100644 (file)
@@ -12,4 +12,4 @@
 .padded { padding-left: 7px; padding-right: 7px; }
 select { width: 12em; }
 .select_big { width: 15em; }
-
+.context_help { font-weight: bold; color: blue; }
index 945416b..af55c16 100644 (file)
@@ -52,7 +52,24 @@ function cleanTbody(tbody, key) {
 }
 
 
+/** Inserts a row into a specified place in a table
+  * tbody is the table body
+  * row is the context row after which the new row is to be inserted
+  * newRow is the new row to insert
+  */
 function insRow( tbody, row, newRow ) {
        if(row.nextSibling) tbody.insertBefore( newRow, row.nextSibling );
        else{ tbody.appendChild(newRow); }
 }
+
+
+/** Checks to see if a given node should be enabled
+  * A node should be enabled if the itemOrg is lower in the
+  * org tree than my permissions allow editing
+  * I.e. I can edit the context item because it's "below" me
+  */
+function checkDisabled( node, itemOrg, perm ) {
+       var itemDepth = findOrgDepth(itemOrg);
+       var mydepth = findOrgDepth(PERMS[perm]);
+       if( mydepth != -1 && mydepth <= itemDepth ) node.disabled = false;
+}
index b029aae..be60fa2 100644 (file)
@@ -21,8 +21,14 @@ function clEditorInit() {
        $('user').appendChild(text(USER.usrname()));
        YES = $('yes').innerHTML;
        NO = $('no').innerHTML;
-       setTimeout( function() { 
-               fetchHighestPermOrgs( SESSION, USER.id(), myPerms ); clGo(); }, 20 );
+
+       setTimeout( 
+               function() { 
+                       fetchHighestPermOrgs( SESSION, USER.id(), myPerms ); 
+                       $('cl_new_name').focus();
+                       clBuildNew();
+                       clGo(); 
+               }, 20 );
 }
 
 
@@ -30,12 +36,41 @@ function clHoldMsg() {
        alert($('cl_hold_msg').innerHTML);
 }
 
-function clGo() {
+function clGo() {      
        var req = new Request(RETRIEVE_CL, SESSION, USER.home_ou());
        req.callback(clDraw);
        req.send();
 }
 
+function clBuildNew() {
+       org = PERMS['CREATE_COPY_LOCATION'];
+       if(org == -1) return;
+       var selector = $('cl_new_owner');
+       org = findOrgUnit(org);
+       buildOrgSel(selector, org, findOrgDepth(org));
+       if(org.children() && org.children()[0]) 
+               selector.disabled = false;
+
+       var sub = $('sc_new_submit');
+       sub.disabled = false;
+       sub.onclick = clCreateNew;
+}
+
+function clCreateNew() {
+       var cl = new acpl();
+       cl.name( $('cl_new_name').value );
+       cl.owning_lib( getSelectorVal( $('cl_new_owner')));
+       cl.holdable( ($('cl_new_hold_yes').checked) ? 1 : 0 );
+       cl.opac_visible( ($('cl_new_vis_yes').checked) ? 1 : 0 );
+       cl.circulate( ($('cl_new_circulate_yes').checked) ? 1 : 0 );
+
+       var req = new Request(CREATE_CL, SESSION, cl);
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+       clGo();
+}
+
 var rowTemplate;
 function clDraw(r) {
 
@@ -67,44 +102,83 @@ function clBuildRow( tbody, row, cl ) {
        $n( row, 'cl_holdable').appendChild(text( (cl.holdable()) ? YES : NO ) );
        $n( row, 'cl_visible').appendChild(text( (cl.opac_visible()) ? YES : NO ) );
        $n( row, 'cl_circulate').appendChild(text( (cl.circulate()) ? YES : NO ) );
-       $n( row, 'cl_edit').onclick = function() { clEdit( cl, tbody, row ); };
+
+       var edit = $n( row, 'cl_edit');
+       edit.onclick = function() { clEdit( cl, tbody, row ); };
+       checkDisabled( edit, cl.owning_lib(), 'UPDATE_COPY_LOCATION');
+
+       var del = $n( row, 'cl_delete' );
+       del.onclick = function() { clDelete( cl, tbody, row ); };
+       checkDisabled( del, cl.owning_lib(), 'DELETE_COPY_LOCATION');
 }
 
 function clEdit( cl, tbody, row ) {
 
        cleanTbody(tbody, 'edit');
-       var r = $('cl_new').cloneNode(true);
+       var r = $('cl_edit').cloneNode(true);
        r.setAttribute('edit','1');
        
-       var name = $n(r, 'cl_new_name');
+       var name = $n(r, 'cl_edit_name');
        name.setAttribute('size', cl.name().length + 3);
        name.value = cl.name();
 
-       $n(r, 'cl_new_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
-
-       var yhold = $n( $n(r,'cl_new_holdable_yes'), 'cl_new_holdable');
-       var nhold = $n( $n(r,'cl_new_holdable_no'), 'cl_new_holdable');
-       var yvis = $n( $n(r,'cl_new_visible_yes'), 'cl_new_visible');
-       var nvis = $n( $n(r,'cl_new_visible_no'), 'cl_new_visible');
-       var ycirc = $n( $n(r,'cl_new_circulate_yes'), 'cl_new_circulate');
-       var ncirc = $n( $n(r,'cl_new_circulate_no'), 'cl_new_circulate');
+       $n(r, 'cl_edit_owner').appendChild(text(findOrgUnit(cl.owning_lib()).name()));
 
-       if(cl.holdable()) yhold.checked = true;
-       else nhold.checked = true;
-       if(cl.opac_visible()) yvis.checked = true;
-       else nvis.checked = true;
-       if(cl.circulate()) ycirc.checked = true;
-       else ncirc.checked = true;
+       var arr = _clOptions(r);
+       if(cl.holdable()) arr[0].checked = true;
+       else arr[1].checked = true;
+       if(cl.opac_visible()) arr[2].checked = true;
+       else arr[3].checked = true;
+       if(cl.circulate()) arr[4].checked = true;
+       else arr[5].checked = true;
 
-       $n(r, 'cl_new_cancel').onclick = function(){cleanTbody(tbody,'edit');}
-       $n(r, 'cl_new_commit').onclick = function(){clEditCommit( tbody, cl ); }
+       $n(r, 'cl_edit_cancel').onclick = function(){cleanTbody(tbody,'edit');}
+       $n(r, 'cl_edit_commit').onclick = function(){clEditCommit( tbody, r, cl ); }
 
        insRow(tbody, row, r);
        name.focus();
        name.select();
 }
 
-function clEditCommit( tbody, cl ) {
-       alert("committing: " + cl.id());        
-       cleanTbody(tbody,'edit');
+function _clOptions(r) {
+       var arr = [];
+       arr[0] = $n( $n(r,'cl_edit_holdable_yes'), 'cl_edit_holdable');
+       arr[1] = $n( $n(r,'cl_edit_holdable_no'), 'cl_edit_holdable');
+       arr[2] = $n( $n(r,'cl_edit_visible_yes'), 'cl_edit_visible');
+       arr[3] = $n( $n(r,'cl_edit_visible_no'), 'cl_edit_visible');
+       arr[4] = $n( $n(r,'cl_edit_circulate_yes'), 'cl_edit_circulate');
+       arr[5] = $n( $n(r,'cl_edit_circulate_no'), 'cl_edit_circulate');
+       return arr;
 }
+
+function clEditCommit( tbody, r, cl ) {
+
+       var arr = _clOptions(r);
+       if(arr[0].checked) cl.holdable(1);
+       else cl.holdable(0);
+       if(arr[2].checked) cl.opac_visible(1);
+       else cl.opac_visible(0);
+       if(arr[4].checked) cl.circulate(1);
+       else cl.circulate(0);
+       cl.name($n(r, 'cl_edit_name').value);
+
+       var req = new Request( UPDATE_CL, SESSION, cl );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+
+       clGo();
+}
+
+
+function clDelete( cl, tbody, row ) {
+       if(!confirm($('cl_delete_confirm').innerHTML)) return;
+       var req = new Request( DELETE_CL, SESSION, cl.id() );
+       req.send(true);
+       var res = req.result();
+       if(checkILSEvent(res)) throw res;
+
+       clGo();
+}
+
+
index 15a4204..0468cfd 100644 (file)
 
                <center>
                        <div class='title'> Copy Locations Editor </div>
+                       <br/>
+
+                       <table class='data_grid data_grid_center' width='65%'>
+                               <thead>
+                                       <tr><td colspan='4'>Create a new copy location</td></tr>
+                               </thead>
+                               <tbody>
+                                       <tr>
+                                               <td id='id'>Name: </td>
+                                               <td>
+                                                       <input id='cl_new_name' type='text' size='10'/>
+                                               </td>
+                                               <td>Holdable: </td>
+                                               <td>
+                                                       <span>Yes</span>
+                                                       <input type='radio' name='cl_new_hold' id='cl_new_hold_yes'/>
+                                                       <span>No</span>
+                                                       <input type='radio' name='cl_new_hold'  
+                                                               id='cl_new_hold_no' checked='checked'> </input>
+                                               </td>
+                                       </tr>
+
+                                       <tr>
+                                               <td>OPAC Visible: </td>
+                                               <td>
+                                                       <span>Yes</span>
+                                                       <input type='radio' name='cl_new_vis' id='cl_new_vis_yes' />
+                                                       <span>No</span>
+                                                       <input type='radio' name='cl_new_vis'  id='cl_new_vis_no' checked='checked'> </input>
+                                               </td>
+                                               <td>Circulate: </td>
+                                               <td>
+                                                       <span>Yes</span>
+                                                       <input type='radio' name='cl_new_circulate' id='cl_new_circulate_yes' />
+                                                       <span>No</span>
+                                                       <input type='radio' name='cl_new_circulate'  
+                                                               id='cl_new_circulate_no' checked='checked'> </input>
+                                               </td>
+                                       </tr>
+                                       <tr>
+                                               <td>Owning Library:</td>
+                                               <td colspan='2' >
+                                                       <select id='cl_new_owner' disabled='disabled'> </select>
+                                               </td>
+                                               <td><input id='sc_new_submit' type='submit' value='Create' disabled='disabled'/></td>
+                                       </tr>
+                               </tbody>
+                       </table>
+
+                       <br/><hr/><br/>
 
 
                        <table class='data_grid data_grid_center' style='width: 95%'>
@@ -40,7 +90,7 @@
                                                <td width='20%'>Owning Library</td>
                                                <td width='15%'>
                                                        <span>Holdable </span>
-                                                       <a class='context_help' href='javascript:void(0);' onclick='clHoldMsg();'> ??</a>
+                                                       <a class='context_help' href='javascript:clHoldMsg();'> ??</a>
                                                </td>
                                                <td width='15%'>OPAC Visible</td>
                                                <td width='15%'>Circulate</td>
                                                <td name='cl_holdable'> </td>
                                                <td name='cl_visible'> </td>
                                                <td name='cl_circulate'> </td>
-                                               <td><input type='submit' value='Edit' name='cl_edit'> </input></td>
-                                               <td><input type='submit' value='Delete' name='cl_delete'> </input></td>
+                                               <td><input type='submit' value='Edit' name='cl_edit' disabled='disabled'> </input></td>
+                                               <td><input type='submit' value='Delete' name='cl_delete' disabled='disabled'> </input></td>
                                        </tr>
                                </tbody>
                        </table>
                        <span id='cl_hold_msg'>
                                If a copy location is "Holdable", copies in that location may have holds placed on them.
                        </span>
+                       <span id='cl_delete_confirm'>
+                               Are you sure you wish to delete the selected copy location?
+                               Note: If copies are currently attached to this location, the delete operation will fail.
+                       </span>
                        <table>
                                <tbody>
-                                       <tr id='cl_new' class='insert_row'>
-                                               <td><input name='cl_new_name' type='text'> </input></td>
-                                               <td name='cl_new_owner'></td>
+                                       <tr id='cl_edit' class='insert_row'>
+                                               <td><input name='cl_edit_name' type='text'> </input></td>
+                                               <td name='cl_edit_owner'></td>
                                                <td>
                                                        <span>Yes</span>
-                                                       <span name='cl_new_holdable_yes'>
-                                                               <input type='radio' name='cl_new_holdable'/>
+                                                       <span name='cl_edit_holdable_yes'>
+                                                               <input type='radio' name='cl_edit_holdable'/>
                                                        </span>
                                                        <span>No</span>
-                                                       <span name='cl_new_holdable_no'>
-                                                               <input type='radio' name='cl_new_holdable'/>
+                                                       <span name='cl_edit_holdable_no'>
+                                                               <input type='radio' name='cl_edit_holdable'/>
                                                        </span>
                                                </td>
                                                <td>
                                                        <span>Yes</span>
-                                                       <span name='cl_new_visible_yes'>
-                                                               <input type='radio' name='cl_new_visible'/>
+                                                       <span name='cl_edit_visible_yes'>
+                                                               <input type='radio' name='cl_edit_visible'/>
                                                        </span>
                                                        <span>No</span>
-                                                       <span name='cl_new_visible_no'>
-                                                               <input type='radio' name='cl_new_visible'/>
+                                                       <span name='cl_edit_visible_no'>
+                                                               <input type='radio' name='cl_edit_visible'/>
                                                        </span>
                                                </td>
                                                <td>
                                                        <span>Yes</span>
-                                                       <span name='cl_new_circulate_yes'>
-                                                               <input type='radio' name='cl_new_circulate'/>
+                                                       <span name='cl_edit_circulate_yes'>
+                                                               <input type='radio' name='cl_edit_circulate'/>
                                                        </span>
                                                        <span>No</span>
-                                                       <span name='cl_new_circulate_no'>
-                                                               <input type='radio' name='cl_new_circulate'/>
+                                                       <span name='cl_edit_circulate_no'>
+                                                               <input type='radio' name='cl_edit_circulate'/>
                                                        </span>
                                                </td>
-                                               <td><input type='submit' name='cl_new_commit' value='Submit'/></td>
-                                               <td><input type='submit' name='cl_new_cancel' value='Cancel'/></td>
+                                               <td><input type='submit' name='cl_edit_commit' value='Submit'/></td>
+                                               <td><input type='submit' name='cl_edit_cancel' value='Cancel'/></td>
                                        </tr>
                                </tbody>
                        </table>
index 33d33a3..c83bccf 100644 (file)
@@ -84,9 +84,8 @@ function ncDisplayTypes(r) {
 }
 
 function ncSetRowCallbacks( type, owner, tbody, row ) {
-       var tdepth = findOrgDepth( owner );
-       var mydepth = findOrgDepth( PERMS['UPDATE_NON_CAT_TYPE'] );
-       if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_edit').disabled = false;
+
+       checkDisabled( $n(row, 'nc_edit'), owner, 'UPDATE_NON_CAT_TYPE');
 
        mydepth = findOrgDepth( PERMS['DELETE_NON_CAT_TYPE'] );
        if( mydepth != -1 && mydepth <= tdepth ) $n(row, 'nc_delete').disabled = false;