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

(-)a/koha-tmpl/intranet-tmpl/prog/en/js/marc_modification_templates.js (+288 lines)
Line 0 Link Here
1
$(document).ready(function() {
2
    $('#select_template').find("input:submit").hide();
3
    $('#select_template').change(function() {
4
        $('#select_template').submit();
5
    });
6
    $("span.match_regex_prefix" ).hide();
7
    $("span.match_regex_suffix" ).hide();
8
9
    $("#add_action").submit(function(){
10
        var action = $("#action").val();
11
        if ( action == 'move_field' || action == 'copy_field' || action == 'copy_and_replace_field') {
12
            if ( $("#from_subfield").val().length != $("#to_subfield").val().length ) {
13
                alert( MSG_MMT_SUBFIELDS_MATCH );
14
                return false;
15
            }
16
            if ( $("#to_field").val().length <= 0 ) {
17
                alert( MSG_MMT_DESTINATION_REQUIRED );
18
                return false;
19
            }
20
            if ( ( $("#to_field").val()   < 10 && $("#to_subfield").val().length   > 0 ) ||
21
                 ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) {
22
                 alert( MSG_MMT_CONTROL_FIELD_EMPTY );
23
                 return false;
24
            }
25
            if ( ( $("#from_field").val() < 10 && $("#to_subfield").val().length   === 0 ) ||
26
                 ( $("#to_field").val()   < 10 && $("#from_subfield").val().length === 0 ) ) {
27
                alert( MSG_MMT_CONTROL_FIELD );
28
                return false;
29
             }
30
        }
31
        if ( action == 'update_field' ) {
32
            if ( $("#from_subfield").val().length <= 0 ) {
33
                alert( MSG_MMT_SOURCE_SUBFIELD );
34
                return false;
35
            }
36
        }
37
        if ( $("#from_field").val().length <= 0 ) {
38
            alert( MSG_MMT_SOURCE_FIELD );
39
            return false;
40
        }
41
    });
42
43
    $("#conditional_field,#from_field").change(function(){
44
        updateAllEvery();
45
    });
46
});
47
48
function updateAllEvery(){
49
    if ( $("#conditional_field").is(":visible") ) {
50
        if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
51
            $("#field_number option[value='0']").html( MSG_MMT_EVERY );
52
        } else {
53
            $("#field_number option[value='0']").html( MSG_MMT_ALL );
54
        }
55
    }
56
}
57
58
function onActionChange(selectObj) {
59
    // get the index of the selected option
60
    var idx = selectObj.selectedIndex;
61
62
    // get the value of the selected option
63
    var action = selectObj.options[idx].value;
64
65
    switch( action ) {
66
        case 'delete_field':
67
            show('field_number_block');
68
            hide('with_value_block');
69
            hide('to_field_block');
70
            break;
71
72
        case 'update_field':
73
            hide('field_number_block');
74
            show('with_value_block');
75
            hide('to_field_block');
76
            break;
77
78
        case 'move_field':
79
            show('field_number_block');
80
            hide('with_value_block');
81
            show('to_field_block');
82
            break;
83
84
        case 'copy_field':
85
            show('field_number_block');
86
            hide('with_value_block');
87
            show('to_field_block');
88
            break;
89
90
        case 'copy_and_replace_field':
91
            show('field_number_block');
92
            hide('with_value_block');
93
            show('to_field_block');
94
            break;
95
96
    }
97
}
98
99
function onConditionalChange(selectObj) {
100
    // get the index of the selected option
101
    var idx = selectObj.selectedIndex;
102
103
    // get the value of the selected option
104
    var action = selectObj.options[idx].value;
105
106
    switch( action ) {
107
        case '':
108
            hide('conditional_block');
109
            break;
110
111
        case 'if':
112
        case 'unless':
113
            show('conditional_block');
114
            break;
115
    }
116
}
117
118
function onConditionalComparisonChange(selectObj) {
119
    // get the index of the selected option
120
    var idx = selectObj.selectedIndex;
121
122
    // get the value of the selected option
123
    var action = selectObj.options[idx].value;
124
125
    switch( action ) {
126
        case 'equals':
127
        case 'not_equals':
128
            show('conditional_comparison_block');
129
            break;
130
131
        default:
132
            hide('conditional_comparison_block');
133
            break;
134
    }
135
}
136
137
function onToFieldRegexChange( checkboxObj ) {
138
    if ( checkboxObj.checked ) {
139
        show('to_field_regex_value_block');
140
    } else {
141
        hide('to_field_regex_value_block');
142
    }
143
}
144
145
function onConditionalRegexChange( checkboxObj ) {
146
    if ( checkboxObj.checked ) {
147
        $("span.match_regex_prefix" ).show();
148
        $("span.match_regex_suffix" ).show();
149
    } else {
150
        $("span.match_regex_prefix" ).hide();
151
        $("span.match_regex_suffix" ).hide();
152
    }
153
}
154
155
function show(eltId) {
156
    elt = document.getElementById( eltId );
157
    elt.style.display='inline';
158
}
159
160
function hide(eltId) {
161
    clearFormElements( eltId );
162
    elt = document.getElementById( eltId );
163
    elt.style.display='none';
164
}
165
166
function clearFormElements(divId) {
167
    myBlock = document.getElementById( divId );
168
169
    var inputElements = myBlock.getElementsByTagName( "input" );
170
    for (var i = 0; i < inputElements.length; i++) {
171
        switch( inputElements[i].type ) {
172
            case "text":
173
                inputElements[i].value = '';
174
                break;
175
            case "checkbox":
176
                inputElements[i].checked = false;
177
                break;
178
        }
179
    }
180
181
    var selectElements = myBlock.getElementsByTagName( "select" );
182
    for (var i = 0; i < selectElements.length; i++) {
183
        selectElements[i].selectedIndex = 0;
184
    }
185
186
}
187
188
function confirmDelete() {
189
    var agree = confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
190
    return agree;
191
}
192
193
var modaction_legend_innerhtml;
194
var action_submit_value;
195
196
function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
197
    to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
