Skip to content

Instantly share code, notes, and snippets.

@marzetas
Created November 28, 2012 15:42
Show Gist options
  • Save marzetas/4162058 to your computer and use it in GitHub Desktop.
Save marzetas/4162058 to your computer and use it in GitHub Desktop.
Review diff
diff --git a/dev/backend/www/webapp/webapp/public/javascript/account/view_taskgroup.js b/dev/backend/www/webapp/webapp/public/javascript/account/view_taskgroup.js
index 356c1c419b1d7727ccabebd1da6b4e78c1b2352f..87f8d81518242a62f1e9172ff0c3423799352d36 100644
--- a/dev/backend/www/webapp/webapp/public/javascript/account/view_taskgroup.js
+++ b/dev/backend/www/webapp/webapp/public/javascript/account/view_taskgroup.js
@@ -12,7 +12,6 @@ dojo.require("dojox.mvc");
dojo.require("dojox.mvc.Group");
dojo.require("dojox.mvc.Repeat");
dojo.require("dojox.mvc.Output");
-dojo.require("dojox.mvc.StatefulModel");
dojo.require("dojox.string.sprintf");
dojo.require("FA.data_stores");
dojo.require("FA.i18n");
@@ -24,7 +23,9 @@ dojo.require("FA.taskgroups.referrer");
dojo.require("FA.taskgroups.templates");
dojo.require("FA.taskgroups.actions");
dojo.require("FA.label_functions");
-dojo.require("FA.mvc.DaliOutput");
+dojo.require("FA.mvc.18.FARequest");
+dojo.require("FA.mvc.18.DaliOutput");
+dojo.require("FA.utils.helpers");
dojo.require("dojo.Stateful");
dojo.addOnLoad( function(){
@@ -35,15 +36,17 @@ dojo.addOnLoad( function(){
FA.view_taskgroup.load = function() {
var taskgroup_node = dojo.byId("taskgroup");
var taskgroup_key;
+ var request = FARequest();
- dojo.xhrGet({
- url: "/account/tasks/groups/taskgroup_json",
- content: {
- key: dojo.attr(taskgroup_node, "data-fa-taskgroup-uuid"),
- cloned_key: dojo.attr(taskgroup_node, "data-fa-cloned-taskgroup-uuid")
- },
- handleAs: "json",
- load: function(data) {
+ dojo.when(
+ request.get({
+ url: "/account/tasks/groups/taskgroup_json",
+ data: {
+ key: dojo.attr(taskgroup_node, "data-fa-taskgroup-uuid"),
+ cloned_key: dojo.attr(taskgroup_node, "data-fa-cloned-taskgroup-uuid")
+ }
+ }),
+ function(data){
FA.view_taskgroup.model = FA.view_taskgroup.create_model(data);
FA.view_taskgroup.listener_init(FA.view_taskgroup.model);
@@ -56,13 +59,9 @@ FA.view_taskgroup.load = function() {
},
"#taskgroup",
FA.view_taskgroup.load_tasks
- );
- },
- error: function(err) {
- /* this will execute if the response couldn't be converted to a JS object,
- or if the request was unsuccessful altogether. */
+ );
}
- });
+ );
}; // end
FA.view_taskgroup.load_tasks = function() {
@@ -82,7 +81,7 @@ FA.view_taskgroup.tasks_did_load = function() {
FA.taskgroups.events.bind();
FA.taskgroups.actions.setupProductDataStores();
- if (!FA.view_taskgroup.model.meta.is_new.value) {
+ if (!FA.view_taskgroup.model.meta.is_new) {
//Disable save button on existing taskgroups
FA.view_taskgroup.update_save_button(false,"Saved");
}
@@ -108,7 +107,7 @@ FA.view_taskgroup.can_perform = function(post_save_action) {
};
FA.view_taskgroup.data_to_save = function() {
- var taskgroup = FA.view_taskgroup.model.toPlainObject();
+ var taskgroup = FA.view_taskgroup.model;
taskgroup.tasks = FA.view_taskgroup.tasks;
// Removing the stuff we don't want to store for the tasks
@@ -142,7 +141,6 @@ FA.view_taskgroup.post_save_action = {
};
FA.view_taskgroup.save = function(action) {
-
if (!FA.view_taskgroup.can_perform(action)){
return;
}
@@ -151,27 +149,26 @@ FA.view_taskgroup.save = function(action) {
}
if (action === FA.view_taskgroup.post_save_action.none){
- FA.view_taskgroup.update_save_button(false,"Saving…");
+ FA.view_taskgroup.update_save_button(false,"Saving...");
}
- var xhrArgs = {
+ var request = new FARequest();
+ dojo.when(
+ request.post({
url: "." + (action === FA.view_taskgroup.post_save_action.clone ? "?action="+action : ''),
- headers: {"Content-Type": "application/json", "Accept":"application/json"},
- postData: FA.view_taskgroup.data_to_save(),
- handleAs: "json",
- load: function(data) {
- if (data.success) {
- FA.taskgroups.referrer.redirect(data.redirect);
- } else {
- FA.view_taskgroup.update_save_button(true,"Try Again");
- flash_runner();
- }
- },
- error: function(error){
+ data: FA.view_taskgroup.data_to_save()
+ }),
+ function(data){
+ if (data.success) {
+ FA.taskgroups.referrer.redirect(data.redirect);
+ } else {
FA.view_taskgroup.update_save_button(true,"Try Again");
+ flash_runner();
}
- };
- var deferred = dojo.xhrPost(xhrArgs);
+ },
+ function(error){
+ FA.view_taskgroup.update_save_button(true,"Try Again");
+ });
};
var FA_save_orig_text;
@@ -191,39 +188,53 @@ FA.view_taskgroup.update_save_button = function(enabled, newtext) {
};
FA.view_taskgroup.create_model = function(data) {
- taskgroup = dojo.clone(data);
-
- taskgroup.meta = {};
- taskgroup.meta.is_new = !taskgroup.uuid;
+ var meta;
+ meta = {};
+ meta.is_new = !data.uuid;
+ data.meta = meta;
- return new dojox.mvc.StatefulModel({ data : taskgroup });
+ return dojox.mvc.getStateful(data);
};
FA.view_taskgroup.taskgroup_delete = function(values) {
- var xhrArgs = {
- url: "/account/tasks/groups/" + values.key,
- handleAs: "json",
- load: function(data) {
- if (data.success) {
- FA.taskgroups.referrer.redirect();
- }
- },
- error: function(error){
- console.error("Cannot delete task group with parameters: ", error);
- }
- };
+ var request = new FARequest();
- var deferred = dojo.xhrDelete(xhrArgs);
+ dojo.when(
+ request.del({
+ url: "/account/tasks/groups/" + values.key
+ }),
+ function(data){
+ if (data.success) {
+ FA.taskgroups.referrer.redirect();
+ }
+ },
+ function(error){
+ console.error("Cannot delete task group with parameters: ", error);
+ }
+ );
}; // end asset_delete
FA.view_taskgroup.listener_init = function(model) {
- if (!model.meta.is_new.value) {
- model.deepwatch("value", function(name, oldValue, newValue){
- if (oldValue == newValue) return;
- FA.view_taskgroup.update_save_button(true);
- });
+ var deepWatch = function(_model){
+ if(_model && typeof _model === "object" && FA.utils.helpers.isStatefulModel(_model)){
+ _model.watch(
+ function(name, oldValue, newValue){
+ if(oldValue === newValue) return;
+ FA.view_taskgroup.update_save_button(true);
+ }
+ );
+ for(var prop in _model){
+ if(_model.hasOwnProperty(prop) && prop !="_watchCallbacks" && typeof _model[prop] === "object" ){
+ deepWatch(_model[prop]);
+ }
+ }
+ }
+ };
+
+ if (!model.meta.get("is_new")){
+ deepWatch(model);
}
-};
+}; // end listener_init
FA.view_taskgroup.sanitize_task_quantities = function(){
for(var i=0; i < FA.view_taskgroup.tasks.length; i++){
@@ -239,24 +250,8 @@ FA.view_taskgroup.sanitize_task_quantities = function(){
}
}
}
-};
+}; // end sanitize_task_quantities
-/*
-Extend dojo.Stateful to support deep watching
-*/
-dojo.extend(dojo.Stateful,{
- listeners: [],
- deepwatch: function(name, callback) {
- this.listeners.push(
- this.watch(name, callback)
- );
- for (var i in this) {
- if (this.hasOwnProperty(i) && !!this[i] && this[i].deepwatch) {
- this.listeners.concat(
- this[i].deepwatch(name, callback)
- );
- }
- }
- return this.listeners;
- }
-});
+FA.view_taskgroup.format_name = function(){
+ return Mustache.to_html("{{name}}", {name: FA.view_taskgroup.model.name});
+};
diff --git a/dev/backend/www/webapp/webapp/templates/account/taskgroup/show.mustache b/dev/backend/www/webapp/webapp/templates/account/taskgroup/show.mustache
index 74b7903d2b56c3b3a3f8b93bbd4843b1106d5de7..e8d100fc8e3b193aff8c074b9ed96ca59a27c08b 100644
--- a/dev/backend/www/webapp/webapp/templates/account/taskgroup/show.mustache
+++ b/dev/backend/www/webapp/webapp/templates/account/taskgroup/show.mustache
@@ -5,15 +5,15 @@
Main Task Group Template
-->
-
+<script type="dojo/require">at: "dojox/mvc/at"</script>
<script type="text/template" class="template" data-template="task_group">
- <div data-dojo-type="dojox.mvc.Group" data-dojo-props='ref: "FA.view_taskgroup.model"'>
- <form data-dojo-type='dijit.form.Form' id="taskgroupform">
+ <form data-dojo-type='dijit/form/Form' id="taskgroupform">
+ <div data-dojo-type="dojox/mvc/Group" data-dojo-props='target: FA.view_taskgroup.model'>
<div id="title_wrapper">
<h1>
<span class="notice"></span>
- <span data-dojo-type="FA.mvc.DaliOutput" data-dojo-props='ref: "name", conditionals: {new: FA.view_taskgroup.model.meta.is_new.value}'>
- [[#new]]New [[/new]]{{entity_title}} [[.]]
+ <span data-dojo-type="FA/mvc/18/DaliOutput" data-dojo-props="value: at('rel:', 'name'), formatters: {name: FA.view_taskgroup.format_name}, conditionals: {new: FA.view_taskgroup.model.meta.is_new}">
+ [[#new]]New [[/new]]{{entity_title}} [[#name]][[.]][[/name]]
</span>
</h1>
</div>
@@ -22,10 +22,10 @@ Main Task Group Template
<label for="name" class="required"><span class="required-tag">*</span>Task Group Name:</label>
<input id="name"
data-dojo-type='dijit.form.ValidationTextBox'
- data-dojo-props='ref:"name",
+ data-dojo-props="value: at('rel:', 'name'),
required: true,
trim: true,
- invalidMessage:"You need a name for the task group"'
+ invalidMessage: 'You need a name for the task group'"
/>
</div>
@@ -36,24 +36,24 @@ Main Task Group Template
<select placeholder="Type Task Name"
data-dojo-type='dijit.form.FilteringSelect'
data-dojo-props='value:"",
- placeHolder:"Type Task Name",
+ placeHolder: "Type Task Name",
labelFunc: FA.label_functions.tasks_and_task_groups,
- labelType:"html",
+ labelType: "html",
required: false,
- name:"add_task_name",
- id:"add_task_name",
- store:FA.data_stores.tasks_only,
- onChange:FA.taskgroups.events.task_changed,
- searchAttr:"name_and_description",
+ name: "add_task_name",
+ id: "add_task_name",
+ store: FA.data_stores.tasks_only,
+ onChange: FA.taskgroups.events.task_changed,
+ searchAttr: "name_and_description",
autoComplete: false,
- maxHeight:265,
- queryExpr:"*${0}*"'></select>
+ maxHeight: 265,
+ queryExpr: "*${0}*"'></select>
<a href="#" id="add_task_button">Add Task To Group</a>
</fieldset>
</div>
- </form>
- </div>
+ </div>
+ </form>
</script>
<!--
@@ -98,7 +98,7 @@ Tasks Table Body
data-dojo-props='placeHolder:"Cost",
name:"cost",
value:"[%cost%]",
- required:false,
+ required:false,
onChange: FA.taskgroups.events.task_cost_changed'>
</td>
@@ -119,24 +119,24 @@ Tasks Table Body
<select id="product_select_[%position%]"
placeholder="Type Product Name"
data-dojo-type='dijit.form.FilteringSelect'
- data-dojo-props='value:"",
- placeHolder:"Type Product Name",
+ data-dojo-props='value: "",
+ placeHolder: "Type Product Name",
required: false,
searchAttr: "product_name",
- maxHeight:265,
- labelFunc:FA.label_functions.products,
- labelType:"html",
+ maxHeight: 265,
+ labelFunc: FA.label_functions.products,
+ labelType: "html",
onChange: FA.taskgroups.events.task_product_changed'></select>
<label>Quantity</label>
<input id="product_qty_[%position%]"
placeholder="Quantity"
data-dojo-type='dijit.form.NumberSpinner'
- data-dojo-props='smallDelta:"1",
- placeHolder:"Quantity",
- name:"quantity",
- intermediateChanges:true,
- constraints:{min:0,max:1000000}'>
+ data-dojo-props='smallDelta: "1",
+ placeHolder: "Quantity",
+ name: "quantity",
+ intermediateChanges: true,
+ constraints: {min:0,max:1000000}'>
<a href="#" id="addupdate_product_button_[%position%]" class="addupdate_product_button disabled">Add</span>
<a href="#" id="remove_product_button_[%position%]" class="remove_product_button disabled">Remove</span>
@@ -154,8 +154,8 @@ Tasks Table Body
<fieldset>
<textarea data-dojo-type='dijit.form.Textarea'
data-dojo-props="onChange: FA.taskgroups.events.task_note_changed,
- placeHolder:'Add a note',
- trim:true,
+ placeHolder: 'Add a note',
+ trim: true,
value: '[%#dojo-props%][%note%][%/dojo-props%]',
required: false"></textarea>
</fieldset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment