Last active
June 21, 2016 20:38
-
-
Save georgesunil81/8c8bda615c327f2bf6efde0d1dfc0aac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//jobs model (Jobs.js) | |
define(['can/model/model'], function() { | |
var jobs = can.Model.extend({ | |
findAll: function(params, success, error) { | |
return can.ajax({ | |
type: 'GET', | |
url: '/job/All?' + params.queryString, | |
}) | |
.then(success, error); | |
} | |
}, { | |
define: { | |
_Status: { | |
get: function() { | |
//alert("gets in get for status!"); | |
switch(this.attr('status')) { | |
case 1: return 'Unassigned'; | |
case 2: return 'Assigned'; | |
} | |
} | |
}, | |
activeJobs: { | |
//the findAll function above will return both active and inactive job records. I want only the active ones to be returned as a response from findAll/ | |
//this function should cause jobs.findAll to return only active jobs based on the following code (pseudocode) - | |
//if status on the current record = 'Active' and job_date on the current record >= today's date, then include it in the response. | |
} | |
} | |
}); | |
return jobs; | |
}); | |
//Jobs controller | |
define([ | |
"jquery", | |
"can", | |
"app/models/Jobs" //Jobs model called here | |
], function($, can, jobs) { | |
return can.Control.extend({ | |
init: function(el, options) { | |
var self = this; | |
var scope = this.scope = new (can.Map.extend({}))(); | |
queryString = "&jobStatus=1&pageIndex=1&pageSize=10&sortBy=1&sortOrder=desc"; | |
jobs.findAll({ queryString: queryString }) | |
.done(function(response) { //response here should only contain active job records. | |
if (response.isSuccessful) { | |
if (response.data.length !== 0) { | |
scope.attr('jobslist', response); //jobslist should only contain active job records. | |
} | |
} else { | |
alert("No date returned!"); | |
} | |
}) | |
.fail(function(response) { //alert( "fail / error" ); //Technical errors! | |
alert("technical error"); | |
}); | |
el.html(can.view("app/pages/landingpage/LandingpageView", scope)); | |
} | |
}); | |
}); | |
//LandingpageView.stache | |
{{#each jobslist}} | |
<p>{{jobid}}</p> | |
<p>{{jobname}}</p> | |
<p>{{_Status}}</p> | |
{{/each}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment