Harjutuse lisamise-salvestamise näide: erinevus redaktsioonide vahel

Allikas: Lambda
Mine navigeerimisribale Mine otsikasti
Resümee puudub
Resümee puudub
 
1. rida: 1. rida:
<pre><nowiki>
<pre><nowiki>
  <html>
  <html>
   <head><title>Lisamine</title>
 
   <head><title></title>
   </head>
   </head>
   <body>
   <body>
    <script src="jquery.js" type="text/javascript">
  <script src="jquery.js" type="text/javascript">
    </script>
  </script>
    <script type="text/javascript">
  <script>
 
       function editTodo (index) {
    var todostore;
         $("#debug").html(index);
 
          
    function change(i) {
      /* load fields */
      item = todostore[i];
           
      $("#editid").val(item.id);
      $("#esalvestaja").val(item.salvestaja);
      $("#etodoname").val(item.f0);
      $("#etododesc").val(item.f1);
 
    }
 
    function sendEditForm() {
      var url = "http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui/uuenda.py?table=t0";
      url += "&f0=" + $("#todoname").val();
      url += "&f1=" + $("#tododesc").val();
     
      $("#debug").html(url);
      $.getJSON(url, sendFormCallback);
       return false;
 
    }
 
 
    function renderTableCallback(todolist, textStatus, jqXHR) {
     
 
      todostore = todolist;
      if (todolist == 0 || todolist.length == 0) {
         $("#todotable").html("No results, add some; might be our error too, sorry.");
         return;
       }
       }
 
       function renderTodoCallback( todolist, textStatus, jqXHR) {
 
       result ="<tr><th>Name</th><th>Description</th></tr>\n";
        $("#debug").html("");
 
      for ( i=0; i < todolist.length; i++ ) {
        var tablecontent = "<tr><th>Name</th><th>Desc</th><th></th></tr>\n";
        result += "<tr>";
        result += "<td>" + todolist[i].f0 + "</td>";
        for (i = 0; i < todolist.length; i++) {
        result += "<td>" + todolist[i].f1 + "</td>";
          tablecontent += "<tr>\n<td>" + todolist[i].f0 + "</td><br/>\n";
        result += "<td><a href=\"javascript:change(" + i + ")\">[Muuda]</a></td>";
          tablecontent += "<td>" + todolist[i].f1 + "</td>\n";
        result += "</tr>";
          tablecontent += "<td><a href=\"javascript:editTodo(" +
    }
            todolist[i].id + ");\">Muuda</a></td>\n</tr>\n";
    $("#todotable").html(result);
 
          tablecontent += "</tr>\n";
    }
        }
 
 
    function renderTable() {
       $("#todolist").html(tablecontent);
      $.getJSON("http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui/otsi.py?salvestaja=test@example.ee&table=t0&order=f0&direction=desc", renderTableCallback);
    }
 
    function sendFormCallback(status, textStatus, jqXHR) {
       if (status == 0 ) {
        $("#debug").html("Sending unsuccessful");
        return;
       }
       }
 
       function renderTodo() {
       renderTable();
        $.getJSON("http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui3/otsi.py?table=t0&salvestaja=test@example.ee", renderTodoCallback);
 
       }
    }
 
       function addTodoCallback(sendstatus, textStatus, jqXHR) {
 
    function sendForm() {
        if (sendstatus == 0) {
      var url = "http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui/salvesta.py?table=t0";
          $("#debug").html("Error with saving entry. Sorry about that.");
      url += "&salvestaja=" + $("#salvestaja").val();
          return;
       url += "&f0=" + $("#todoname").val();
        }
       url += "&f1=" + $("#tododesc").val();
     
        renderTodo();
      /*$("#debug").html(url);*/
      $.getJSON(url, sendFormCallback);
      }
      return false;
    }
      function addTodo() {
 
 
        /* add checking */
    function sendEditForm() {
      var url = "http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui/uuenda.py?table=t0";
      url += "&salvestaja=" + $("#esalvestaja").val();
        var url="http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui3/salvesta.py?table=t0&";
      url += "&f0=" + $("#etodoname").val();
        url += "salvestaja=" + $("#salvestaja").val();
      url += "&f1=" + $("#etododesc").val();
        url += "&f0=" + $("#todoname").val();
      url += "&id=" + $("#editid").val();
        url += "&f1=" + $("#tododesc").val();
     
       
      $("#debug").html(url);
        $("#debug").html(url);
      $.getJSON(url, sendFormCallback); /* note shared function */
       return false;
        $.getJSON(url, addTodoCallback );
    }
 
        return false /* don't send the form using normal means */
 
       }
 
 
