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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record-strings.inc (-3 / +2 lines)
Lines 1-6 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_PRE   = _("This subfield cannot be added: there is no");
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
    var MSG_MERGEREC_SUBFIELD_POST  = _("field in the destination record.");
5
</script>
6
</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 (-109 / +142 lines)
Lines 2-121 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 (where == 0 && $(this).text() == field) {
83
                            where = this;
84
                        }
85
                    });
86
87
                    // If there is no matching field in the destination record
88
                    if (where == 0) {
89
90
                        // TODO:
91
                        // We select the whole field and removing non-selected subfields, instead of...
92
93
                        // Alerting the user
94
                        alert(MSG_MERGEREC_SUBFIELD_PRE + " " + field + " " + MSG_MERGEREC_SUBFIELD_POST);
95
                        pField.checked = false;
96
                    } else {
97
                        $(where).nextAll("ul").append(clone);
98
                    }
99
100
                }
101
102
            } else {
103
                // If we are a field
104
                var where = 0;
105
                // Find where to add the field
106
                $("#resultul li span.field").each(function() {
107
                    if (where == 0 && $(this).text() > field) {
108
                        where = this;
109
                    }
110
                });
111
112
                $(where).parent().before(clone);
113
            }
114
        }
138
        }
115
    } else {
139
      } else {
116
        // Else, we remove it from the results tab
140
        $('#' + field.id).find('input.fieldpick').attr('checked', false);
117
        $("ul#resultul li#k" + key).remove();
141
      }
118
    }
142
    }
143
  }
119
}
144
}
120
145
121
/*
146
/*
Lines 124-139 function toggleField(pField) { Link Here
124
$(document).ready(function(){
149
$(document).ready(function(){
125
    // When a field is checked / unchecked
150
    // When a field is checked / unchecked
126
    $('input.fieldpick').click(function() {
151
    $('input.fieldpick').click(function() {
127
        toggleField(this);
128
        // (un)check all subfields
152
        // (un)check all subfields
129
        var ischecked = this.checked;
153
        var ischecked = this.checked;
154
        if (ischecked && !field_can_be_added($('#tabs'), $(this).parent())) {
155
          return false;
156
        }
157
130
        $(this).parent().find("input.subfieldpick").each(function() {
158
        $(this).parent().find("input.subfieldpick").each(function() {
131
            this.checked = ischecked;
159
            this.checked = ischecked;
132
        });
160
        });
161
        rebuild_target($('#tabs'), $('#resultul'));
133
    });
162
    });
134
163
135
    // When a field or subfield is checked / unchecked
164
    // When a field or subfield is checked / unchecked
136
    $("input.subfieldpick").click(function() {
165
    $("input.subfieldpick").click(function() {
137
        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'));
138
    });
171
    });
139
});
172
});
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-4 / +3 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-94 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;
91
      rebuild_target($("#tabs"), $("#resultul"));
92
    });
92
    });
93
93
94
    // Creating tabs
94
    // Creating tabs
95
- 

Return to bug 8064