Permalink
Browse files

customer updates

  • Loading branch information...
jbass86 committed Dec 1, 2013
1 parent ef75569 commit 6cc26eb71ed485849b565f862379a559d4cdcfe8
View
1 app.js
@@ -125,6 +125,7 @@ app.configure('development', function(){
app.get('/', routes.index);
app.get('/users_by_last_name', user.users_by_last_name);
+app.post('/update_user', user.update_user);
//app.get('/inventory', routes.inventory);
http.createServer(app).listen(app.get('port'), function(){
@@ -13,7 +13,9 @@ define(["vendor/backbone",
Backbone.View.extend(
className: "customerSection",
- events: {"click .insertCustomerButton" : "insertCustomerEvent"},
+ events: {"click .insertCustomerButton" : "insertCustomerEvent", \
+ "click .customerTable .editButton" : "customerTableEdit", \
+ "click .customerTable .deleteButton" : "customerTableDelete"},
initialize: (model) ->
@@ -30,7 +32,7 @@ define(["vendor/backbone",
###
render: () ->
- @$el.html(Templates.customerSection());
+ @$el.html(Templates.customerSection({}));
elem = @customerUpdateView.render();
@$el.find(".contentDiv").append(elem);
@@ -49,27 +51,33 @@ define(["vendor/backbone",
@customerUpdateView.realized();
@populateTable();
+
+ window.setInterval(() =>
+ @populateTable();
+ 10000);
populateTable: () ->
$.get("users_by_last_name", {}, (data) =>
table = @$el.find(".customerTable table");
+ table.html("");
for row in data.rows
- table.append("<tr>" + \
- "<td>" + row.value.last_name + "</td>" + \
- "<td>" + row.value.first_name + "</td>" + \
- "<td>" + row.value.nick_name + "</td>" + \
- "<td>" + row.value.email + "</td>" + \
- "<td>" + row.value.country + "</td>" + \
- "<td>" + row.value.birthday + "</td>" + \
- "<td> <button>" + "Edit" + "</button> </td>" + \
- "<td> <button>" + "Delete" + "</button> </td>" + \
- "</tr>");
+ console.log("wowow");
+ table.append(Templates.customerRowTemplate(row.value));
);
- insertCustomerEvent: () ->
+ customerTableEdit: (event) ->
+ console.log("customer table edit");
+
+ customerTableDelete: (event) ->
+ console.log("customer table delete");
+
+ insertCustomerEvent: (event) ->
- @customerUpdateView.toggleHidden(true, true);
+ @customerUpdateView.toggleHidden(true, true);
+ window.setTimeout(() =>
+ @populateTable();
+ 2000);
)
)

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -11,9 +11,15 @@ define(["vendor/backbone",
Backbone.View.extend(
className: "customerUpdatePanel pressedborder box_shadow",
id: "draggable",
+
+ events: {"click .closeButton" : "closePanel", \
+ "click .cancelButton" : "closePanel", \
+ "click .updateButton" : "updateCustomer"},
+
initialize: (model) ->
+
###
Create the Dialog and return its element
@method render
@@ -28,24 +34,19 @@ define(["vendor/backbone",
toggleHidden: (overlayOn, animate) ->
if (!overlayOn)
-
if (animate)
-
@$el.fadeOut("slow");
-
else
-
@$el.css("display", "none");
else
-
if (animate)
-
-
@$el.fadeIn("slow");
-
else
@$el.css("display", "");
+ closePanel: () ->
+
+ @toggleHidden(false, true);
###
Called after Dialog has been appended, this will set up the prog search
@@ -59,5 +60,24 @@ define(["vendor/backbone",
console.log(@$el.find(".updateButton"));
@$el.find(".updateButton").button();
@$el.find(".cancelButton").button();
+
+ updateCustomer: () ->
+
+ console.log(@$el.find(".firstNameArea").val());
+ update = {first_name: @$el.find(".firstNameArea").val(), \
+ last_name: @$el.find(".lastNameArea").val(), \
+ nick_name: @$el.find(".nickNameArea").val(), \
+ email: @$el.find(".emailArea").val(), \
+ country: @$el.find(".countryArea").val(), \
+ birthday: @$el.find(".birthdayArea").val()}
+ console.log("update to send to server");
+ console.log(update);
+
+ $.post("update_user", update, (data) =>
+
+ console.log("updated user");
+ console.log(data);
+ );
+ @toggleHidden(false, true);
)
)

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -2,6 +2,41 @@
define(["vendor/handlebars"], function(Handlebars) {
return {
+"customerRowTemplate": Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
+ this.compilerInfo = [2,'>= 1.0.0-rc.3'];
+helpers = helpers || Handlebars.helpers; data = data || {};
+ var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression;
+
+
+ buffer += "<tr>\r\n <td>";
+ if (stack1 = helpers.last_name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.last_name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "</td>\r\n <td>";
+ if (stack1 = helpers.first_name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.first_name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "</td>\r\n <td>";
+ if (stack1 = helpers.nick_name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.nick_name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "</td>\r\n <td>";
+ if (stack1 = helpers.email) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.email; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "</td>\r\n <td>";
+ if (stack1 = helpers.country) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.country; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "</td>\r\n <td>";
+ if (stack1 = helpers.birthday) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0.birthday; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "</td>\r\n <td> <button class=\"editButton\"> Edit </button> </td>\r\n <td> <button class=\"deleteButton\"> Delete </button> </td>\r\n</tr>";
+ return buffer;
+ }
+
+),
"customerSection": Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
@@ -0,0 +1,10 @@
+<tr>
+ <td>{{last_name}}</td>
+ <td>{{first_name}}</td>
+ <td>{{nick_name}}</td>
+ <td>{{email}}</td>
+ <td>{{country}}</td>
+ <td>{{birthday}}</td>
+ <td> <button class="editButton"> Edit </button> </td>
+ <td> <button class="deleteButton"> Delete </button> </td>
+</tr>
View
@@ -9,22 +9,38 @@ exports.users_by_last_name = function(req, res){
var nano = require('nano')('http://localhost:5984');
nano.db.get('users', function() {
- var users = nano.use('users');
+ var users = nano.use('users');
+
+ users.view('get_users', 'sort_by_last_name', function(err, body){
+
+ console.log("got something out of users");
+ console.log(body);
+ console.log(req.query.add)
+ //console.log(req);
+ if (body){
+ console.log(body.name);
+ }
+ res.send(body);
+ });
+ });
+};
- users.view('get_users', 'sort_by_last_name', function(err, body){
+exports.update_user = function(req, res){
+ //res.send("respond with a resource");
- console.log("got something out of users");
- console.log(body);
- console.log(req.query.add)
- //console.log(req);
- if (body){
-
- console.log(body.name);
- }
- res.send(body);
+ var nano = require('nano')('http://localhost:5984');
+ nano.db.get('users', function() {
- });
+ var users = nano.use('users');
-});
+ if (!req.body.id){
+
+ users.insert(req.body, req.body.id, function(err, body, header){
+ if (err){
+ console.log("There was an error updating the user");
+ }
+ });
+ }
+ });
};

0 comments on commit 6cc26eb

Please sign in to comment.