this.selectedIndex = 0;
};
+ acqLitCreatePoCancel.onClick = function() {
+ acqLitPoCreateDialog.hide();
+ }
acqLitCreatePoSubmit.onClick = function() {
if (!self.createPoProviderSelector.attr("value") ||
!self.createPoAgencySelector.attr("value")) {
po.provider(this.createPoProviderSelector.attr("value"));
po.ordering_agency(this.createPoAgencySelector.attr("value"));
po.prepayment_required(fields.prepayment_required[0] ? true : false);
+ var name = this.createPoNameInput.attr('value');
+ if (name) po.name(name); // avoid name=""
// if we're creating assets, delay the asset creation
// until after the PO is created. This will allow us to
widget.build(function(w) { self.createPoProviderSelector = w; });
}
+ this.createPoCheckDupes = function() {
+ var org = self.createPoAgencySelector.attr('value');
+ var name = self.createPoNameInput.attr('value');
+ openils.Util.hide('acq-dupe-po-name');
+
+ if (!name) {
+ acqLitCreatePoSubmit.attr('disabled', false);
+ return;
+ }
+
+ acqLitCreatePoSubmit.attr('disabled', true);
+ var orgs = fieldmapper.aou.descendantNodeList(org, true);
+ new openils.PermaCrud().search('acqpo',
+ {name : name, ordering_agency : orgs},
+ {async : true, oncomplete : function(r) {
+ var po = openils.Util.readResponse(r);
+
+ if (po && (po = po[0])) {
+
+ var link = dojo.byId('acq-dupe-po-link');
+ openils.Util.show('acq-dupe-po-name', 'table-row');
+ var dupe_path = '/acq/po/view/' + po.id();
+
+ if (window.xulG) {
+
+ if (window.IAMBROWSER) {
+ // TODO: integration
+
+ } else {
+ // XUL client
+ link.onclick = function() {
+
+ var loc = xulG.url_prefix('XUL_BROWSER?url=') +
+ window.encodeURIComponent(
+ xulG.url_prefix('EG_WEB_BASE' + dupe_path)
+ );
+
+ xulG.new_tab(loc,
+ {tab_name: '', browser:false},
+ {
+ no_xulG : false,
+ show_nav_buttons : true,
+ show_print_button : true,
+ }
+ );
+ }
+ }
+
+ } else {
+ link.onclick = function() {
+ window.open(oilsBasePath + dupe_path, '_blank').focus();
+ }
+ }
+
+ } else {
+ acqLitCreatePoSubmit.attr('disabled', false);
+ }
+ }}
+ );
+ }
+
if (!this.createPoAgencySelector) {
var widget = new openils.widget.AutoFieldWidget({
"fmField": "ordering_agency",
"parentNode": dojo.byId("acq-lit-po-agency"),
"orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
});
- widget.build(function(w) { self.createPoAgencySelector = w; });
+ widget.build(function(w) {
+ self.createPoAgencySelector = w;
+ dojo.connect(w, 'onChange', self.createPoCheckDupes);
+ });
+ }
+
+ if (!this.createPoNameInput) {
+ var widget = new openils.widget.AutoFieldWidget({
+ "fmField": "name",
+ "fmClass": "acqpo",
+ "parentNode": dojo.byId("acq-lit-po-name"),
+ "orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
+ });
+ widget.build(function(w) {
+ self.createPoNameInput = w;
+ dojo.connect(w, 'onChange', self.createPoCheckDupes);
+ });
}
};
dojo.require("openils.widget.EditDialog");
dojo.require("openils.widget.EditPane");
+dojo.require("openils.PermaCrud");
+dojo.require("openils.User");
+dojo.require("fieldmapper.OrgUtils");
-var editDialog;
+dojo.requireLocalization('openils.acq', 'acq');
+var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
+
+var editDialog, selectedAgency, currentName;
function toPoListing() {
location.href = oilsBasePath + "/acq/search/unified?ca=po";
openils.Util.addOnLoad(
function() {
+
+ // apply here in case the selector never changes
+ // (i.e. no onchange fires).
+ selectedAgency = openils.User.user.ws_ou();
+
+ // called each time the PO name changes
+ function name_changed(new_name) {
+ currentName = new_name;
+
+ console.debug('checking for PO name collision + "'
+ + currentName + '" at ' + selectedAgency);
+
+ if (!new_name) { // name cleared
+ editDialog.editPane.saveButton.attr('disabled', false);
+ return;
+ }
+
+ // disable Save option pending confirmation of uniqueness
+ editDialog.editPane.saveButton.attr('disabled', true);
+
+ var orgs = fieldmapper.aou.descendantNodeList(selectedAgency, true);
+ new openils.PermaCrud().search('acqpo',
+ {name : new_name, ordering_agency : orgs},
+ {async : true, oncomplete : function(r) {
+ var po = openils.Util.readResponse(r);
+ var tbody = editDialog.editPane.table.getElementsByTagName('tbody')[0];
+
+ // remove any previous dupe warning row
+ dojo.forEach(tbody.getElementsByTagName('tr'), function(row) {
+ if (row) { // sometimes row is undefined??
+ if (row.getAttribute('dupe-po-row'))
+ tbody.removeChild(row);
+ }
+ });
+
+ if (po && (po = po[0])) {
+ // duplicate found. add info row to create dialog
+
+ var parent_row;
+ dojo.forEach(tbody.getElementsByTagName('tr'), function(row) {
+ if (row.getAttribute('fmfield') == 'name')
+ parent_row = row;
+ });
+
+ var new_tr = dojo.create('tr', {'dupe-po-row' : 1});
+ var link = dojo.create('a', {
+ href : 'javascript:;',
+ innerHTML : localeStrings.DUPE_PO_NAME_LINK
+ });
+
+ var dupe_path = '/acq/po/view/' + po.id();
+
+ if (window.xulG) {
+
+ if (window.IAMBROWSER) {
+ // TODO: integration
+
+ } else {
+ // XUL client
+ link.onclick = function() {
+
+ var loc = xulG.url_prefix('XUL_BROWSER?url=') +
+ window.encodeURIComponent(
+ xulG.url_prefix('EG_WEB_BASE' + dupe_path)
+ );
+
+ xulG.new_tab(loc,
+ {tab_name: '', browser:false},
+ {
+ no_xulG : false,
+ show_nav_buttons : true,
+ show_print_button : true,
+ }
+ );
+ }
+ }
+
+ } else {
+ link.onclick = function() {
+ window.open(oilsBasePath + dupe_path, '_blank').focus();
+ }
+ }
+
+ new_tr.appendChild(dojo.create('td',
+ {innerHTML : localeStrings.DUPE_PO_NAME_MSG}));
+ var link_td = dojo.create('td');
+ link_td.appendChild(link);
+ new_tr.appendChild(link_td);
+ tbody.insertBefore(new_tr, parent_row.nextSibling);
+
+ } else {
+ editDialog.editPane.saveButton.attr('disabled', false);
+ }
+ }}
+ );
+ }
+
+ function agency_changed(val) {
+ selectedAgency = val;
+ if (currentName) {
+ // if the ordering agency changes, re-run the dupe name check.
+ name_changed(currentName);
+ }
+ }
+
editDialog = new openils.widget.EditDialog({
"editPane": new openils.widget.EditPane({
"fmObject": new acqpo(),
* much advantage over a hardcoded interface. */
"suppressFields": [
"create_time", "edit_time", "editor", "order_date",
- "owner", "cancel_reason", "creator", "state", "name"
+ "owner", "cancel_reason", "creator", "state"
],
- "fieldOrder": ["ordering_agency", "provider"],
+ "fieldOrder": ["ordering_agency", "name", "provider"],
"mode": "create",
overrideWidgetArgs : {
provider : { dijitArgs : { store_options : { base_filter : { active :"t" } } } },
- ordering_agency : { orgDefaultsToWs : true }
+ ordering_agency : {
+ orgDefaultsToWs : true,
+ dijitArgs : {onChange : agency_changed}
+ },
+ name : {dijitArgs : {onChange : name_changed}}
},
"onSubmit": function(po) {
fieldmapper.standardRequest(
});
editDialog.startup();
editDialog.show();
+
+ // modify the label of the 'name' field to make it more clear it's optional
+ var row = dojo.query('[fmfield=name]', editDialog.editPane.table)[0];
+ var name_td = row.getElementsByTagName('td')[0];
+ name_td.innerHTML = dojo.string.substitute(
+ localeStrings.PO_NAME_OPTIONAL,
+ [name_td.innerHTML]
+ );
}
);