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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record-strings.inc (+6 lines)
Line 0 Link Here
1
[%# transletable strings for merge-record.js %]
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.");
4
    var MSG_MERGEREC_SUBFIELD_PRE   = _("This subfield cannot be added: there is no");
5
    var MSG_MERGEREC_SUBFIELD_POST  = _("field in the destination record.");
6
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/merge-record.inc (-136 lines)
Lines 45-186 Link Here
45
    [% END %]
45
    [% END %]
46
    </div><!-- /div#tabrecord[% recordnumber %] -->
46
    </div><!-- /div#tabrecord[% recordnumber %] -->
47
[% END %]
47
[% END %]
48
[% BLOCK mergejs %]
49
    // Creating tabs
50
    $("#tabs").tabs();
51
52
    // Toggle a field / subfield
53
    function toggleField(pField) {
54
55
    // Getting the key of the clicked checkbox
56
    var ckid   = $(pField).attr("id");
57
    var tab    = ckid.split('_');
58
    var source = tab[1]; // From which record the click came from
59
    var key    = tab[2];
60
    var type   = $(pField).attr("class");
61
62
    // Getting field/subfield
63
    var field;
64
    var subfield;
65
    if (type == "subfieldpick") {
66
67
            field = $(pField).parent().parent().parent().find("span.field").text();
68
            subfield = $(pField).parent().find("span.subfield").text();
69
    } else {
70
71
            field = $(pField).parent().find("span.field").text();
72
    }
73
74
    // If the field has just been checked
75
    if (pField.checked) {
76
77
        // We check for repeatability
78
        var canbeadded = true;
79
        if (type == "subfieldpick") {
80
        var repeatable = 1;
81
        var alreadyexists = 0;
82
        if (tagslib[field] && tagslib[field][subfield]) {
83
            repeatable = tagslib[field][subfield].repeatable; // Note : we can't use the dot notation here (tagslib.021) because the key is a number
84
            // TODO : Checking for subfields
85
        }
86
        } else {
87
        if (tagslib[field]) {
88
            repeatable = tagslib[field].repeatable;
89
            alreadyexists = $("#resultul span.field:contains(" + field + ")");
90
            if (repeatable == 0 && alreadyexists.length != 0) {
91
            canbeadded = false;
92
            }
93
        }
94
        }
95
        // If the field is not repeatable, we check if it already exists in the result table
96
        if (canbeadded == false) {
97
        alert(_("The field is non-repeatable and already exists in the destination record. Therefore, you cannot add it."));
98
        pField.checked = 0;
99
        } else {
100
101
        // Cloning the field or subfield we picked
102
        var clone = $(pField).parent().clone();
103
104
        // Removing the checkboxes from it
105
        $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
106
            $(this).remove();
107
        });
108
109
110
        // If we are a subfield
111
        if (type == "subfieldpick") {
112
            // then we need to find who is our parent field...
113
            fieldkey = $(pField).parent().parent().parent().attr("id");
114
115
            // Find where to add the subfield
116
117
            // First, check if the field is not already in the destination record
118
            if ($("#resultul li#" + fieldkey).length > 0) {
119
            // If so, we add our field to it
120
            $("#resultul li#" + fieldkey + " ul").append(clone);
121
            } else {
122
            // If not, we add the subfield to the first matching field
123
            var where = 0;
124
            $("#resultul li span.field").each(function() {
125
                if (where == 0 && $(this).text() == field) {
126
                where = this;
127
                }
128
            });
129
130
            // If there is no matching field in the destination record
131
            if (where == 0) {
132
133
                // TODO:
134
                // We select the whole field and removing non-selected subfields, instead of...
135
136
                // Alerting the user
137
                alert(_("This subfield cannot be added: there is no") + " " + field + " " + _("field in the destination record."));
138
                pField.checked = false;
139
140
            } else {
141
                $(where).nextAll("ul").append(clone);
142
            }
143
144
            }
145
146
147
148
        } else {
149
            // If we are a field
150
            var where = 0;
151
            // Find where to add the field
152
            $("#resultul li span.field").each(function() {
153
            if (where == 0 && $(this).text() > field) {
154
                where = this;
155
            }
156
            });
157
158
            $(where).parent().before(clone);
159
        }
160
        }
161
    } else {
162
163
        // Else, we remove it from the results tab
164
        $("ul#resultul li#k" + key).remove();
165
    }
166
}
167
168
169
    // When a field is checked / unchecked
170
    $('input.fieldpick').click(function() {
171
    toggleField(this);
172
    // (un)check all subfields
173
    var ischecked = this.checked;
174
    $(this).parent().find("input.subfieldpick").each(function() {
175
        this.checked = ischecked;
176
    });
177
    });
178
179
    // When a field or subfield is checked / unchecked
180
    $("input.subfieldpick").click(function() {
181
    toggleField(this);
182
    });
183
[% END %]
184
[% BLOCK mergesource %]
48
[% BLOCK mergesource %]
185
<div id="tabs" class="toptabs">
49
<div id="tabs" class="toptabs">
186
<h2>Source records</h2>
50
<h2>Source records</h2>
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/merge-record.js (+139 lines)
Line 0 Link Here
1
/*
2
 * Merging 2 source records into a destination record
3
 */
4
5
/**
6
 * Check or uncheck a field or subfield in a source record
7
 * @param pField the checkbox clicked
8
 */
9
function toggleField(pField) {
10
11
    // Getting the key of the clicked checkbox
12
    var ckid   = $(pField).attr("id");
13
    var tab    = ckid.split('_');
14
    var source = tab[1]; // From which record the click came from
15
    var key    = tab[2];
16
    var type   = $(pField).attr("class");
17
18
    // Getting field/subfield
19
    var field;
20
    var subfield;
21
    if (type == "subfieldpick") {
22
        field = $(pField).parent().parent().parent().find("span.field").text();
23
        subfield = $(pField).parent().find("span.subfield").text();
24
    } else {
25
        field = $(pField).parent().find("span.field").text();
26
    }
27
28
    // If the field has just been checked
29
    if (pField.checked) {
30
31
        // We check for repeatability
32
        var canbeadded = true;
33
        if (type == "subfieldpick") {
34
            var repeatable = 1;
35
            var alreadyexists = 0;
36
            if (tagslib[field] && tagslib[field][subfield]) {
37
                // Note : we can't use the dot notation here (tagslib.021) because the key is a number
38
                repeatable = tagslib[field][subfield].repeatable;
39
                // TODO : Checking for subfields
40
            }
41
        } else {
42
            if (tagslib[field]) {
43
                repeatable = tagslib[field].repeatable;
44
                alreadyexists = $("#resultul span.field:contains(" + field + ")");
45
                if (repeatable == 0 && alreadyexists.length != 0) {
46
                    canbeadded = false;
47
                }
48
            }
49
        }
50
51
        // If the field is not repeatable, we check if it already exists in the result table
52
        if (canbeadded == false) {
53
            alert(MSG_MERGEREC_ALREADY_EXISTS);
54
            pField.checked = 0;
55
        } else {
56
57
            // Cloning the field or subfield we picked
58
            var clone = $(pField).parent().clone();
59
60
            // Removing the checkboxes from it
61
            $(clone).find("input.subfieldpick, input.fieldpick").each(function() {
62
                $(this).remove();
63
            });
64
65
            // If we are a subfield
66
            if (type == "subfieldpick") {
67
                // then we need to find who is our parent field...
68
                fieldkey = $(pField).parent().parent().parent().attr("id");
69
70
                // Find where to add the subfield
71
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
        }
115
    } else {
116
        // Else, we remove it from the results tab
117
        $("ul#resultul li#k" + key).remove();
118
    }
119
}
120
121
/*
122
 * Add actions on field and subfields checkboxes
123
 */
124
$(document).ready(function(){
125
    // When a field is checked / unchecked
126
    $('input.fieldpick').click(function() {
127
        toggleField(this);
128
        // (un)check all subfields
129
        var ischecked = this.checked;
130
        $(this).parent().find("input.subfieldpick").each(function() {
131
            this.checked = ischecked;
132
        });
133
    });
134
135
    // When a field or subfield is checked / unchecked
136
    $("input.subfieldpick").click(function() {
137
        toggleField(this);
138
    });
139
});
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/merge.tt (-2 / +6 lines)
Lines 1-8 Link Here
1
[% PROCESS 'merge-record.inc' %]
1
[% PROCESS 'merge-record.inc' %]
2
2
[% INCLUDE 'doc-head-open.inc' %]
3
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
4
<title>Koha &rsaquo; Cataloging &rsaquo; Merging records</title>
4
[% INCLUDE 'greybox.inc' %]
5
[% INCLUDE 'greybox.inc' %]
5
[% INCLUDE 'doc-head-close.inc' %]
6
[% INCLUDE 'doc-head-close.inc' %]
7
<script type="text/javascript" src="[% themelang %]/js/merge-record.js"></script>
8
[% INCLUDE 'merge-record-strings.inc' %]
6
<style type="text/css">
9
<style type="text/css">
7
div.record ul, div.record li { float:none; display:block; }
10
div.record ul, div.record li { float:none; display:block; }
8
div#result { margin-top: 1em; }
11
div#result { margin-top: 1em; }
Lines 23-29 $(document).ready(function(){ Link Here
23
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
26
    $.getJSON("/cgi-bin/koha/cataloguing/merge_ajax.pl", {frameworkcode : "[% framework %]" }, function(json) {
24
        tagslib = json;
27
        tagslib = json;
25
    });
28
    });
26
    [% PROCESS mergejs %]
29
30
    // Creating tabs
31
    $("#tabs").tabs();
27
});
32
});
28
33
29
34
30
- 

Return to bug 10650