Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 4th, 2013  |  syntax: None  |  size: 4.62 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var isCellActive = false;
  2.  
  3. function _altMakeEdit(id) {
  4.     debugger;
  5.     if (!isCellActive) {
  6.         var val = document.getElementById(id).innerHTML;
  7.         if (val != "<div>&nbsp;</div>") {
  8.             document.getElementById(id).parentNode.innerHTML = "<input onblur='submitChange(&#39;" + id + "&#39;,&#34;" + val + "&#34;);' type='text' id='" + id + "' value='" + val + "'></input>";
  9.         }
  10.         else if (val == "<div>&nbsp;</div>") {
  11.             document.getElementById(id).parentNode.innerHTML = "<input onblur='submitChange(&#39;" + id + "&#39;,&#34;" + val + "&#34;);' type='text' id='" + id + "' value=''></input>";
  12.         }
  13.         document.getElementById(id).focus()
  14.     }
  15.     isCellActive = true;
  16. }
  17.  
  18. function submitChange(id, value) {
  19.  
  20.     var row = id.split(",")[0];
  21.     var col = id.split(",")[1];
  22.     debugger;
  23.     var mainString = row + ",0";
  24.     var altString = row + ",1";
  25.     var purposeString = row + ",2";
  26.     var main=''
  27.     var alt ='';
  28.     var purpose ='';
  29.     var column = '';
  30.  
  31.     switch (col){
  32.         case '0':
  33.             main = document.getElementById(mainString).value.trim();
  34.             alt = document.getElementById(altString).innerHTML.trim();
  35.             purpose = document.getElementById(purposeString).innerHTML.trim();
  36.             column = 'main';
  37.             if (main.trim().length == 0) {
  38.                 alert("Main Cannot Be Empty");
  39.             }
  40.             else {
  41.                 document.getElementById(id).parentNode.innerHTML = "<span id='" + id + "' onclick='_altMakeEdit(&#39;" + id + "&#39;);'>" + main + "</span>";
  42.                 isCellActive = false;
  43.             }
  44.             break;
  45.         case '1':
  46.             main = document.getElementById(mainString).innerHTML.trim();
  47.             alt = document.getElementById(altString).value.trim();
  48.             purpose = document.getElementById(purposeString).innerHTML.trim();
  49.             column = 'alt';
  50.             if (alt.trim().length == 0) {
  51.                 alert("Alt Cannot Be Empty");
  52.             }
  53.             else {
  54.                 document.getElementById(id).parentNode.innerHTML = "<span id='" + id + "' onclick='_altMakeEdit(&#39;" + id + "&#39;);'>" + alt + "</span>";
  55.                 isCellActive = false;
  56.             }
  57.             break;
  58.         case '2':
  59.             main = document.getElementById(mainString).innerHTML.trim();
  60.             alt = document.getElementById(altString).innerHTML.trim();
  61.             purpose = document.getElementById(purposeString).value.trim();
  62.             column = 'purpose';
  63.             if (purpose == "") {
  64.                 document.getElementById(id).parentNode.innerHTML = "<div id='" + id + "' onclick='_altMakeEdit(&#39;" + id + "&#39;);'>&nbsp</div>";
  65.             }
  66.             else {
  67.                 document.getElementById(id).parentNode.innerHTML = "<span id='" + id + "' onclick='_altMakeEdit(&#39;" + id + "&#39;);'>" + purpose + "</span>";
  68.             }
  69.             isCellActive = false;
  70.             break;
  71.     }
  72.     var request = new XMLHttpRequest();
  73.     debugger;
  74.     request.onreadystatechange = function () {
  75.         if (request.readyState == 4 && request.status == 200) {
  76.             //Awesome job reece \o/
  77.         }
  78.     }
  79.     var URL = "/Pilot/editAlt/?main=" + main + "&alt=" + alt + "&purpose=" + purpose + "&column=" + column;
  80.     request.open('GET', URL, true);
  81.     request.send();
  82.  
  83. }
  84.  
  85. function deleteAlt(id) {
  86.     var request = new XMLHttpRequest();
  87.     debugger;
  88.     request.onreadystatechange = function () {
  89.         if (request.readyState == 4 && request.status == 200) {
  90.            
  91.         }
  92.     }
  93.     var URL = "/Pilot/deleteAlt/?pos=" + id;
  94.     request.open('GET', URL, false);
  95.     request.send();
  96.     document.location.reload(true)
  97. }
  98.  
  99. function addAlt() {
  100.     $("#newAltBox").css("display", "block");
  101.  
  102. }
  103.  
  104. function submitNewAlt() {
  105.     debugger;
  106.     var mainName = document.getElementById("mainName").options[document.getElementById("mainName").selectedIndex].text;
  107.     var altName = document.getElementById("altName").value;
  108.     var purpose = document.getElementById("altPurpose").value;
  109.  
  110.     if (altName.trim().length == 0) {
  111.         alert('New Alt Name Must Not Be Empty');
  112.     }
  113.     else {
  114.         var request = new XMLHttpRequest();
  115.         debugger;
  116.         request.onreadystatechange = function () {
  117.             if (request.readyState == 4 && request.status == 200) {
  118.  
  119.             }
  120.         }
  121.         var URL = "/Pilot/addAlt/?mainName=" + mainName + "&altName=" + altName + "&altPurpose=" + purpose;
  122.         request.open('GET', URL, false);
  123.         request.send();
  124.         document.location.reload(true)
  125.     }
  126. }
clone this paste RAW Paste Data