/*
Just a rough idea about how we can format our javascript going forward with the rest api and dust templates, we can use backbone.js and other client side library, however that comes with many things than we may not require at this moment. This i believe will separate, rendering logic with api calling and will also force to keep the restful url and return codes "restfull".
we can obviously make it better, but i just rough it in so we get an idea.
*/
// basemodel.js file.
var ModelPrototype = function(){
this.initialize=function(){
$("#result").append("<p> calling initialize for "+this.name+"</p>");
}
this.setBaseUrl=function(){
$("#result").append("<p>setting Base Url "+this.name+"</p>");
}
this.url=""
// set this object after model intialize from server.
// url can be passed if we want to override the base url
this.save=function(data,success,error,url){
// do a put request, format url based on base url
}
this.insert=function(data,success,error,url){
// do a post request,format url based on base url
}
this.delete=function(success,error,url){
// do delete request,format url based on base url
}
this.get=function(success,error,url){
// do a get call
$("#result").append("<p>Doing get call "+this.name+"</p>");
var randomValue = Math.random() < 0.5 ? true : false;
if(randomValue === true){
success();
} else {
error();
}
}
// may be holds last returned json object form the ajax call
this.returnedObject=null;
};
// this can be extended as required
var Model = function(name){
this.name=name;
};
Model.prototype = new ModelPrototype();
var ioModel = new Model("IOModel");
var otherModel = new Model("Other");
ioModel.setBaseUrl();
ioModel.initialize();
otherModel.setBaseUrl();
otherModel.initialize();
var ViewPrototype = function(){
// idea...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.