Click here to Skip to main content
15,893,663 members
Articles / Web Development / HTML5

Developing Web 2.0 User Interface for Self Hosted WCF Services using HTML5, CSS3 and JQuery

Rate me:
Please Sign up or sign in to vote.
4.08/5 (8 votes)
24 Jul 2011MIT5 min read 70.1K   684   26  
Devloping Web 2.0 user interface for self hosted WCF services using HTML5, CSS3 and JQuery
function StatesPage () {
  this.loadStatesPage = function (data) {
    content = undefined;
    $.each (data, function (index, value) {
      if (data[index]["id"]=="content") {
        content = data[index].innerHTML;
        $("#content")[0].innerHTML = content;
        $("#b_update")[0].onclick = updateStates;
        loadStatesTable();
      }
    });
    if (content == undefined) {alert("Failed to load page: Content missing"); return;} 
  }

  var loadStatesTable = function () {
    getdata('/states','json', function (data, textStatus, xhr) {
      var statesTable = $('#content table')[0];
      $.each(data.states, function (i,s) {

       var visitedControl = $('<input></input>')
            .attr('type','checkbox')
            .attr('checked',s.visited=="1")
       visitedControl[0]['modified'] = false;
       visitedControl[0].onclick = function () { this.modified = !this.modified; }
        
        $('<tr></tr>')
        .append($('<td>'+s.state+'</td>'))
        .append($('<td>'+s.capital+'</td>'))
        .append($('<td></td>').append(visitedControl))
        .appendTo(statesTable);

      });
    });
  }

  var updateStates = function () {
    var statesTable = $('#content table')[0];
    $.each(statesTable.rows, function (i,r) {
      if (i==0) {
        return true;
      }
      var checkBox = r.cells[2].children[0];
      if (checkBox.modified)  {
        $.ajax({ type: 'POST', 
          url:'/state',
          data:JSON.stringify({"id":i,"visited": checkBox.checked}), 
          beforeSend:function(xhr, settings){
            xhr.setRequestHeader("Authorization", auth.getToken());
            xhr.setRequestHeader("Content-Type",'application/json');
          },
          success: function(data, textStatus, xhr) {   
                   },
          error: function(xhr,error) {
                   if(xhr.status==401) {
                     auth.loadLoginPage();
                   }
                 }          
        });
      }
    });
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions