data stringification was not done, when object was not modified, and

passed as it is and that leads to error during fetching the modified
SQL.

Thanks Neel for the point out.
This commit is contained in:
Ashesh Vashi 2016-01-07 18:31:08 +05:30
parent fe05f2d0c6
commit a611f84aad
2 changed files with 18 additions and 17 deletions

View File

@ -725,7 +725,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) {
// Save the changes // Save the changes
btn.click(function() { btn.click(function() {
var m = view.model, var m = view.model,
d = m.toJSON(true, 0, 'POST'); d = m.toJSON(true);
if (d && !_.isEmpty(d)) { if (d && !_.isEmpty(d)) {
m.save({}, { m.save({}, {
attrs: d, attrs: d,
@ -1109,7 +1109,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) {
* 'changed': [JSON of each modified model with session changes] * 'changed': [JSON of each modified model with session changes]
* } * }
*/ */
toJSON: function(session, level) { toJSON: function(session) {
var self = this, var self = this,
session = (typeof(session) != "undefined" && session == true); session = (typeof(session) != "undefined" && session == true);
@ -1127,7 +1127,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) {
} }
res['changed'] = []; res['changed'] = [];
_.each(self.sessAttrs['changed'], function(o) { _.each(self.sessAttrs['changed'], function(o) {
res['changed'].push(o.toJSON(true, (level || 0) + 1)); res['changed'].push(o.toJSON(true));
}); });
if (res['changed'].length == 0) { if (res['changed'].length == 0) {
delete res['changed']; delete res['changed'];
@ -1429,13 +1429,9 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) {
* objects (collection, and model) will be return as stringified JSON, * objects (collection, and model) will be return as stringified JSON,
* only from the parent object. * only from the parent object.
*/ */
toJSON: function(session, level, method) { toJSON: function(session, method) {
var self = this, res, isNew = self.isNew(); var self = this, res, isNew = self.isNew();
// We will run JSON.stringify(..) only from the main object, not for
// the JSON object within the objects.
level = level || 0;
session = (typeof(session) != "undefined" && session == true); session = (typeof(session) != "undefined" && session == true);
if (!session || isNew) { if (!session || isNew) {
@ -1459,14 +1455,19 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) {
* transformed to JSON data. * transformed to JSON data.
*/ */
if (session) { if (session) {
if (obj && obj.sessChanged && obj.sessChanged()) { res[k] = obj && obj.toJSON(
res[k] = ((level== 0 && method && method == 'GET') ? !isNew && obj.sessChanged && obj.sessChanged()
// Convert the JSON data to string, which will allow us to );
// send the data to the server in GET HTTP method, and will /*
// not be translated to wierd format. * We will run JSON.stringify(..) only from the main object,
(obj && JSON.stringify(obj.toJSON(session && !isNew, level + 1))) : * not for the JSON object within the objects, that only when
(obj && obj.toJSON(session && !self.isNew(), level + 1)) * HTTP method is 'GET'.
); *
* We do stringify the object, so that - it will not be
* translated to wierd format using jQuery.
*/
if (obj && method && method == 'GET') {
res[k] = JSON.stringify(res[k]);
} }
} else { } else {
res[k] = (obj && obj.toJSON()); res[k] = (obj && obj.toJSON());

View File

@ -978,7 +978,7 @@
url: msql_url, url: msql_url,
type: 'GET', type: 'GET',
cache: false, cache: false,
data: self.model.toJSON(true, 0, 'GET'), data: self.model.toJSON(true, 'GET'),
dataType: "json", dataType: "json",
contentType: "application/json" contentType: "application/json"
}).done(function(res) { }).done(function(res) {