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. */
76 if (cpmList.length > 0) {
77 pcrud.update( cpmList, {});
81 * Close the connection and commit the transaction. This is necessary to do before
82 * the subsequent delete operation (because of ON DELETE CASCADE issues).
88 * Update the AutoGrid to delete the items being mapped out of existence so that
89 * the display reflects the updated situation.
90 * Then use a PermaCrud connection to delete/eliminate the object. This
91 * code is adapted from the delete case in AutoGrid.js. Note that this code
92 * uses a total==1 as the exit condition (because you are not deleting the
93 * winning/prevailing/surviving part.
98 if (item.id != parseInt(obj.itemID)) {
99 var fmObject = new fieldmapper[gridControl.fmClass]().fromStoreItem(item);
100 new openils.PermaCrud()['eliminate'](
102 oncomplete : function(r) {
103 gridControl.store.deleteItem(item);
104 if (--total == 1 && gridControl.onPostSubmit) {
105 gridControl.onPostSubmit();
116 mergeDiv.innerHTML = "<div class=\"biblio-merge-prevail-title\" >" +
117 dojo.i18n.getLocalization("openils.biblio","biblio_messages").CLICK_PREVAILING +
119 mergeDiv.items = items;
122 * Create a DIV for each selected item, and put in the container DIV
124 for (var i = 0; i < total; i++) {
125 var newDiv = dojo.create("div");
126 newDiv.className = "biblio-merge-item";
127 newDiv.itemID = items[i].id;
128 newDiv.onclick = function() {mergeDiv.processMerge(this);};
129 var newText = new String(items[i].label);
131 /* To make spacing more visible, replace spaces with a middot character */
132 newText = newText.replace(/ /g, String.fromCharCode(183) /* middot*/);
133 newDiv.appendChild(document.createTextNode( newText ));
134 mergeDiv.appendChild(newDiv);
136 mergePartsPopup.setContent(mergeDiv);
138 mergePartsPopup.show();