var productcodestructure = {}; function createAssignmentForm(assID, url){ initAssignmentTable(); $('#assignmentstation').find('option').remove() $.ajax({ type: "GET", url: "../server/", dataType: "xml", success: function(xml) { $(xml).find('station').each(function(index){ $('#assignmentstation').append(''); }); } }); if (assID == null){ $('#storedassignments').css("display", "none"); $('#assignmentLupe').css("display", "block"); //$('#addExternalImageAssignment').removeAttr('disabled'); $('#addExternalImageAssignment').val(""); $('#updateExternalImageAssignment').css("display", "none"); } else{ $('#storedassignments').css("display", "block"); $('#updateExternalImageAssignment').css("display", "block"); $('#updateExternalImageAssignment').attr('onClick', 'updateImage(' + assID + ')'); $('#assignmentLupe').css("display", "none"); //$('#addExternalImageAssignment').attr('disabled','disabled'); $('#addExternalImageAssignment').val(url); //Show Assignments $.getJSON( "../server/assignments/" + assID, function( data ) { $.each( data, function(curstation, alldata){ var clonePattern = $("#copyAssignmentTable").clone(); $('td',clonePattern).text(""); $('[data-class=station]',clonePattern).text(curstation); $('#assignmentdetaillist').append(clonePattern); $.each( alldata, function(i, pattern){ var clonePattern = $("#copyAssignmentTable").clone(); $('td',clonePattern).text(""); var searchpattern = productcodestructure; $.each( pattern, function(i, item){ $('[data-class=part' + i + ']',clonePattern).text(item); if(i != "TEXT"){ searchpattern[i] = item; } }); $('[data-class=delete]',clonePattern).html('[тип]'); arr = jQuery.map( searchpattern, function( n, i ) { return ( n + "." ); }); $('[data-class=search]',clonePattern).html('[?]'); $('#assignmentdetaillist').append(clonePattern); }); }); }); } $('#assignment_details').css("display", "block"); } function updateImage(assID){ var newImgUrl = $('#addExternalImageAssignment').val(); $.ajax({ type: "Put", data: '{"url": "' + newImgUrl + '"}', headers: {"content-id": "list"}, contentType: "application/json", url: "../server/assignments/" + assID, success: function(res) { //reload assignmentlist (left) initAssignment(); //reload cur assignment (right) createAssignmentForm(assID, newImgUrl) }, error: function (request, status, error) { alert(request.responseText + status + error); } }); } //called when new image is selected function getImgText(imgtext){ var result = /[^;]*$/.exec(imgtext)[0]; if(result != imgtext){ $('#assignmentText').val(result.replace(/\.[^/.]+$/, "")) } } function submitAssignment(newassignment){ //console.log("Submiting Assignment") var obj = new Object(); var skipasscreationform = false; if(typeof newassignment !== "undefined"){ skipasscreationform = true; obj = newassignment; } else{ obj.img = $('#addExternalImageAssignment').val(); obj.station = $('#assignmentstation option:selected').text(); obj.parts = {}; abk.forEach(function(item){ if(typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined' && typeof $("#FormPatternAssignment_Form_" + item).val() !== 'undefined'){ //if($("#FormPatternAssignment_Form_" + item).find(":selected").text() != ""){ obj.parts[item] = $("#FormPatternAssignment_Form_" + item).find(":selected").text(); //} } }); obj.assignmentText = $('#assignmentText').val(); } //console.log(obj) $.ajax({ type: "Post", data: JSON.stringify(obj), headers: {"content-id": "list"}, contentType: "application/json", url: "../server/assignments/", async: false, success: function(res) { //console.log("Posted") if(!skipasscreationform){ createAssignmentForm(res.id, $('#addExternalImageAssignment').val()) } }, error: function (request, status, error) { alert(request.responseText + status + error); } }); } function removeSelectedItems(){ var removedItems = []; $("#assignmentslist input[type=checkbox]:checked").each(function(index, data){ removedItems.push($(data).attr("name")); }); if (confirm('Deleting: ' + removedItems)) { $("#assignmentslist input[type=checkbox]:checked").each(function(index, data){ //only refresh item list when last item is removed deleteAssignment($(data).attr("name"), false, index === ($("#assignmentslist input[type=checkbox]:checked").length -1)) }); } } function deleteAssignment(assignmentID, ask = true, refresh = true) { //Delete From DB if (!ask || confirm('Are you really, really, REALLY sure!')) { $.ajax({ type: "DELETE", url: "../server/assignments/" + assignmentID, success: function(res) { if(refresh) initAssignment(); } }); } } function deleteSingleAssignment(assignmentID, patternID) { //Delete From DB if (confirm('Are you really, really, REALLY sure!')) { $.ajax({ type: "DELETE", url: "../server/assignments/" + assignmentID + "/" + patternID, success: function(res) { //initAssignment(); createAssignmentForm(assignmentID, $('#addExternalImageAssignment').val()) } }); } } function newSearchAssignment(station, pattern, searchtext){ console.log(station + pattern + searchtext); $('#searchAssingmentStation').val(station); $('#searchAssingmentPattern').val(pattern); $('#searchAssingmentText').val(searchtext); searchAssignmentForm(); } function searchAssignmentForm(){ $('#assignmentslist tr').css('background-color', 'white'); $.getJSON( "../server/assignments/search/?pattern=" + $('#searchAssingmentPattern').val() + "&station=" + $('#searchAssingmentStation option:selected').text() + "&text=" + $('#searchAssingmentText').val(), function( data ) { $.each( data, function(i, item){ $('tr[name="' + item +'"]').css('background-color', '#73d216') // Matches exactly 'tcol1' }); }); } function initAssignment(){ $('#assignmentslist').text(""); $.getJSON( "../server/assignments/", function( data ) { $.each( data, function(i, item){ var clonePattern = document.importNode(document.querySelector('#assignmentitem').content,true); $('[data-class=tr]',clonePattern).attr('name', item); $('[data-class=image]',clonePattern).attr('src', item); $('[data-class=item] a',clonePattern).text(item); $('[data-class=item] a',clonePattern).attr('href','javascript:createAssignmentForm(' + i + ',"' + item + '");'); //$('[data-class=duplicate] a',clonePattern).attr('href','javascript:duplicatePattern(' + curstation + ','+ $(this).attr('id') + ');'); $('[data-class=multiRemovelink]',clonePattern).attr('name', i ); $('[data-class=delete] a',clonePattern).attr('href','javascript:deleteAssignment(' + i + ');'); $('#assignmentslist').append(clonePattern); }); }); $('#searchAssingmentStation').find('option').remove() $.ajax({ type: "GET", url: "../server/", dataType: "xml", success: function(xml) { $(xml).find('station').each(function(index){ $('#searchAssingmentStation').append(''); }); } }); } function selectAll(){ $(':input','#assignmentslist') .not(':button, :submit, :reset, :hidden') .val('') .prop('checked', true) .prop('selected', true); } function unselectAll(){ $(':input','#assignmentslist') .not(':button, :submit, :reset, :hidden') .val('') .prop('checked', false) .prop('selected', false); } function initAssignmentTable(){ $('#assignmentdetaillist').text(""); $('#assignmentdetaillist').append("