$(document).ready( function() {  
    $(document).ready( function() {
       renderTodo();
 
   
       renderTable();
     
     });
     });
 
 
    </script>
  </script>
 
    <form onsubmit="return addTodo();">
 
      <input id="salvestaja" type="text" placeholder="Salvestaja" value="test@example.ee"><br/>
  <form onsubmit="return sendForm();">
      <input id="todoname" type="text" placeholder="Title"><br/>
    <p>Insert item</p>
      <input id="tododesc" type="text" placeholder="Description"><br/>
    <input id="id" type="hidden" value=""/><br />
      <input type="submit" value="Salvesta">
    <input id="salvestaja" type="text" value="test@example.ee" /><br />
    </form>
    <input id="todoname" type="text" placeholder="Todo name" /><br />
    <input id="tododesc" type="text" placeholder="Description" /><br />
    <div id="debug">
    <input id="send" type="submit" value="Save"/><br />
 
    </div>
 
  </form>
    <table id="todolist">
 
    </table>
  <form onsubmit="return sendEditForm();">
    <p>Edit item</p>
    <input id="editid" type="hidden" value=""/><br />
    <input id="esalvestaja" type="text" value="test@example.ee" /><br />
    <input id="etodoname" type="text" placeholder="Todo name" /><br />
    <input id="etododesc" type="text" placeholder="Description" /><br />
    <input id="esend" type="submit" value="Save"/><br />
  </form>
 
  <div id="debug">
  </div>
 
  <table id="todotable">
 
  </table>
 
   </body>
   </body>
</html>
</html>
</nowiki></pre>
</nowiki></pre>

Viimane redaktsioon: 3. mai 2012, kell 09:56

 <html>

  <head><title></title>
  </head>
  <body>
  <script src="jquery.js" type="text/javascript">
  </script>
  <script>

    var todostore;

    function change(i) {
      /* load fields */
      item = todostore[i];
            
      $("#editid").val(item.id);
      $("#esalvestaja").val(item.salvestaja);
      $("#etodoname").val(item.f0);
      $("#etododesc").val(item.f1);

    }

    function sendEditForm() {
      var url = "http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui/uuenda.py?table=t0";
      url += "&f0=" + $("#todoname").val();
      url += "&f1=" + $("#tododesc").val();
      
      $("#debug").html(url);
      $.getJSON(url, sendFormCallback);
      return false;

    }


    function renderTableCallback(todolist, textStatus, jqXHR) {
      

      todostore = todolist;
      if (todolist == 0 || todolist.length == 0) {
        $("#todotable").html("No results, add some; might be our error too, sorry.");
        return;
      }


      result ="<tr><th>Name</th><th>Description</th></tr>\n";

      for ( i=0; i < todolist.length; i++ ) {
        result += "<tr>";
        result += "<td>" + todolist[i].f0 + "</td>";
        result += "<td>" + todolist[i].f1 + "</td>";
        result += "<td><a href=\"javascript:change(" + i + ")\">[Muuda]</a></td>";
        result += "</tr>";
    }
    $("#todotable").html(result);

    }


    function renderTable() {
      $.getJSON("http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui/otsi.py?salvestaja=test@example.ee&table=t0&order=f0&direction=desc", renderTableCallback);
    }

    function sendFormCallback(status, textStatus, jqXHR) {
      if (status == 0 ) {
        $("#debug").html("Sending unsuccessful");
        return;
      }

      renderTable();

    }


    function sendForm() {
      var url = "http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui/salvesta.py?table=t0";
      url += "&salvestaja=" + $("#salvestaja").val();
      url += "&f0=" + $("#todoname").val();
      url += "&f1=" + $("#tododesc").val();
      
      /*$("#debug").html(url);*/
      $.getJSON(url, sendFormCallback);
      return false;
    }


    function sendEditForm() {
      var url = "http://dijkstra.cs.ttu.ee/~irve/cgi-bin/ui/uuenda.py?table=t0";
      url += "&salvestaja=" + $("#esalvestaja").val();
      url += "&f0=" + $("#etodoname").val();
      url += "&f1=" + $("#etododesc").val();
      url += "&id=" + $("#editid").val();
      
      $("#debug").html(url);
      $.getJSON(url, sendFormCallback); /* note shared function */
      return false;
    }




    $(document).ready( function() {

      renderTable();
      
    });


  </script>


  <form onsubmit="return sendForm();">
    <p>Insert item</p>
    <input id="id" type="hidden" value=""/><br />
    <input id="salvestaja" type="text" value="test@example.ee" /><br />
    <input id="todoname" type="text" placeholder="Todo name" /><br />
    <input id="tododesc" type="text" placeholder="Description" /><br />
    <input id="send" type="submit" value="Save"/><br />


  </form>

  <form onsubmit="return sendEditForm();">
    <p>Edit item</p>
    <input id="editid" type="hidden" value=""/><br />
    <input id="esalvestaja" type="text" value="test@example.ee" /><br />
    <input id="etodoname" type="text" placeholder="Todo name" /><br />
    <input id="etododesc" type="text" placeholder="Description" /><br />
    <input id="esend" type="submit" value="Save"/><br />
  </form>

  <div id="debug">
  </div>
  
  <table id="todotable">

  </table>

  </body>
</html>