From 4e7e1aae85afede78f2e4fb18ae562e8095f8b60 Mon Sep 17 00:00:00 2001
From: Nicolas
Date: Wed, 17 Aug 2011 20:19:58 +0200
Subject: [PATCH 01/21] colloection select and include_blank option to
select_tag
---
view/helpers/helpers.js | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/view/helpers/helpers.js b/view/helpers/helpers.js
index 75b3f91b..50b8fd5f 100644
--- a/view/helpers/helpers.js
+++ b/view/helpers/helpers.js
@@ -1,4 +1,4 @@
-steal('jquery/view/ejs').then(function($){
+steal.plugins('jquery/view/ejs').then(function($){
/**
* @add jQuery.EJS.Helpers.prototype
@@ -214,11 +214,28 @@ $.extend($.EJS.Helpers.prototype, {
html_options.id = html_options.id || name;
//html_options.value = value;
html_options.name = name;
+ if (html_options.hasOwnProperty('include_blank')){
+ choices.unshift({text: (html_options.include_blank || ''), value: ''});
+ delete html_options['include_blank'];
+ }
var txt = '';
txt += this.start_tag_for('select', html_options);
- for(var i = 0; i < choices.length; i++)
+ var prevGroupOn = null;
+
+ if (choices[0] && choices[0].hasOwnProperty('groupOn')){
+ txt += this.start_tag_for('optgroup', {label: choices[0].groupLabel});
+ prevGroupOn = choices[0].groupOn
+ }
+ for(var i = 0; i < choices.length; i++)
{
- var choice = choices[i];
+ var choice = choices[i];
+
+ if(choice.hasOwnProperty('groupOn') && choice.groupOn != prevGroupOn){
+ txt += this.tag_end('optgroup');
+ txt += this.start_tag_for('optgroup', {label: choice.groupLabel});
+ prevGroupOn = choice.groupOn
+ }
+
if(typeof choice == 'string') choice = {value: choice};
if(!choice.text) choice.text = choice.value;
if(!choice.value) choice.text = choice.text;
@@ -317,8 +334,8 @@ $.extend($.EJS.Helpers.prototype, {
options = options || {};
options.src = steal.root.join("resources/images/"+image_location);
return this.single_tag_for('img', options);
- }
-
+ },
+
});
$.EJS.Helpers.prototype.text_tag = $.EJS.Helpers.prototype.text_area_tag;
From 5ffcae76ab7db2ac43c7cc31931f0b71feda93f2 Mon Sep 17 00:00:00 2001
From: Nicolas
Date: Thu, 18 Aug 2011 00:21:36 +0200
Subject: [PATCH 02/21] added collection select and include blank options to
select_tag
---
view/helpers/helpers.js | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/view/helpers/helpers.js b/view/helpers/helpers.js
index f12e01f1..d1fe07b3 100644
--- a/view/helpers/helpers.js
+++ b/view/helpers/helpers.js
@@ -214,11 +214,28 @@ $.extend($.EJS.Helpers.prototype, {
html_options.id = html_options.id || name;
//html_options.value = value;
html_options.name = name;
+ if (html_options.hasOwnProperty('include_blank')){
+ choices.unshift({text: ((html_options.include_blank == true ) ? '' : html_options.include_blank), value: ''});
+ delete html_options['include_blank'];
+ }
var txt = '';
txt += this.start_tag_for('select', html_options);
- for(var i = 0; i < choices.length; i++)
+ var prevGroupOn = null;
+
+ if (choices[0] && choices[0].hasOwnProperty('groupOn')){
+ txt += this.start_tag_for('optgroup', {label: choices[0].groupLabel});
+ prevGroupOn = choices[0].groupOn
+ }
+ for(var i = 0; i < choices.length; i++)
{
- var choice = choices[i];
+ var choice = choices[i];
+
+ if(choice.hasOwnProperty('groupOn') && choice.groupOn != prevGroupOn){
+ txt += this.tag_end('optgroup');
+ txt += this.start_tag_for('optgroup', {label: choice.groupLabel});
+ prevGroupOn = choice.groupOn
+ }
+
if(typeof choice == 'string') choice = {value: choice};
if(!choice.text) choice.text = choice.value;
if(!choice.value) choice.text = choice.text;
@@ -317,8 +334,8 @@ $.extend($.EJS.Helpers.prototype, {
options = options || {};
options.src = steal.root.join("resources/images/"+image_location);
return this.single_tag_for('img', options);
- }
-
+ },
+
});
$.EJS.Helpers.prototype.text_tag = $.EJS.Helpers.prototype.text_area_tag;
From 1975c57b36bfd751f8a4054cce3ffe6f55fa5ddf Mon Sep 17 00:00:00 2001
From: Nicolas
Date: Thu, 25 Aug 2011 20:42:56 +0200
Subject: [PATCH 03/21] refresh global list on model and prevent duplications
---
model/model.js | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/model/model.js b/model/model.js
index 0ff9e715..2afb6b69 100644
--- a/model/model.js
+++ b/model/model.js
@@ -761,12 +761,18 @@ steal.plugins('jquery/class', 'jquery/lang').then(function() {
if (!attributes ) {
return null;
}
- return new this(
+
+ var instance = new this(
// checks for properties in an object (like rails 2.0 gives);
isObject(attributes[this._shortName]) ||
isObject(attributes.data) ||
isObject(attributes.attributes) ||
attributes);
+ if (this.list && instance[this.id]){
+ this.list.remove(instance)
+ this.list.push(instance)
+ }
+ return instance
},
/**
* @function wrapMany
@@ -1294,17 +1300,17 @@ steal.plugins('jquery/class', 'jquery/lang').then(function() {
}
- //if this class has a global list, add / remove from the list.
- if ( property === Class.id && val !== null && Class.list ) {
- // if we didn't have an old id, add ourselves
- if (!old ) {
- Class.list.push(this);
- } else if ( old != val ) {
- // if our id has changed ... well this should be ok
- Class.list.remove(old);
- Class.list.push(this);
- }
- }
+// //if this class has a global list, add / remove from the list.
+// if ( property === Class.id && val !== null && Class.list ) {
+// // if we didn't have an old id, add ourselves
+// if (!old ) {
+// Class.list.push(this);
+// } else if ( old != val ) {
+// // if our id has changed ... well this should be ok
+// Class.list.remove(old);
+// Class.list.push(this);
+// }
+// }
},
/**
From 55e77c676786b2e0beb66e52f964215f16e2e6fe Mon Sep 17 00:00:00 2001
From: Nicolas
Date: Wed, 24 Aug 2011 01:16:54 +0200
Subject: [PATCH 04/21] new steal stuff
---
view/helpers/helpers.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/view/helpers/helpers.js b/view/helpers/helpers.js
index 50b8fd5f..98384f9a 100644
--- a/view/helpers/helpers.js
+++ b/view/helpers/helpers.js
@@ -1,4 +1,4 @@
-steal.plugins('jquery/view/ejs').then(function($){
+steal('jquery/view/ejs').then(function($){
/**
* @add jQuery.EJS.Helpers.prototype
From 8c4be41f0c69d201a840e0aa19e649186d37d7ac Mon Sep 17 00:00:00 2001
From: Nicolas
Date: Thu, 1 Sep 2011 11:04:11 +0200
Subject: [PATCH 05/21] custom serialization for back end requests
---
model/model.js | 49 ++++++++++++++++++++--------------
model/qunit.html | 2 +-
model/test/qunit/model_test.js | 17 ++++++++++++
3 files changed, 47 insertions(+), 21 deletions(-)
diff --git a/model/model.js b/model/model.js
index 34d2a3a0..9db1c1fd 100644
--- a/model/model.js
+++ b/model/model.js
@@ -91,7 +91,7 @@ steal('jquery/class', 'jquery/lang').then(function() {
reject = function(data){
deferred.rejectWith(self, [data])
},
- args = [self.serialize(), resolve, reject];
+ args = [self.serialize(true), resolve, reject];
if(type == 'destroy'){
args.shift();
@@ -1033,7 +1033,8 @@ steal('jquery/class', 'jquery/lang').then(function() {
}
},
bind: bind,
- unbind: unbind
+ unbind: unbind,
+ backendSerialize: {}
},
/**
* @Prototype
@@ -1383,25 +1384,33 @@ steal('jquery/class', 'jquery/lang').then(function() {
}
return attributes;
},
- serialize : function(){
- var Class = this.Class,
- attrs = Class.attributes,
- type,
- converter,
- data = {},
- attr;
+ serialize : function(backend){
+ var Class = this.Class,
+ attrs = Class.attributes,
+ type,
+ converter,
+ data = {},
+ attr,
+ instruction;
- attributes = {};
-
- for ( attr in attrs ) {
- if ( attrs.hasOwnProperty(attr) ) {
- type = attrs[attr];
- converter = Class.serialize[type] || Class.serialize['default'];
- data[attr] = converter( this[attr] , type );
- }
- }
- return data;
- },
+ attributes = {};
+
+ for ( attr in attrs ) {
+ if ( attrs.hasOwnProperty(attr) ) {
+ type = attrs[attr];
+ converter = Class.serialize[type] || Class.serialize['default'];
+ if (backend && Class.backendSerialize.hasOwnProperty(attr)){
+ instruction = Class.backendSerialize[attr]
+ if (instruction != false || (instruction['if'] && instruction['if'].call(this, this[attr]))){
+ data[instruction['key'] || attr] = converter( this[attr] , type );
+ }
+ } else {
+ data[attr] = converter( this[attr] , type );
+ }
+ }
+ }
+ return data;
+ },
/**
* Returns if the instance is a new object. This is essentially if the
* id is null or undefined.
diff --git a/model/qunit.html b/model/qunit.html
index abca295f..218735de 100644
--- a/model/qunit.html
+++ b/model/qunit.html
@@ -12,6 +12,6 @@
associations
list
-
+