1 /* ---------------------------------------------------------------------------
2 * Copyright (C) 2014 C/W MARS Inc.
3 * Dan Pearl <dpearl@cwmars.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * ---------------------------------------------------------------------------
18 * Support for the facility to merge multiple part designations into
22 if(!dojo._hasResource["openils.biblio.monographPartMerge"]) {
23 dojo._hasResource["openils.biblio.monographPartMerge"] = true;
24 dojo.provide("openils.biblio.monographPartMerge");
25 dojo.declare("openils.biblio.monographPartMerge", null, {});
28 * Generate a pop-up to control part merging
30 openils.biblio.monographPartMerge.showMergeDialog = function(gridControl) {
31 dojo.requireLocalization("openils.biblio","biblio_messages");
33 var items = gridControl.getSelectedItems();
34 var total = items.length;
36 if (total < 2 ) // Validate number of selected items
38 alert(dojo.i18n.getLocalization("openils.biblio","biblio_messages").SELECT_TWO);
42 var mergePartsPopup = new dijit.Dialog({title:
43 dojo.i18n.getLocalization("openils.biblio","biblio_messages").MERGE_PARTS_TITLE});
45 var mergeDiv = dojo.create("div");
48 * Establish handler when an item is clicked upon
50 mergeDiv.processMerge = function (obj) {
51 mergePartsPopup.hide();
52 dojo.require('openils.PermaCrud');
54 var searchParams = {};
55 searchParams["part"] = new Array() ;
58 * Establish a list of id's of monograph_parts that are affected by remap. Later, find
59 * all copy_part_map items that reference any of these parts
62 dojo.forEach (this.items,
64 searchParams["part"].push(String(item.id)) /* Must be String in json */
66 // var testString = searchParams["part"].join(', '); /* DEBUG */
68 var pcrud = new openils.PermaCrud();
69 var cpmList = pcrud.search("acpm", searchParams);
73 g.part(parseInt(obj.itemID)) /* Assign "winner" DB id of mono_part. */
77 if (cpmList.length > 0) {
78 pcrud.apply( cpmList);
82 * Close the connection and commit the transaction. This is necessary to do before
83 * the subsequent delete operation (because of ON DELETE CASCADE issues).
89 * Update the AutoGrid to delete the items being mapped out of existence so that
90 * the display reflects the updated situation.
91 * Then use a PermaCrud connection to delete/eliminate the object. This
92 * code is adapted from the delete case in AutoGrid.js. Note that this code
93 * uses a total==1 as the exit condition (because you are not deleting the
94 * winning/prevailing/surviving part.
99 if (item.id != parseInt(obj.itemID)) {
100 var fmObject = new fieldmapper[gridControl.fmClass]().fromStoreItem(item);
101 new openils.PermaCrud()['eliminate'](
103 oncomplete : function(r) {
104 gridControl.store.deleteItem(item);
105 if (--total == 1 && gridControl.onPostSubmit) {
106 gridControl.onPostSubmit();
117 mergeDiv.innerHTML = "<div class=\"biblio-merge-prevail-title\" >" +
118 dojo.i18n.getLocalization("openils.biblio","biblio_messages").CLICK_PREVAILING +
120 mergeDiv.items = items;
123 * Create a DIV for each selected item, and put in the container DIV
125 for (var i = 0; i < total; i++) {
126 var newDiv = dojo.create("div");
127 newDiv.className = "biblio-merge-item";
128 newDiv.itemID = items[i].id;
129 newDiv.onclick = function() {mergeDiv.processMerge(this);};
130 var newText = new String(items[i].label);
132 /* To make spacing more visible, replace spaces with a middot character */
133 newText = newText.replace(/ /g, String.fromCharCode(183) /* middot*/);
134 newDiv.appendChild(document.createTextNode( newText ));
135 mergeDiv.appendChild(newDiv);
137 mergePartsPopup.setContent(mergeDiv);
139 mergePartsPopup.show();