// Using a REST demo API "Job management"
// - Use the HTTP methods PUT, POST, DELETE, GET for specifying the operation
// - item id as part of URL makes URL a representation of a server side item
// - "Accept:application/json" header field: requests JSON for data transport
// - Additionally shows how to use cross domain requests
// The "global players" :
var jobs, server, // Model parts (client and stub for server)
controller, // Controller
events, // A tiny event registration service
table, inputArea, msg // View parts
;
// --- A representation of the job data on client side
jobs = {
JOBS:{},
get:function(id) {
return id ? this.JOBS[id] : this.JOBS;
},
getLength:function(jobData) {
var length = 0;
$.each( jobData || this.JOBS, function() { length++ } );
return length;
},
getFirstID:function(jobData) {
for (var id in (jobData || this.JOBS)) {
return id;
}
},
update: function(jobData) {
var self = this, update = false;
$.each( jobData, function(id,job) {
if (id) self.JOBS[id] = job;
update = true;
});
if (update) events.raise( "update", jobData );
},
replace:function(jobData) {
this.JOBS = jobData;
events.raise("replace", jobData);
},
deleteSingle:function(id) {
delete this.JOBS[id];
events.raise( "deleteSingle", id );
},
fields: {
REPID: "Report",
VARID: "Variant",
PRIO: "Prio",
RESTART: "Restart",
DESCR: "Description",
CONTACT: "Contact"
}
};
// --- The area containing the input fields
inputArea = {
fillFromJob:function(id,job) {
$.each( jobs.fields, function(name) {
if (name == "RESTART")
$("#RESTART").prop("checked",job.RESTART == "X");
else
$("#"+name).val( job[name] );
});
$("#ID").val(id);
},
fillVariants:function(variants,selected) {
var...
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.