Skip to content
Browse files

customer updates

  • Loading branch information...
1 parent ef75569 commit 6cc26eb71ed485849b565f862379a559d4cdcfe8 @jbass86 committed
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(){
View
36 public/javascripts/plugins/CustomerSection/view/CustomerSectionView.coffee
@@ -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);
)
)
View
30 public/javascripts/plugins/CustomerSection/view/CustomerSectionView.js
@@ -8,7 +8,9 @@ define(["vendor/backbone", "plugins/CustomerSection/model/CustomerUpdatePanelMod
return Backbone.View.extend({
className: "customerSection",
events: {
- "click .insertCustomerButton": "insertCustomerEvent"
+ "click .insertCustomerButton": "insertCustomerEvent",
+ "click .customerTable .editButton": "customerTableEdit",
+ "click .customerTable .deleteButton": "customerTableDelete"
},
initialize: function(model) {
console.log("I am the customer section!!!");
@@ -24,7 +26,7 @@ define(["vendor/backbone", "plugins/CustomerSection/model/CustomerUpdatePanelMod
render: function() {
var elem;
- this.$el.html(Templates.customerSection());
+ this.$el.html(Templates.customerSection({}));
elem = this.customerUpdateView.render();
this.$el.find(".contentDiv").append(elem);
elem.draggable();
@@ -39,25 +41,41 @@ define(["vendor/backbone", "plugins/CustomerSection/model/CustomerUpdatePanelMod
*/
realized: function() {
+ var _this = this;
this.customerUpdateView.realized();
- return this.populateTable();
+ this.populateTable();
+ return window.setInterval(function() {
+ return _this.populateTable();
+ }, 10000);
},
populateTable: function() {
var _this = this;
return $.get("users_by_last_name", {}, function(data) {
var row, table, _i, _len, _ref, _results;
table = _this.$el.find(".customerTable table");
+ table.html("");
_ref = data.rows;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
row = _ref[_i];
- _results.push(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");
+ _results.push(table.append(Templates.customerRowTemplate(row.value)));
}
return _results;
});
},
- insertCustomerEvent: function() {
- return this.customerUpdateView.toggleHidden(true, true);
+ customerTableEdit: function(event) {
+ return console.log("customer table edit");
+ },
+ customerTableDelete: function(event) {
+ return console.log("customer table delete");
+ },
+ insertCustomerEvent: function(event) {
+ var _this = this;
+ this.customerUpdateView.toggleHidden(true, true);
+ return window.setTimeout(function() {
+ return _this.populateTable();
+ }, 2000);
}
});
});
View
36 public/javascripts/plugins/CustomerSection/view/CustomerUpdatePanelView.coffee
@@ -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);
)
)
View
28 public/javascripts/plugins/CustomerSection/view/CustomerUpdatePanelView.js
@@ -8,6 +8,11 @@ define(["vendor/backbone", "plugins/CustomerSection/view/Templates", "css!plugin
return Backbone.View.extend({
className: "customerUpdatePanel pressedborder box_shadow",
id: "draggable",
+ events: {
+ "click .closeButton": "closePanel",
+ "click .cancelButton": "closePanel",
+ "click .updateButton": "updateCustomer"
+ },
initialize: function(model) {},
/*
Create the Dialog and return its element
@@ -34,6 +39,9 @@ define(["vendor/backbone", "plugins/CustomerSection/view/Templates", "css!plugin
}
}
},
+ closePanel: function() {
+ return this.toggleHidden(false, true);
+ },
/*
Called after Dialog has been appended, this will set up the prog search
list with all known searches
@@ -45,6 +53,26 @@ define(["vendor/backbone", "plugins/CustomerSection/view/Templates", "css!plugin
console.log(this.$el.find(".updateButton"));
this.$el.find(".updateButton").button();
return this.$el.find(".cancelButton").button();
+ },
+ updateCustomer: function() {
+ var update,
+ _this = this;
+ console.log(this.$el.find(".firstNameArea").val());
+ update = {
+ first_name: this.$el.find(".firstNameArea").val(),
+ last_name: this.$el.find(".lastNameArea").val(),
+ nick_name: this.$el.find(".nickNameArea").val(),
+ email: this.$el.find(".emailArea").val(),
+ country: this.$el.find(".countryArea").val(),
+ birthday: this.$el.find(".birthdayArea").val()
+ };
+ console.log("update to send to server");
+ console.log(update);
+ $.post("update_user", update, function(data) {
+ console.log("updated user");
+ return console.log(data);
+ });
+ return this.toggleHidden(false, true);
}
});
});
View
35 public/javascripts/plugins/CustomerSection/view/Templates.js
@@ -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 || {};
View
10 public/javascripts/plugins/CustomerSection/view/res/templates/customerRowTemplate.html
@@ -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
42 routes/user.js
@@ -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.
Something went wrong with that request. Please try again.