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

(-)a/koha-tmpl/intranet-tmpl/prog/js/additem.js (-27 / +26 lines)
Lines 1-4 Link Here
1
/* global __ */
1
/* global __ */
2
/* exported addItem checkCount showItem deleteItemBlock clearItemBlock check_additem */
2
function addItem( node, unique_item_fields ) {
3
function addItem( node, unique_item_fields ) {
3
    var index = $(node).closest("div").attr('id');
4
    var index = $(node).closest("div").attr('id');
4
    var current_qty = parseInt($("#quantity").val());
5
    var current_qty = parseInt($("#quantity").val());
Lines 36-50 function addMulti( count, node, unique_item_fields){ Link Here
36
    $("#procModal").modal('show');
37
    $("#procModal").modal('show');
37
    $("#" + index).hide();
38
    $("#" + index).hide();
38
    for(var i=0;i<count;i++){
39
    for(var i=0;i<count;i++){
39
       cloneItemBlock(index, unique_item_fields, function(cloneIndex){
40
        cloneItemBlock(index, unique_item_fields, function(cloneIndex){
40
            addItemInList(cloneIndex,unique_item_fields, function(){
41
            addItemInList(cloneIndex,unique_item_fields, function(){
41
                    if( ($("#items_list tbody tr").length-countItemsBefore)==(count)){
42
                if( ($("#items_list tbody tr").length-countItemsBefore)==(count)){
42
                        $("#multiValue").val('');
43
                    $("#multiValue").val('');
43
                        $('#'+index).appendTo('#outeritemblock');
44
                    $('#'+index).appendTo('#outeritemblock');
44
                        $('#'+index).show();
45
                    $('#'+index).show();
45
                        $('#'+index + ' #add_multiple_copies' ).css("visibility","hidden");
46
                    $('#'+index + ' #add_multiple_copies' ).css("visibility","hidden");
46
                        $("#procModal").modal('hide');
47
                    $("#procModal").modal('hide');
47
                    }
48
                }
48
            });
49
            });
49
            $("#" + cloneIndex).find("input[name='buttonPlus']").val( ( __("Update item") ) );
50
            $("#" + cloneIndex).find("input[name='buttonPlus']").val( ( __("Update item") ) );
50
            $("#" + cloneIndex).find("input[name='buttonPlusMulti']").remove();
51
            $("#" + cloneIndex).find("input[name='buttonPlusMulti']").remove();
Lines 52-62 function addMulti( count, node, unique_item_fields){ Link Here
52
            $("#" + cloneIndex).hide();
53
            $("#" + cloneIndex).hide();
53
            current_qty++;
54
            current_qty++;
54
            $('#quantity').val( current_qty );
55
            $('#quantity').val( current_qty );
55
       });
56
        });
56
    }
57
    }
57
}
58
}
58
59
59
60
function checkCount(node, unique_item_fields){
60
function checkCount(node, unique_item_fields){
61
    var count = parseInt( $("#multiValue").val(), 10 );
61
    var count = parseInt( $("#multiValue").val(), 10 );
62
    if ( isNaN( count ) || count <=0) {
62
    if ( isNaN( count ) || count <=0) {
Lines 93-99 function constructTrNode(index, unique_item_fields) { Link Here
93
        + "onclick='deleteItemBlock(this, \"" + index + "\", \"" + unique_item_fields + "\");' class='btn btn-default btn-xs'><i class='fa fa-trash'></i> "
93
        + "onclick='deleteItemBlock(this, \"" + index + "\", \"" + unique_item_fields + "\");' class='btn btn-default btn-xs'><i class='fa fa-trash'></i> "
94
        + ( __("Delete") ) + "</a>";
94
        + ( __("Delete") ) + "</a>";
95
    result += "<td class='actions'>" + edit_link + " " + del_link + "</td>";
95
    result += "<td class='actions'>" + edit_link + " " + del_link + "</td>";
96
    for(i in fields) {
96
    for(var i in fields) {
97
        var field = fields[i];
97
        var field = fields[i];
98
        var field_elt = $("#" + index)
98
        var field_elt = $("#" + index)
99
            .find("[name='kohafield'][value='items."+field+"']")
99
            .find("[name='kohafield'][value='items."+field+"']")
Lines 154-161 function cloneItemBlock(index, unique_item_fields, callback) { Link Here
154
    }
154
    }
155
    var dont_copy_fields = new Array();
155
    var dont_copy_fields = new Array();
156
    if(unique_item_fields) {
156
    if(unique_item_fields) {
157
        var dont_copy_fields = unique_item_fields.split('|');
157
        dont_copy_fields = unique_item_fields.split('|');
158
        for(i in dont_copy_fields) {
158
        for(var i in dont_copy_fields) {
159
            dont_copy_fields[i] = "items." + dont_copy_fields[i];
159
            dont_copy_fields[i] = "items." + dont_copy_fields[i];
160
        }
160
        }
161
    }
161
    }
Lines 166-172 function cloneItemBlock(index, unique_item_fields, callback) { Link Here
166
        data: {
166
        data: {
167
            frameworkcode: 'ACQ'
167
            frameworkcode: 'ACQ'
168
        },
168
        },
169
        success: function(data, textStatus, jqXHR) {
169
        success: function(data) {
170
            /* Create the item block */
170
            /* Create the item block */
171
            var random = Math.floor(Math.random()*100000); // get a random itemid.
171
            var random = Math.floor(Math.random()*100000); // get a random itemid.
172
            var clone = $("<div/>", { id: 'itemblock'+random });
172
            var clone = $("<div/>", { id: 'itemblock'+random });
Lines 178-192 function cloneItemBlock(index, unique_item_fields, callback) { Link Here
178
            });
178
            });
179
            /* Add buttons + and Clear */
179
            /* Add buttons + and Clear */
180
            var buttonPlus = "<fieldset class=\"action\">";
180
            var buttonPlus = "<fieldset class=\"action\">";
181
                buttonPlus += '<input type="button" class="addItemControl" name="buttonPlus" style="cursor:pointer; margin:0 1em;" onclick="addItem(this,\'' + unique_item_fields + '\')" value="' + ( __("Add item") )+ '" />';
181
            buttonPlus += '<input type="button" class="addItemControl" name="buttonPlus" style="cursor:pointer; margin:0 1em;" onclick="addItem(this,\'' + unique_item_fields + '\')" value="' + ( __("Add item") )+ '" />';
182
                buttonPlus += '<input type="button" class="addItemControl cancel" name="buttonClear" style="cursor:pointer;" onclick="clearItemBlock(this)" value="' + __("Clear") + '" />';
182
            buttonPlus += '<input type="button" class="addItemControl cancel" name="buttonClear" style="cursor:pointer;" onclick="clearItemBlock(this)" value="' + __("Clear") + '" />';
183
                buttonPlus += '<input type="button" class="addItemControl" name="buttonPlusMulti" onclick="javascript:this.nextSibling.style.display=\'inline\'; return false;" style="cursor:pointer; margin:0 1em;" value="' + __("Add multiple items") + '" />';
183
            buttonPlus += '<input type="button" class="addItemControl" name="buttonPlusMulti" onclick="javascript:this.nextSibling.style.display=\'inline\'; return false;" style="cursor:pointer; margin:0 1em;" value="' + __("Add multiple items") + '" />';
184
                buttonPlus += '<span id="add_multiple_copies" style="display:none">'
184
            buttonPlus += '<span id="add_multiple_copies" style="display:none">'
185
                            +     '<input type="number" class="addItemControl" id="multiValue" name="multiValue" placeholder="' + __("Number of items to add") + '" />'
185
                +     '<input type="number" class="addItemControl" id="multiValue" name="multiValue" placeholder="' + __("Number of items to add") + '" />'
186
                            +     '<input type="button" class="addItemControl" name=buttonAddMulti" style="cursor:pointer; margin:0 1em;" onclick="checkCount( this ,\'' + unique_item_fields + '\')" value="' + __("Add") + '" />'
186
                +     '<input type="button" class="addItemControl" name=buttonAddMulti" style="cursor:pointer; margin:0 1em;" onclick="checkCount( this ,\'' + unique_item_fields + '\')" value="' + __("Add") + '" />'
187
                            +     '<div class="dialog message">' + __("NOTE: Fields listed in the 'UniqueItemsFields' system preference will not be copied") + '</div>'
187
                +     '<div class="dialog message">' + __("NOTE: Fields listed in the 'UniqueItemsFields' system preference will not be copied") + '</div>'
188
                            + '</span>';
188
                + '</span>';
189
                buttonPlus += "</fieldset>";
189
            buttonPlus += "</fieldset>";
190
            $(clone).append(buttonPlus);
190
            $(clone).append(buttonPlus);
191
            /* Copy values from the original block (input) */
191
            /* Copy values from the original block (input) */
192
            $(original).find("input[name='field_value']").each(function(){
192
            $(original).find("input[name='field_value']").each(function(){
Lines 227-233 function BindPluginEvents(data) { Link Here
227
    for(var i=0; i<events.length; i++) {
227
    for(var i=0; i<events.length; i++) {
228
        window[events[i]]();
228
        window[events[i]]();
229
        if( i<events.length-1 && events[i]==events[i+1] ) { i++; }
229
        if( i<events.length-1 && events[i]==events[i+1] ) { i++; }
230
            // normally we find the function name twice
230
        // normally we find the function name twice
231
    }
231
    }
232
}
232
}
233
233
Lines 251-257 function check_additem(unique_item_fields) { Link Here
251
    $(".order_error").empty(); // Clear error div
251
    $(".order_error").empty(); // Clear error div
252
252
253
    // Check if a value is duplicated in form
253
    // Check if a value is duplicated in form
254
    for ( field in array_fields ) {
254
    for ( var field in array_fields ) {
255
        var fieldname = array_fields[field];
255
        var fieldname = array_fields[field];
256
        if (fieldname == '') {
256
        if (fieldname == '') {
257
            continue;
257
            continue;
Lines 290-296 function check_additem(unique_item_fields) { Link Here
290
        dataType: 'json',
290
        dataType: 'json',
291
        data: data,
291
        data: data,
292
        success: function(data) {
292
        success: function(data) {
293
            for (field in data) {
293
            for (var field in data) {
294
                success = false;
294
                success = false;
295
                for (var i=0; i < data[field].length; i++) {
295
                for (var i=0; i < data[field].length; i++) {
296
                    var value = data[field][i];
296
                    var value = data[field][i];
297
- 

Return to bug 25353