dojo.require('dijit.form.TextBox');
dojo.require('dijit.form.ValidationTextBox');
dojo.require('dijit.form.Textarea');
+dojo.require('dijit.form.CheckBox');
dojo.require('dijit.layout.ContentPane');
dojo.require('dijit.layout.LayoutContainer');
dojo.require('dijit.layout.BorderContainer');
+dojo.require('dijit.Toolbar');
+dojo.require('dijit.ToolbarSeparator');
dojo.require('dojox.widget.Toaster');
dojo.require('dojox.fx');
dojo.require('openils.XUL');
dojo.require('dojox.grid.cells.dijit');
-dojo.require('dojo.data.ItemFileWriteStore');
dojo.require('dojox.grid.DataGrid');
dojo.requireLocalization("openils.conify", "conify");
pCRUD.update(modified_ccs, {
onerror : function (r) {
highlighter.red.play();
- status_update( dojo.string.substitute(ccs_strings.ERROR_SAVING_STATUS, [status_store.getValue( current_status, 'name' )]) );
+ status_update( dojo.string.substitute(ccs_strings.ERROR_SAVING_STATUS, [current_status.name]));
},
oncomplete : function (r) {
status_store.setValue( current_status, 'ischanged', 0 );
highlighter.green.play();
- status_update( dojo.string.substitute(ccs_strings.SUCCESS_SAVE, [status_store.getValue( current_status, 'name' )]) );
+ status_update( dojo.string.substitute(ccs_strings.SUCCESS_SAVE, [current_status.name] ));
}
});
}
var new_item_hash = list[0].toHash();
status_store.newItem( new_item_hash );
status_update( dojo.string.substitute(ccs_strings.SUCCESS_CREATING_STATUS, [new_item_hash.name]) );
- status_grid.model.sort(-2);
+ status_grid.sort(-2);
highlighter.green.play();
}
});
function delete_them()
{
var selected_rows = status_grid.selection.getSelected();
+
+ status_grid.removeSelectedRows();
- var selected_items = [];
for (var i in selected_rows) {
- selected_items.push(
- status_grid.getItem( selected_rows[i] ).__dojo_data_item
- );
- }
+ const current_status = selected_rows[i];
- status_grid.selection.clear();
+ if ( confirm(dojo.string.substitute(ccs_strings.CONFIRM_DELETE, [current_status['name']]))) {
- for (var i in selected_items) {
- current_status = selected_items[i];
-
- if ( confirm(dojo.string.substitute(ccs_strings.CONFIRM_DELETE, [status_store.getValue( current_status, 'name' )]))) {
-
- status_store.setValue( current_status, 'isdeleted', 1 );
+ current_status['isdeleted'] = 1;
var modified_ccs = new ccs().fromStoreItem( current_status );
modified_ccs.isdeleted( 1 );
pCRUD.eliminate(modified_ccs, {
onerror : function (r) {
highlighter.red.play();
- status_update( dojo.string.substitute( ccs_strings.ERROR_DELETING, [status_store.getValue( current_status, 'name' )] ) );
+ status_update( dojo.string.substitute( ccs_strings.ERROR_DELETING, [current_status['name']] ) );
+ onsole.log("pcrud couldn't delete: ", current_status['name']);
},
oncomplete : function (r) {
- var old_name = status_store.getValue( current_status, 'name' );
-
- status_store.fetch({
- query : { id : status_store.getValue( current_status, 'id' ) },
- onItem : function (item, req) { try { if (this.isItem( item )) this.deleteItem( item ); } catch (e) { /* meh */ } },
- scope : status_store
- });
-
- current_status = null;
-
highlighter.green.play();
- status_update( dojo.string.substitute(ccs_strings.STATUS_DELETED, [old_name]) );
}
});
}
}
-
-var status_grid_layout = [
-{ cells : [
- [
- { name : ccs_strings.ID,
- field : "id",
- },
- { name : ccs_strings.NAME,
- field : "name",
- width : "auto",
- //editor : dojox.grid.editors.Dijit
- editable: true
- },
- { name : ccs_strings.TRANSLATION,
- width : "10em",
- height : "2em",
- formatter: function (row) {
- return '<span class="status_grid_trans_cell_'+row+'"></span>';
- },
- get : function (row) {
- if (!window.status_rows) window.status_rows = [];
- var r = grid_container.getItem(row);
- if (r) {
- window.status_rows[row] = new ccs().fromHash(grid_container.getItem(row));
- setTimeout(
- 'dojo.query(".status_grid_trans_cell_' + row + '").'+
- 'instantiate(openils.widget.TranslatorPopup,{field:"name",'+
- 'targetObject:"window.status_rows['+row+']"});'+
- 'status_grid.rowHeightChanged('+row+')',
- 0
- );
- return row;
- }
- return '';
- }
- },
- { name : ccs_strings.HOLDABLE,
- field : "holdable",
- editable: true,
- //editor : dojox.grid.editors.bool,
- get : function (row) {
- var r = grid_container.getItem(row);
- if (r) {
- var h = r.holdable;
- if (h == 't' || h === true) return true;
- return false;
- }
- }
- },
- { name : ccs_strings.OPAC_VISIBLE,
- field : "opac_visible",
- editable: true,
- //editor : dojox.grid.editors.bool,
- get : function (row) {
- var r = grid_container.getItem(row);
- if (r) {
- var h = r.opac_visible;
- if (h == 't' || h === true) return true;
- return false;
- }
- }
- },
- { name : ccs_strings.COPY_ACTIVE,
- field : "copy_active",
- //editor : dojox.grid.editors.bool,
- editable: true,
- get : function (row) {
- var r = grid_container.getItem(row);
- if (r) {
- var h = r.copy_active;
- if (h == 't' || h === true) return true;
- return false;
- }
- }
- }
- ]
- ]
+/**
+ * Creates a function that looks at the row properties for a given row
+ * and turns the 't' or 'f' returned from the CRUD interface for true or
+ * false in to a literal true or false, so widgets for the field can be
+ * auto-created by dojo.
+ *
+ * @param propName - The name of the property to fetch for the given row
+ * @return A function that outputs true or false for the given property.
+ **/
+function getBoolRow(propName){
+ return function boolRow(rowNum, rowVal) {
+ if(rowVal === null)
+ return false;
+
+ var h = rowVal[propName];
+ return (h == 't' || h === true);
+ };
}
-];
+function getTranslationFormat(r, row, grid)
+{
+ if (!window.status_rows) window.status_rows = [];
+ if (r) {
+ window.status_rows[row] = new ccs().fromHash(r);
+
+ var tp = new openils.widget.TranslatorPopup({field:"name", targetObject:"window.status_rows["+row+"]"});
+ tp._destroyOnRemove=true;
+ return tp;
+ }
+}
+
+var status_grid_layout = [[
+ {name: ccs_strings.ID, field:'id'},
+ {name: ccs_strings.NAME, field: 'name', width: 'auto', editable: true},
+ {name: ccs_strings.TRANSLATION, width: "10em", height: "2em", field:"_item", formatter: getTranslationFormat, editable: true},
+ {name: ccs_strings.HOLDABLE, field: "holdable", editable: true, cellType:dojox.grid.cells.Bool, get:getBoolRow('holdable')},
+ {name: ccs_strings.OPAC_VISIBLE, field : "opac_visible", editable: true, cellType:dojox.grid.cells.Bool, get:getBoolRow('opac_visible')},
+]];
dojo.addOnLoad(function()
{
- highlighter.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'grid_container', duration : 500 } );
- highlighter.red = dojox.fx.highlight( { color : '#FF2018', node : 'grid_container', duration : 500 } );
+ highlighter.green = dojox.fx.highlight( { color : '#B4FFB4', node : 'pagebody', duration : 500 } );
+ highlighter.red = dojox.fx.highlight( { color : '#FF2018', node : 'pagebody', duration : 500 } );
});
+
for (var i in lineitems) {
JUBGrid.lineitems[lineitems[i].id()] = lineitems[i];
}
-//FIXME JUBGrid.jubGrid = gridWidget;
- JUBGrid.jubGrid.setModel(model);
+ JUBGrid.jubGrid = gridWidget;
+ //JUBGrid.jubGrid.setModel(model);
if(JUBGrid.showDetails) {
dojo.connect(gridWidget, "onRowClick",
function(evt) {
- var jub = model.getRow(evt.rowIndex);
+ var jub = JubGrid.jubGrid.getItem(evt.rowIndex);
var grid;
JUBGrid.jubDetailGrid.lineitemID = jub.id;
);
}
// capture changes to lineitems
- dojo.connect(model.store, "onSet", JUBGrid.onJUBSet);
+ dojo.connect(JUBGrid.jubGrid.store, "onSet", JUBGrid.onJUBSet);
gridWidget.update();
},
JUBGrid.lineitems = keepMe;
deleteList(deleteMe, 0, function(){
- JUBGrid.jubGrid.model.store =
- new dojo.data.ItemFileReadStore({data:jub.toStoreData(keepMe)});
- JUBGrid.jubGrid.model.refresh();
- JUBGrid.jubGrid.update();
+ JUBGrid.jubGrid.store = new dojo.data.ItemFileReadStore({data:jub.toStoreData(keepMe)});
});
},
alert("Error: "+evt.desc);
} else {
var deleteItem = function(item, rq) {
- JUBGrid.jubDetailGrid.model.store.deleteItem(item);
+ JUBGrid.jubDetailGrid.store.deleteItem(item);
};
var updateCount = function(item) {
- var newval = JUBGrid.jubGrid.model.store.getValue(item, "item_count");
- JUBGrid.jubGrid.model.store.setValue(item, "item_count", newval-1);
- JUBGrid.jubGrid.update();
+ var newval = JUBGrid.jubGrid.store.getValue(item, "item_count");
+ JUBGrid.jubGrid.store.setValue(item, "item_count", newval-1);
};
- JUBGrid.jubDetailGrid.model.store.fetch({query:{id:lid.id},
+ JUBGrid.jubDetailGrid.store.fetch({query:{id:lid.id},
onItem: deleteItem});
- JUBGrid.jubGrid.model.store.fetch({query:{id:JUBGrid.jubDetailGrid.lineitemID},
+ JUBGrid.jubGrid.store.fetch({query:{id:JUBGrid.jubDetailGrid.lineitemID},
onItem: updateCount});
}
- JUBGrid.jubDetailGrid.update();
};
openils.acq.Lineitem.deleteLID(lid.id, deleteFromStore);
},
createLID: function(fields) {
+ console.log(fields);
fields['lineitem'] = JUBGrid.jubDetailGrid.lineitemID;
+ console.log(fields);
+ JUBGrid.jubDetailGrid.store.newItem(acqlid.toStoreData([lid]).items[0]);
var addToStore = function (lid) {
- JUBGrid.jubDetailGrid.model.store.newItem(acqlid.toStoreData([lid]).items[0]);
- JUBGrid.jubDetailGrid.refresh();
- JUBGrid.jubGrid.update();
- JUBGrid.jubGrid.refresh();
+ JUBGrid.jubDetailGrid.store.newItem(acqlid.toStoreData([lid]).items[0]);
+ //JUBGrid.jubDetailGrid.refresh();
+ //JUBGrid.jubGrid.update();
+ //JUBGrid.jubGrid.refresh();
}
+ console.log("added to store");
+ console.log(addToStore());
openils.acq.Lineitem.createLID(fields, addToStore);
},
// called when a lineitem is edited
onJUBSet: function (griditem, attr, oldVal,newVal) {
+ console.log("onJUBSet called");
var item;
var updateDone = function(r) {
},
};
+