123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- 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('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
- });
- }
- });
-
- 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('<a href="javascript:deleteSingleAssignment(' + assID +', ' + i + ');">[⨯]</a>');
-
- arr = jQuery.map( searchpattern, function( n, i ) {
- return ( n + "." );
- });
-
- $('[data-class=search]',clonePattern).html('<a href="javascript:newSearchAssignment(\'' + curstation + '\', \'' + arr.join( "" ) +'\', \'' + pattern.TEXT + '\' );">[?]</a>');
-
-
- $('#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){
-
- 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();
- }
-
- $.ajax({
- type: "Post",
- data: JSON.stringify(obj),
- headers: {"content-id": "list"},
- contentType: "application/json",
- url: "../server/assignments/",
- success: function(res) {
- if(!skipasscreationform){
- createAssignmentForm(res.id, $('#addExternalImageAssignment').val())
- }
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
- }
- function deleteAssignment(assignmentID) { //Delete From DB
- if (confirm('Are you really, really, REALLY sure!')) {
- $.ajax({
- type: "DELETE",
- url: "../server/assignments/" + assignmentID,
- success: function(res) {
- 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=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('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
- });
- }
- });
- }
- function initAssignmentTable(){
- $('#assignmentdetaillist').text("");
- $('#assignmentdetaillist').append("<tr id='copyAssignmentTable'></tr>");
- $('#assignmentdetaillist tr').append("<td data-class='station'>Station</td>");
- $.getJSON( "../server/json/ProductCode.json", function( data ) {
- $.each( data["pattern"], function(i, item){
- $('#assignmentdetaillist tr').append("<td data-class='part"+ item["abk"] +"'>"+ item["abk"] +"</td>");
- productcodestructure[item["abk"]] = "";
- });
- $('#assignmentdetaillist tr').append("<td data-class='partTEXT'>Text</td>");
- $('#assignmentdetaillist tr').append("<td data-class='delete'>Delete</td>");
- $('#assignmentdetaillist tr').append("<td data-class='search'>Search</td>");
- });
-
- }
- $(document).ready(function() {
- initAssignment();
- $(document).on('submit', '#assignmentform', function() { //prevent page reload on form submit
- return false;
- });
-
- });
|