Skip to content

Commit

Permalink
bug fix in the client api wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
luiseduardobrito committed Sep 25, 2013
1 parent f4f1aed commit 427bdb5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 28 deletions.
3 changes: 1 addition & 2 deletions api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ module.exports = {

response(res).json({
result: "error",
message: e.message.toString(),
code: 500
message: e.message.toString()
})

return;
Expand Down
4 changes: 3 additions & 1 deletion api/models/user_model.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var lang = require("../../language");

module.exports = {

name: {
Expand Down Expand Up @@ -33,7 +35,7 @@ module.exports = {

// sample validation
if(number.length < 8)
throw new Error("The credit card should be at least 8 characters long");
throw new Error(lang.user.invalid_card || "The credit card should be at least 8 characters long");

return true;
}
Expand Down
81 changes: 58 additions & 23 deletions client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,42 +381,77 @@
data = this._data || {};
var __this = this;

$.get(connection_url + this._uri, data, function(data) {
$.ajax({

if(!data) {
type: 'GET',
url: connection_url + this._uri,
data: data,

var cb = __this._methods["error"] ||
success: function(data){

cb();
}
var response = data;

var response = toString.call(data) == toString.call("str") ?
JSON.parse(data) : data;
if(!data.result || data.result != "success") {

if(!response) {
var cb = __this._methods["error"];
cb(data);
return;
}

var cb = __this._methods["error"] || function(){};
cb(response);
}
else {

else if(response.result
&& response.result == "success") {
var cb = __this._methods["success"];
cb(data);
return;
}
},

var cb = __this._methods["success"] || function(){};
cb(response);
error: function(data){
var cb = __this._methods["error"];
cb(data);
}

else if(response.result
&& response.result == "error") {
});

var cb = __this._methods["error"] || function(){};
cb(response);
}
return this;
};

_this.prototype.post = function() {

var connection_url = "http://" + config.api.host;
connection_url += ":" + config.api.port + "/api/";

else {
data = this._data || {};
var __this = this;

$.ajax({

type: 'POST',
url: connection_url + this._uri,
data: data,

success: function(data){

var response = data;

if(!data.result || data.result != "success") {

var cb = __this._methods["error"];
cb(data);
return;
}

else {

var cb = __this._methods["success"];
cb(data);
return;
}
},

var cb = __this._methods["error"] || function(){};
cb(response);
error: function(data){
var cb = __this._methods["error"];
cb(data);
}

});
Expand Down
4 changes: 3 additions & 1 deletion language/pt-BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ module.exports = {
logout_success: "Logout efetuado com sucesso",
logout_error: "O logout não pode ser efetuado",

forbidden_access: "Acesso restrito, vocẽ não tem permissões administrativas"
forbidden_access: "Acesso restrito, vocẽ não tem permissões administrativas",

invalid_card: "The credit card should be at least 8 characters long"
}
}
2 changes: 1 addition & 1 deletion views/home/signup.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>

<span style="color: red; display: none" data-subscribe="user/signup/error" data-action="$('#signup-error').html(data.message); $(this).hide().fadeIn('slow')">
Error: <span id="signup-error">unknown error</span>
<span id="signup-error">Unknown error</span>
</span>

<form data-module="user" data-method="signup">
Expand Down

0 comments on commit 427bdb5

Please sign in to comment.