View | Details | Raw Unified | Return to bug 8064
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record-strings.inc (-2 / +2 lines)
Lines 1-5 Link Here
1
[%# transletable strings for merge-record.js %]
1
[%# transletable strings for merge-record.js %]
2
<script type="text/javascript">
2
<script type="text/javascript">
3
    var MSG_MERGEREC_ALREADY_EXISTS = _("The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it.");
3
    var MSG_MERGEREC_ALREADY_EXISTS = _("The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it.");
4
    var MSG_MERGEREC_SUBFIELD   = _("This subfield cannot be added: there is no %s field in the destination record.");
4
    var MSG_MERGEREC_SUBFIELD_ALREADY_EXISTS = _("The subfield is non-repeatable and already exists in the destination record. Therefore, you cannot add it.");
5
</script>
5
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc (-29 / +2 lines)
Lines 69-102 Link Here
69
<div id="result">
69
<div id="result">
70
    <h2>Destination record</h2>
70
    <h2>Destination record</h2>
71
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
71
    <div style="border:1px solid #E8E8E8;padding:1em;margin-top:2em;">
72
        <ul id="resultul">
72
        <ul id="resultul"></ul>
73
          [% FOREACH field IN ref_record.display %]
73
    </div>
74
            [% IF field.tag != biblionumbertag %]
75
              <li id="k[% field.key %]">
76
                <span class="field">[% field.tag %]</span>
77
                <input type="hidden" name="tag_[% field.tag %]_indicator1_[% field.key %]" value="[% field.indicator1 %]" />
78
                <input type="hidden" name="tag_[% field.tag %]_indicator2_[% field.key %]" value="[% field.indicator2 %]" />
79
                [% IF ( field.value ) %]
80
                  / [% field.value %]
81
                  <input type="hidden" name="tag_[% field.tag %]_code_00_[% field.key %]" value="00" />
82
                  <input type="hidden" name="tag_[% field.tag %]_subfield_00_[% field.key %]" value="[% field.value |html%]" />
83
                [% END %]
84
85
                [% IF ( field.subfield ) %]
86
                  <ul>
87
                    [% FOREACH subfield IN field.subfield %]
88
                      <li id="k[% subfield.subkey %]">
89
                        <span class="subfield">[% subfield.subtag %]</span> / [% subfield.value %]
90
                        <input type="hidden" name="tag_[% field.tag %]_code_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.subtag %]" />
91
                        <input type="hidden" name="tag_[% field.tag %]_subfield_[% subfield.subtag %]_[% field.key %]_[% subfield.subkey %]" value="[% subfield.value |html%]" />
92
                      </li>
93
                    [% END %]
94
                  </ul>
95
                [% END %]
96
              </li>
97
            [% END %]
98
          [% END %]
99
        </ul>
100
</div>
101
</div> <!-- // #result -->
74
</div> <!-- // #result -->
102
[% END %]
75
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/merge-record.js (-115 / +142 lines)
Lines 2-127 Link Here
2
 * Merging 2 source records into a destination record
2
 * Merging 2 source records into a destination record
3
 */
3
 */
4
4
5
/**
5
function build_target_record($sources) {
6
 * Check or uncheck a field or subfield in a source record
6
  var target_record = {};
7
 * @param pField the checkbox clicked
7
8
 */
8
  $sources.find('.record input[type="checkbox"].fieldpick:checked').each(function() {
9
function toggleField(pField) {
9
    var $checkbox = $(this);
10
10
    var $li = $checkbox.parent();
11
    // Getting the key of the clicked checkbox
11
    var field = $checkbox.parent().find("span.field").text();
12
    var ckid   = $(pField).attr("id");
12
13
    var tab    = ckid.split('_');
13
    if (!(field in target_record)) {
14
    var source = tab[1]; // From which record the click came from
14
      target_record[field] = [];
15
    var key    = tab[2];
15
    }
16
    var type   = $(pField).attr("class");
16
    target_record[field].push({
17
17
      'id' : $li.attr('id'),
18
    // Getting field/subfield
18
      'tag' : field,
19
    var field;
19
      'subfields' : []
20
    var subfield;
20
    });
21
    if (type == "subfieldpick") {
21
  });
22
        field = $(pField).parent().parent().parent().find("span.field").text();
22
23
        subfield = $(pField).parent().find("span.subfield").text();
23
  $sources.find('.record input[type="checkbox"].subfieldpick:checked').each(function() {
24
    var $checkbox = $(this);
25
    var $li = $checkbox.parent();
26
    var $field_li = $li.parents('li');
27
    var field = $field_li.find('span.field').text();
28
    var subfield = $li.find('span.subfield').text();
29
30
    var target_field;
31
    if (field in target_record) {
32
      for (i in target_record[field]) {
33
        if (target_record[field][i].id == $field_li.attr('id')) {
34
          target_field = target_record[field][i];
35
        }
36
      }
37
      if (!target_field) {
38
        target_field = target_record[field][0];
39
      }
40
    }
41
    if (target_field) {
42
      target_field.subfields.push({
43
        'id' : $li.attr('id'),
44
        'code' : subfield
45
      });
24
    } else {
46
    } else {
25
        field = $(pField).parent().find("span.field").text();
47
      $field_li.find('input.fieldpick').attr('checked', true);
48
      target_record[field] = [{
49
        'id' : $field_li.attr('id'),
50
        'tag' : field,
51
        'subfields' : [{
52
          'id' : $li.attr('id'),
53
          'code' : subfield
54
        }]
55
      }];
26
    }
56
    }
57
  });
27
58
28
    // If the field has just been checked
59
  return target_record;
29
    if (pField.checked) {
60
}
30
61
31
        // We check for repeatability
62
function field_can_be_added($sources, $li) {
32
        var canbeadded = true;
63
  target_record = build_target_record($sources);
33
        if (type == "subfieldpick") {
64
34
            var repeatable = 1;
65
  var tag = $li.find('span.field').text();
35
            var alreadyexists = 0;
66
  var repeatable = true;
36
            if (tagslib[field] && tagslib[field][subfield]) {
67
  if (tag in tagslib) {
37
                // Note : we can't use the dot notation here (tagslib.021) because the key is a number
68
    repeatable = (tagslib[tag].repeatable != 0) ? true : false;
38
                repeatable = tagslib[field][subfield].repeatable;
69
  }
39
                // TODO : Checking for subfields
70
40
            }
71
  if ((!repeatable) && (tag in target_record)) {
41
        } else {
72
    alert(MSG_MERGEREC_ALREADY_EXISTS);
42
            if (tagslib[field]) {
73
    return false;
43
                repeatable = tagslib[field].repeatable;
74
  }
44
                alreadyexists = $("#resultul span.field:contains(" + field + ")");
75
45
                if (repeatable == 0 && alreadyexists.length != 0) {
76
  return true;
46
                    canbeadded = false;
77
}
47
                }
78
48
            }
79
function subfield_can_be_added($sources, $li) {
80
  target_record = build_target_record($sources);
81
82
  var $field_li = $li.parents('li');
83
  var tag = $field_li.find('span.field').text();
84
  var code = $li.find('span.subfield').text();
85
86
  var repeatable = true;
87
  if (tag in tagslib && code in tagslib[tag]) {
88
    repeatable = (tagslib[tag][code].repeatable != 0) ? true : false;
89
  }
90
91
  if (!repeatable) {
92
    var target_field;
93
    if (tag in target_record) {
94
      for (i in target_record[tag]) {
95
        if (target_record[tag][i].id == $field_li.attr('id')) {
96
          target_field = target_record[tag][i];
97
        }
98
      }
99
      if (!target_field) {
100
        target_field = target_record[tag][0];
101
      }
102
    }
103
    if (target_field) {
104
      for (i in target_field.subfields) {
105
        var subfield = target_field.subfields[i];
106
        if (code == subfield.code) {
107
          alert(MSG_MERGEREC_SUBFIELD_ALREADY_EXISTS);
108
          return false;
49
        }
109
        }
110
      }
111
    }
112
  }
113
114
  return true;
115
}
50
116
51
        // If the field is not repeatable, we check if it already exists in the result table
117
function rebuild_target($sources, $target) {
52
        if (canbeadded == false) {
118
  target_record = build_target_record($sources);
53
            alert(MSG_MERGEREC_ALREADY_EXISTS);
119
54
            pField.checked = 0;
120
  $target.empty();
55
        } else {
121
  var keys = $.map(target_record, function(elem, idx) { return idx }).sort();
56
122
  for (k in keys) {
57
            // Cloning the field or subfield we picked
123
    var tag = keys[k];
58
            var clone = $(pField).parent().clone();
124
    var fields = target_record[tag];
59
125
    for (i in fields) {
60
            // Removing the checkboxes from it
126
      var field = fields[i];
61
            $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
127
      if (field.subfields.length > 0) {
62
                $(this).remove();
128
        var $field_clone = $('#' + field.id).clone();
63
            });
129
        $field_clone.find('ul').empty();
64
130
        $field_clone.find('.fieldpick').remove();
65
            // If we are a subfield
131
        $target.append($field_clone);
66
            if (type == "subfieldpick") {
132
67
                // then we need to find who is our parent field...
133
        for (j in field.subfields) {
68
                fieldkey = $(pField).parent().parent().parent().attr("id");
134
          var subfield = field.subfields[j];
69
135
          var $subfield_clone = $('#' + subfield.id).clone();
70
                // Find where to add the subfield
136
          $subfield_clone.find('.subfieldpick').remove();
71
137
          $field_clone.find('ul').append($subfield_clone);
72
                // First, check if the field is not already in the destination record
73
                if ($("#resultul li#" + fieldkey).length > 0) {
74
75
                    // If so, we add our field to it
76
                    $("#resultul li#" + fieldkey + " ul").append(clone);
77
                } else {
78
79
                    // If not, we add the subfield to the first matching field
80
                    var where = 0;
81
                    $("#resultul li span.field").each(function() {
82
                        if ($(this).text() == field) {
83
                            where = this;
84
                            return false; // break each()
85
                        }
86
                    });
87
88
                    // If there is no matching field in the destination record
89
                    if (where == 0) {
90
91
                        // TODO:
92
                        // We select the whole field and removing non-selected subfields, instead of...
93
94
                        // Alerting the user
95
                        alert(MSG_MERGEREC_SUBFIELD.format(field));
96
                        pField.checked = false;
97
                    } else {
98
                        $(where).nextAll("ul").append(clone);
99
                    }
100
101
                }
102
103
            } else {
104
                // If we are a field
105
                var where = 0;
106
                // Find a greater field to add before
107
                $("#resultul li span.field").each(function() {
108
                    if ($(this).text() > field) {
109
                        where = this;
110
                        return false; // break each()
111
                    }
112
                });
113
                if (where) {
114
                    $(where).parent().before(clone);
115
                } else {
116
                    // No greater field, add to the end
117
                    $("#resultul").append(clone);
118
                }
119
            }
120
        }
138
        }
121
    } else {
139
      } else {
122
        // Else, we remove it from the results tab
140
        $('#' + field.id).find('input.fieldpick').attr('checked', false);
123
        $("ul#resultul li#k" + key).remove();
141
      }
124
    }
142
    }
143
  }
125
}
144
}
126
145
127
/*
146
/*
Lines 130-145 function toggleField(pField) { Link Here
130
$(document).ready(function(){
149
$(document).ready(function(){
131
    // When a field is checked / unchecked
150
    // When a field is checked / unchecked
132
    $('input.fieldpick').click(function() {
151
    $('input.fieldpick').click(function() {
133
        toggleField(this);
134
        // (un)check all subfields
152
        // (un)check all subfields
135
        var ischecked = this.checked;
153
        var ischecked = this.checked;
154
        if (ischecked && !field_can_be_added($('#tabs'), $(this).parent())) {
155
          return false;
156
        }
157
136
        $(this).parent().find("input.subfieldpick").each(function() {
158
        $(this).parent().find("input.subfieldpick").each(function() {
137
            this.checked = ischecked;
159
            this.checked = ischecked;
138
        });
160
        });
161
        rebuild_target($('#tabs'), $('#resultul'));
139
    });
162
    });
140
163
141
    // When a field or subfield is checked / unchecked
164
    // When a field or subfield is checked / unchecked
142
    $("input.subfieldpick").click(function() {
165
    $("input.subfieldpick").click(function() {
143
        toggleField(this);
166
      var ischecked = this.checked;
167
      if (ischecked && !subfield_can_be_added($('#tabs'), $(this).parent())) {
168
        return false;
169
      }
170
      rebuild_target($('#tabs'), $('#resultul'));
144
    });
171
    });
145
});
172
});
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-7 / +5 lines)
Lines 40-46 div#result { margin-top: 1em; } Link Here
40
                if (tagslib[tag][subfieldcode].mandatory == 1 && tagslib[tag][subfieldcode].tab >= 0) {
40
                if (tagslib[tag][subfieldcode].mandatory == 1 && tagslib[tag][subfieldcode].tab >= 0) {
41
                    var fields = $("#resultul span.field:contains("+ tag +")");
41
                    var fields = $("#resultul span.field:contains("+ tag +")");
42
                    $(fields).each(function() {
42
                    $(fields).each(function() {
43
                        var subfields = $(this).parent().find("span.subfield:contains("+ subfieldcode +")");
43
                        var subfields = $(this).parents('li').find("span.subfield:contains("+ subfieldcode +")");
44
                        if (subfields.length == 0) {
44
                        if (subfields.length == 0) {
45
                            missing.subfields.push( {
45
                            missing.subfields.push( {
46
                                'tag': tag,
46
                                'tag': tag,
Lines 85-97 div#result { margin-top: 1em; } Link Here
85
    }
85
    }
86
86
87
$(document).ready(function(){
87
$(document).ready(function(){
88
    // Getting marc structure via ajax
89
    tagslib = [];
88
    tagslib = [];
90
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
89
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
91
        tagslib = json;
90
      tagslib = json;
92
91
      rebuild_target($("#tabs"), $("#resultul"));
93
    //Set focus to cataloging search
94
    $("input[name=q]:eq(0)").focus();
95
    });
92
    });
96
93
97
    // Creating tabs
94
    // Creating tabs
Lines 102-107 $(document).ready(function(){ Link Here
102
    $('#tabs div#tabrecord[% ref_biblionumber %]').find('input[type="checkbox"]').attr('checked', true);
99
    $('#tabs div#tabrecord[% ref_biblionumber %]').find('input[type="checkbox"]').attr('checked', true);
103
    $('#tabs > div:not("#tabrecord[% ref_biblionumber %]")').find('input[type="checkbox"]').removeAttr('checked');
100
    $('#tabs > div:not("#tabrecord[% ref_biblionumber %]")').find('input[type="checkbox"]').removeAttr('checked');
104
101
102
    //Set focus to cataloging search
103
    $("input[name=q]:eq(0)").focus();
105
});
104
});
106
105
107
  [% END %]
106
  [% END %]
108
- 

Return to bug 8064