From e267ad6ca5e5041c779fcdda1e12d11157670c7e Mon Sep 17 00:00:00 2001 From: Joseph Lewis Date: Mon, 4 Jun 2012 13:13:22 -0600 Subject: [PATCH] Updated perm_list to work with dojo 1.4 --- .../web/conify/global/permission/perm_list.html | 205 +++------------------ Open-ILS/web/conify/global/permission/perm_list.js | 156 +++++++++++++++- 2 files changed, 176 insertions(+), 185 deletions(-) diff --git a/Open-ILS/web/conify/global/permission/perm_list.html b/Open-ILS/web/conify/global/permission/perm_list.html index 680cf6104f..22c50e3061 100644 --- a/Open-ILS/web/conify/global/permission/perm_list.html +++ b/Open-ILS/web/conify/global/permission/perm_list.html @@ -1,3 +1,8 @@ + +]> - -]> - + + &conify.perm_list.permission_list.title; - + @@ -57,88 +63,9 @@ - + - - - - - - @@ -147,107 +74,17 @@
&conify.perm_list.new_permission.label;
- +
-
-
-
-
-
- -
- - - - - +
+ + +
- - - diff --git a/Open-ILS/web/conify/global/permission/perm_list.js b/Open-ILS/web/conify/global/permission/perm_list.js index ff303f965c..d7924c96bd 100644 --- a/Open-ILS/web/conify/global/permission/perm_list.js +++ b/Open-ILS/web/conify/global/permission/perm_list.js @@ -31,7 +31,9 @@ dojo.require('dijit.layout.LayoutContainer'); dojo.require('dijit.layout.BorderContainer'); dojo.require('dojox.widget.Toaster'); dojo.require('dojox.fx'); -dojo.require('dojox.grid.Grid'); +dojo.require("dojox.grid.cells.dijit"); +dojo.require("dojo.data.ItemFileWriteStore"); +dojo.require('dojox.grid.DataGrid'); dojo.requireLocalization("openils.conify", "conify"); // some handy globals @@ -97,3 +99,155 @@ function save_them_all (event) { dojo.addOnUnload( save_them_all ); + + + +var dirtyStore = []; +var perm_rows = []; + +var _perm_list = pCRUD.retrieveAll('ppl', { order_by : { ppl : 'code' } }); +var _perm_data = ppl.toStoreData( _perm_list, 'code' ); +var perm_store = new dojo.data.ItemFileWriteStore({ data : _perm_data }); + + +perm_store.onSet = function (item, attr, o, n) { + if (attr == 'ischanged') return; + if (n == o) return; + this.setValue( item, 'ischanged', 1); +}; + + +var perm_grid_layout = [ + { cells : [ + [ + { name : ppl_strings.LABEL_CODE, field : "code", width : "300px", rowSpan : "2", editable : true }, + { name : ppl_strings.LABEL_DESCRIPTION, field : "description", width : "auto", style : "minHeight:1em;", editable : true } + ], + [ + { name : ppl_strings.LABEL_TRANSLATION, + width : "10em", + height : "2em", + formatter : function (value) { + return ''; + }, + get : function (row) { + var r = perm_grid.getItem(row); + if (r) { + perm_rows[row] = new ccs().fromHash(perm_grid.getItem(row)); + setTimeout( + 'dojo.query(".perm_grid_trans_desc_' + row + '").'+ + 'instantiate(openils.widget.TranslatorPopup,{field:"description",'+ + 'targetObject:"window.perm_rows['+row+']"});'+ + 'perm_grid.rowHeightChanged('+row+')', + 0 + ); + var oldnode = dojo.byId('description_translation_' + row); + if (oldnode) dijit.byNode(oldnode).destroyRecursive(); + return row; + } + return ''; + } + } + ] + ] + } +]; + +dojo.addOnUnload( function (event) { + + perm_store.fetch({ + query : { ischanged : 1 }, + onItem : function (item, req) { try { if (this.isItem( item )) dirtyStore.push( item ); } catch (e) { /* meh */ } }, + scope : perm_store + }); + + if (dirtyStore.length > 0) { + var confirmation = confirm(ppl_strings.CONFIRM_EXIT_PPL); + + if (confirmation) { + for (var i in dirtyStore) { + current_perm = dirtyStore[i]; + save_perm(true); + } + } + } + +}); + + + +function saveNewPermCode() +{ +var new_code = new_perm_code.getValue(); + if (!new_code) return; + + var new_fm_obj = new ppl().fromHash({ + isnew : 1, + code : new_code + }); + + var err = false; + pCRUD.create(new_fm_obj, { + onerror : function (r) { + highlighter.red.play(); + status_update( ppl_strings.ERROR_CALLING_METHOD_PPL ); + err = true; + }, + oncomplete : function (r, list) { + var new_item_hash = list[0].toHash(); + perm_store.newItem( new_item_hash ); + status_update( dojo.string.substitute(ppl_strings.SUCCESS_CREATING_PERMISSION, [new_item_hash.code]) ); + perm_grid.model.sort(-1); + highlighter.green.play(); + } + }); +} + +function delete_them() +{ + var selected_rows = perm_grid.selection.getSelected(); + var selected_items = []; + + for (var i in selected_rows) { + selected_items.push( + perm_grid.model.getRow( selected_rows[i] ).__dojo_data_item + ); + } + + perm_grid.selection.clear(); + + for (var i in selected_items) { + current_perm = selected_items[i]; + + if ( confirm( dojo.string.substitute(ppl_strings.CONFIRM_DELETE, [perm_store.getValue(current_perm, 'code')]) ) ) { + + perm_store.setValue( current_perm, 'isdeleted', 1 ); + + var modified_ppl = new ppl().fromStoreItem( current_perm ); + modified_ppl.isdeleted( 1 ); + + pCRUD.eliminate(modified_ppl, { + onerror : function (r) { + highlighter.red.play(); + status_update( dojo.string.substitute(ppl_strings.ERROR_DELETING, [perm_store.getValue( current_perm, 'code' )]) ); + }, + oncomplete : function (r) { + var old_name = perm_store.getValue( current_perm, 'code' ); + + perm_store.fetch({ + query : { id : perm_store.getValue( current_perm, 'id' ) }, + onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } }, + scope : perm_store + }); + + current_perm = null; + + highlighter.green.play(); + status_update( dojo.string.substitute(ppl_strings.STATUS_DELETED, [old_name]) ); + } + }); + + } + } +} + -- 2.11.0