198
    conditional_comparison, conditional_value, conditional_regex, description
199
) {
200
    document.getElementById('mmta_id').value = mmta_id;
201
202
    setSelectByValue( 'action', action );
203
    document.getElementById('action').onchange();
204
205
    setSelectByValue( 'field_number', field_number );
206
207
    document.getElementById('from_field').value = from_field;
208
    document.getElementById('from_subfield').value = from_subfield;
209
    document.getElementById('field_value').value = field_value;
210
    document.getElementById('to_field').value = to_field;
211
    document.getElementById('to_subfield').value = to_subfield;
212
    $("#to_regex_search").val(to_regex_search);
213
    $("#to_regex_replace").val(to_regex_replace);
214
    $("#to_regex_modifiers").val(to_regex_modifiers);
215
216
    document.getElementById('to_field_regex').checked = conditional_regex.length;
217
    document.getElementById('to_field_regex').onchange();
218
219
    setSelectByValue( 'conditional', conditional );
220
    document.getElementById('conditional').onchange();
221
222
    document.getElementById('conditional_field').value = conditional_field;
223
    document.getElementById('conditional_subfield').value = conditional_subfield;
224
225
    setSelectByValue( 'conditional_comparison', conditional_comparison );
226
    document.getElementById('conditional_comparison').onchange();
227
228
    document.getElementById('conditional_value').value = conditional_value;
229
230
    document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
231
232
    document.getElementById('description').value = description;
233
234
    window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
235
    document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(ordering);
236
237
    window.action_submit_value = document.getElementById('action_submit').value;
238
    document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
239
240
    show('cancel_edit');
241
}
242
243
function cancelEditAction() {
244
    document.getElementById('mmta_id').value = '';
245
246
    setSelectByValue( 'action', 'delete_field' );
247
    document.getElementById('action').onchange();
248
249
    document.getElementById('from_field').value = '';
250
    document.getElementById('from_subfield').value = '';
251
    document.getElementById('field_value').value = '';
252
    document.getElementById('to_field').value = '';
253
    document.getElementById('to_subfield').value = '';
254
    $("#to_regex_search").val("");
255
    $("#to_regex_replace").val("");
256
    $("#to_regex_modifiers").val("");
257
258
    document.getElementById('to_field_regex').checked = false;
259
    document.getElementById('to_field_regex').onchange();
260
261
    setSelectByValue( 'conditional', '' );
262
    document.getElementById('conditional').onchange();
263
264
    document.getElementById('conditional_field').value = '';
265
    document.getElementById('conditional_subfield').value = '';
266
267
    setSelectByValue( 'conditional_comparison', '' );
268
    document.getElementById('conditional_comparison').onchange();
269
270
    document.getElementById('conditional_value').value = '';
271
272
    document.getElementById('conditional_regex').checked = false;
273
274
    document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
275
    document.getElementById('action_submit').value = window.action_submit_value;
276
277
    hide('cancel_edit');
278
}
279
280
function setSelectByValue( selectId, value ) {
281
    s = document.getElementById( selectId );
282
283
    for ( i = 0; i < s.options.length; i++ ) {
284
        if ( s.options[i].value == value ) {
285
            s.selectedIndex = i;
286
        }
287
    }
288
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt (-299 / +17 lines)
Lines 1-303 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; MARC modification templates</title>
2
<title>Koha &rsaquo; Tools &rsaquo; MARC modification templates</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
5
<script type="text/javascript">
4
<script type="text/javascript">
6
//<![CDATA[
5
    //<![CDATA[
7
$(document).ready(function() {
6
    var MSG_MMT_SUBFIELDS_MATCH = _("Both subfield values should be filled or empty.");
8
    $('#select_template').find("input:submit").hide();
7
    var MSG_MMT_DESTINATION_REQUIRED = _("The destination should be filled.");
9
    $('#select_template').change(function() {
8
    var MSG_MMT_CONTROL_FIELD_EMPTY = _("If the field is a control field, the subfield should be empty");
10
        $('#select_template').submit();
9
    var MSG_MMT_CONTROL_FIELD = _("A control field cannot be used with a regular field.");
11
    });
10
    var MSG_MMT_SOURCE_SUBFIELD = _("The source subfield should be filled for update.");
12
    $("span.match_regex_prefix" ).hide();
11
    var MSG_MMT_SOURCE_FIELD = _("The source field should be filled.");
13
    $("span.match_regex_suffix" ).hide();
12
    var MSG_MMT_EVERY = _("Every");
14
13
    var MSG_MMT_ALL = _("All");
15
    $("#add_action").submit(function(){
14
    var MSG_MMT_CONFIRM_DEL_TEMPLATE= _("Are you sure you wish to delete this template?");
16
        var action = $("#action").val();
15
    var MSG_MMT_EDIT_ACTION = _("Edit action %s");
17
        if ( action == 'move_field' || action == 'copy_field' || action == 'copy_and_replace_field') {
16
    var MSG_MMT_UPDATE_ACTION = _("Update action");
18
            if ( $("#from_subfield").val().length != $("#to_subfield").val().length ) {
17
    //]]>
19
                alert(_("Both subfield values should be filled or empty."));
20
                return false;
21
            }
22
            if ( $("#to_field").val().length <= 0 ) {
23
                alert(_("The destination should be filled."));
24
                return false;
25
            }
26
            if ( ( $("#to_field").val()   < 10 && $("#to_subfield").val().length   > 0 ) ||
27
                 ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) {
28
                 alert(_("If the field is a control field, the subfield should be empty"));
29
                 return false;
30
            }
31
            if ( ( $("#from_field").val() < 10 && $("#to_subfield").val().length   == 0 ) ||
32
                 ( $("#to_field").val()   < 10 && $("#from_subfield").val().length == 0 ) ) {
33
                alert(_("A control field cannot be used with a regular field."));
34
                return false;
35
             }
36
        }
37
        if ( action == 'update_field' ) {
38
            if ( $("#from_subfield").val().length <= 0 ) {
39
                alert(_("The source subfield should be filled for update."));
40
                return false;
41
            }
42
        }
43
        if ( $("#from_field").val().length <= 0 ) {
44
            alert(_("The source field should be filled."));
45
            return false;
46
        }
47
    });
48
49
    $("#conditional_field,#from_field").change(function(){
50
        updateAllEvery();
51
    });
52
});
53
//]]>
54
</script>
18
</script>
55
19
<script type="text/javascript" src="[% themelang %]/js/marc_modification_templates.js"></script>
56
<script>
57
function updateAllEvery(){
58
    if ( $("#conditional_field").is(":visible") ) {
59
        if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
60
            $("#field_number option[value='0']").html(_("Every"));
61
        } else {
62
            $("#field_number option[value='0']").html(_("All"));
63
        }
64
    }
65
}
66
67
function onActionChange(selectObj) {
68
    // get the index of the selected option
69
    var idx = selectObj.selectedIndex;
70
71
    // get the value of the selected option
72
    var action = selectObj.options[idx].value;
73
74
    switch( action ) {
75
        case 'delete_field':
76
            show('field_number_block');
77
            hide('with_value_block');
78
            hide('to_field_block');
79
            break;
80
81
        case 'update_field':
82
            hide('field_number_block');
83
            show('with_value_block');
84
            hide('to_field_block');
85
            break;
86
87
        case 'move_field':
88
            show('field_number_block');
89
            hide('with_value_block');
90
            show('to_field_block');
91
            break;
92
93
        case 'copy_field':
94
            show('field_number_block');
95
            hide('with_value_block');
96
            show('to_field_block');
97
            break;
98
99
        case 'copy_and_replace_field':
100
            show('field_number_block');
101
            hide('with_value_block');
102
            show('to_field_block');
103
            break;
104
105
    }
106
}
107
108
function onConditionalChange(selectObj) {
109
    // get the index of the selected option
110
    var idx = selectObj.selectedIndex;
111
112
    // get the value of the selected option
113
    var action = selectObj.options[idx].value;
114
115
    switch( action ) {
116
        case '':
117
            hide('conditional_block');
118
            break;
119
120
        case 'if':
121
        case 'unless':
122
            show('conditional_block');
123
            break;
124
    }
125
}
126
127
function onConditionalComparisonChange(selectObj) {
128
    // get the index of the selected option
129
    var idx = selectObj.selectedIndex;
130
131
    // get the value of the selected option
132
    var action = selectObj.options[idx].value;
133
134
    switch( action ) {
135
        case 'equals':
136
        case 'not_equals':
137
            show('conditional_comparison_block');
138
            break;
139
140
        default:
141
            hide('conditional_comparison_block');
142
            break;
143
    }
144
}
145
146
function onToFieldRegexChange( checkboxObj ) {
147
    if ( checkboxObj.checked ) {
148
        show('to_field_regex_value_block');
149
    } else {
150
        hide('to_field_regex_value_block');
151
    }
152
}
153
154
function onConditionalRegexChange( checkboxObj ) {
155
    if ( checkboxObj.checked ) {
156
        $("span.match_regex_prefix" ).show();
157
        $("span.match_regex_suffix" ).show();
158
    } else {
159
        $("span.match_regex_prefix" ).hide();
160
        $("span.match_regex_suffix" ).hide();
161
    }
162
}
163
164
function show(eltId) {
165
    elt = document.getElementById( eltId );
166
    elt.style.display='inline';
167
}
168
169
function hide(eltId) {
170
    clearFormElements( eltId );
171
    elt = document.getElementById( eltId );
172
    elt.style.display='none';
173
}
174
175
function clearFormElements(divId) {
176
    myBlock = document.getElementById( divId );
177
178
    var inputElements = myBlock.getElementsByTagName( "input" );
179
    for (var i = 0; i < inputElements.length; i++) {
180
        switch( inputElements[i].type ) {
181
            case "text":
182
                inputElements[i].value = '';
183
                break;
184
            case "checkbox":
185
                inputElements[i].checked = false;
186
                break;
187
        }
188
    }
189
190
    var selectElements = myBlock.getElementsByTagName( "select" );
191
    for (var i = 0; i < selectElements.length; i++) {
192
        selectElements[i].selectedIndex = 0;
193
    }
194
195
}
196
197
function confirmDelete() {
198
    var agree = confirm(_("Are you sure you wish to delete this template?"));
199
    return agree;
200
}
201
202
var modaction_legend_innerhtml;
203
var action_submit_value;
204
205
function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
206
    to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
