emerald-rails 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -102,16 +102,25 @@ Emerald.Controller.extend = function(actions){
102
102
 
103
103
  instance.persistView = true;
104
104
 
105
- instance.persistViewCallback = function(JSON, observerObject) {
105
+ // Persistence callbacks
106
+ instance.afterAjaxResponseSuccessCallback = function(responseText, observerObject) {
106
107
  if (!observerObject)
107
108
  observerObject = Emerald.Model.Observer;
108
109
 
109
110
  if (this.persistView)
110
- observerObject.update(JSON);
111
+ observerObject.update(responseText);
111
112
 
112
113
  return true;
113
114
  }
114
115
 
116
+ instance.failedAjaxResponseCallback = function(responseText) {
117
+ // TODO implement
118
+ if (typeof observerObject == 'undefined' || !observerObject)
119
+ observerObject = Emerald.Model.Observer;
120
+
121
+ observerObject.update(responseText);
122
+ }
123
+
115
124
  return instance;
116
125
  }
117
126
 
@@ -140,12 +149,21 @@ Emerald.Model.extend = function(properties) {
140
149
  return null;
141
150
  }
142
151
 
143
- instance.save = function(data, andCallbackController, persistenceObject) {
152
+ instance.update = function(domElements){
153
+ for (i = 0; i < domElements.length; i++) {
154
+ var element = domElements[i];
155
+ this[element.name] = element.value;
156
+ }
157
+
158
+ return this;
159
+ }
160
+
161
+ instance.save = function(andCallbackController, persistenceObject) {
144
162
  if (!persistenceObject)
145
163
  persistenceObject = Emerald.Persistence;
146
164
 
147
165
  // TODO verify that `data` fields are the ones listed in this.attrAccessible
148
- return new persistenceObject(this).save(data, andCallbackController);
166
+ return new persistenceObject(this).save(andCallbackController);
149
167
  }
150
168
 
151
169
  return instance;
@@ -247,8 +265,10 @@ Emerald.Persistence = function(model, persistenceObject) {
247
265
  if (!persistenceObject)
248
266
  persistenceObject = Emerald.Persistence;
249
267
 
250
- instance.save = function(model, callbackController){
251
- return persistenceObject.save(model, callbackController);
268
+ instance.model = model;
269
+
270
+ instance.save = function(callbackController){
271
+ return persistenceObject.save(instance.model, callbackController);
252
272
  }
253
273
 
254
274
  return instance;
@@ -271,12 +291,12 @@ Emerald.Persistence.save = function(model, callbackController) {
271
291
  var _controller = controller;
272
292
  var requestSpecs = Emerald.Persistence.saveRequest(model);
273
293
 
274
- $.ajax(requestSpecs).done(function(jsonResponse) {
294
+ $.ajax(requestSpecs).done(function(response) {
275
295
  if (_controller)
276
- _controller.persistViewCallback(jsonResponse);
277
- }).fail(function(jsonResponse) {
296
+ _controller.afterAjaxResponseSuccessCallback(response);
297
+ }).fail(function(response) {
278
298
  if (_controller)
279
- _controller.failedAjaxResponseCallback(jsonResponse);
299
+ _controller.failedAjaxResponseCallback($.parseJSON(response.responseText));
280
300
  });
281
301
 
282
302
  return requestSpecs;
@@ -1,3 +1,3 @@
1
1
  module EmeraldRails
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -102,16 +102,25 @@ Emerald.Controller.extend = function(actions){
102
102
 
103
103
  instance.persistView = true;
104
104
 
105
- instance.persistViewCallback = function(JSON, observerObject) {
105
+ // Persistence callbacks
106
+ instance.afterAjaxResponseSuccessCallback = function(responseText, observerObject) {
106
107
  if (!observerObject)
107
108
  observerObject = Emerald.Model.Observer;
108
109
 
109
110
  if (this.persistView)
110
- observerObject.update(JSON);
111
+ observerObject.update(responseText);
111
112
 
112
113
  return true;
113
114
  }
114
115
 
116
+ instance.failedAjaxResponseCallback = function(responseText) {
117
+ // TODO implement
118
+ if (typeof observerObject == 'undefined' || !observerObject)
119
+ observerObject = Emerald.Model.Observer;
120
+
121
+ observerObject.update(responseText);
122
+ }
123
+
115
124
  return instance;
116
125
  }
117
126
 
@@ -140,12 +149,21 @@ Emerald.Model.extend = function(properties) {
140
149
  return null;
141
150
  }
142
151
 
143
- instance.save = function(data, andCallbackController, persistenceObject) {
152
+ instance.update = function(domElements){
153
+ for (i = 0; i < domElements.length; i++) {
154
+ var element = domElements[i];
155
+ this[element.name] = element.value;
156
+ }
157
+
158
+ return this;
159
+ }
160
+
161
+ instance.save = function(andCallbackController, persistenceObject) {
144
162
  if (!persistenceObject)
145
163
  persistenceObject = Emerald.Persistence;
146
164
 
147
165
  // TODO verify that `data` fields are the ones listed in this.attrAccessible
148
- return new persistenceObject(this).save(data, andCallbackController);
166
+ return new persistenceObject(this).save(andCallbackController);
149
167
  }
150
168
 
151
169
  return instance;
@@ -247,8 +265,10 @@ Emerald.Persistence = function(model, persistenceObject) {
247
265
  if (!persistenceObject)
248
266
  persistenceObject = Emerald.Persistence;
249
267
 
250
- instance.save = function(model, callbackController){
251
- return persistenceObject.save(model, callbackController);
268
+ instance.model = model;
269
+
270
+ instance.save = function(callbackController){
271
+ return persistenceObject.save(instance.model, callbackController);
252
272
  }
253
273
 
254
274
  return instance;
@@ -271,12 +291,12 @@ Emerald.Persistence.save = function(model, callbackController) {
271
291
  var _controller = controller;
272
292
  var requestSpecs = Emerald.Persistence.saveRequest(model);
273
293
 
274
- $.ajax(requestSpecs).done(function(jsonResponse) {
294
+ $.ajax(requestSpecs).done(function(response) {
275
295
  if (_controller)
276
- _controller.persistViewCallback(jsonResponse);
277
- }).fail(function(jsonResponse) {
296
+ _controller.afterAjaxResponseSuccessCallback(response);
297
+ }).fail(function(response) {
278
298
  if (_controller)
279
- _controller.failedAjaxResponseCallback(jsonResponse);
299
+ _controller.failedAjaxResponseCallback($.parseJSON(response.responseText));
280
300
  });
281
301
 
282
302
  return requestSpecs;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emerald-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-24 00:00:00.000000000 Z
12
+ date: 2012-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -59,12 +59,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ segments:
63
+ - 0
64
+ hash: -2226190882378884785
62
65
  required_rubygems_version: !ruby/object:Gem::Requirement
63
66
  none: false
64
67
  requirements:
65
68
  - - ! '>='
66
69
  - !ruby/object:Gem::Version
67
70
  version: '0'
71
+ segments:
72
+ - 0
73
+ hash: -2226190882378884785
68
74
  requirements: []
69
75
  rubyforge_project:
70
76
  rubygems_version: 1.8.23