207
    conditional_comparison, conditional_value, conditional_regex, description
208
) {
209
    document.getElementById('mmta_id').value = mmta_id;
210
211
    setSelectByValue( 'action', action );
212
    document.getElementById('action').onchange();
213
214
    setSelectByValue( 'field_number', field_number );
215
216
    document.getElementById('from_field').value = from_field;
217
    document.getElementById('from_subfield').value = from_subfield;
218
    document.getElementById('field_value').value = field_value;
219
    document.getElementById('to_field').value = to_field;
220
    document.getElementById('to_subfield').value = to_subfield;
221
    $("#to_regex_search").val(to_regex_search);
222
    $("#to_regex_replace").val(to_regex_replace);
223
    $("#to_regex_modifiers").val(to_regex_modifiers);
224
225
    document.getElementById('to_field_regex').checked = conditional_regex.length;
226
    document.getElementById('to_field_regex').onchange();
227
228
    setSelectByValue( 'conditional', conditional );
229
    document.getElementById('conditional').onchange();
230
231
    document.getElementById('conditional_field').value = conditional_field;
232
    document.getElementById('conditional_subfield').value = conditional_subfield;
233
234
    setSelectByValue( 'conditional_comparison', conditional_comparison );
235
    document.getElementById('conditional_comparison').onchange();
236
237
    document.getElementById('conditional_value').value = conditional_value;
238
239
    document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
240
241
    document.getElementById('description').value = description;
242
243
    window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
244
    document.getElementById('modaction_legend').innerHTML = _("Edit action %s").format(ordering);
245
246
    window.action_submit_value = document.getElementById('action_submit').value;
247
    document.getElementById('action_submit').value = _("Update action");
248
249
    show('cancel_edit');
250
}
251
252
function cancelEditAction() {
253
    document.getElementById('mmta_id').value = '';
254
255
    setSelectByValue( 'action', 'delete_field' );
256
    document.getElementById('action').onchange();
257
258
    document.getElementById('from_field').value = '';
259
    document.getElementById('from_subfield').value = '';
260
    document.getElementById('field_value').value = '';
261
    document.getElementById('to_field').value = '';
262
    document.getElementById('to_subfield').value = '';
263
    $("#to_regex_search").val("");
264
    $("#to_regex_replace").val("");
265
    $("#to_regex_modifiers").val("");
266
267
    document.getElementById('to_field_regex').checked = false;
268
    document.getElementById('to_field_regex').onchange();
269
270
    setSelectByValue( 'conditional', '' );
271
    document.getElementById('conditional').onchange();
272
273
    document.getElementById('conditional_field').value = '';
274
    document.getElementById('conditional_subfield').value = '';
275
276
    setSelectByValue( 'conditional_comparison', '' );
277
    document.getElementById('conditional_comparison').onchange();
278
279
    document.getElementById('conditional_value').value = '';
280
281
    document.getElementById('conditional_regex').checked = false;
282
283
    document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
284
    document.getElementById('action_submit').value = window.action_submit_value;
285
286
    hide('cancel_edit');
287
}
288
289
function setSelectByValue( selectId, value ) {
290
    s = document.getElementById( selectId );
291
292
    for ( i = 0; i < s.options.length; i++ ) {
293
        if ( s.options[i].value == value ) {
294
            s.selectedIndex = i;
295
        }
296
    }
297
}
298
299
</script>
300
301
</head>
20
</head>
302
21
303
<body id="tools_marc_modification_templates" class="tools">
22
<body id="tools_marc_modification_templates" class="tools">
Lines 311-317 function setSelectByValue( selectId, value ) { Link Here
311
    <div id="yui-main">
30
    <div id="yui-main">
312
        <div class="yui-b">
31
        <div class="yui-b">
313
            <h2>MARC modification templates</h2>
32
            <h2>MARC modification templates</h2>
314
            
33
315
            [% IF error %]
34
            [% IF error %]
316
                [% IF error == 'no_from_field' %]
35
                [% IF error == 'no_from_field' %]
317
                    <div class="dialog message">Error: no field value specified.</div>
36
                    <div class="dialog message">Error: no field value specified.</div>
Lines 351-358 function setSelectByValue( selectId, value ) { Link Here
351
                            <th>Order</th>
70
                            <th>Order</th>
352
                            <th>Action</th>
71
                            <th>Action</th>
353
                            <th>Description</th>
72
                            <th>Description</th>
354
                            <th>&nbsp</th>
73
                            <th>&nbsp;</th>
355
                            <th>&nbsp</th>
74
                            <th>&nbsp;</th>
356
                        </tr>
75
                        </tr>
357
76
358
                        [% FOREACH ActionsLoo IN ActionsLoop %]
77
                        [% FOREACH ActionsLoo IN ActionsLoop %]
359
- 

Return to bug 15867