Skip to content
Browse files

added a bunch of customer functionality

  • Loading branch information...
1 parent 6cc26eb commit 9553fd3fd32199f5f871375d12d9440241d80d95 @jbass86 committed
Showing with 524 additions and 175 deletions.
  1. +3 −93 app.js
  2. +22 −0 public/javascripts/plugins/CustomerSection/model/CustomerDeleteDialogModel.coffee
  3. +20 −0 public/javascripts/plugins/CustomerSection/model/CustomerDeleteDialogModel.js
  4. +1 −0 public/javascripts/plugins/CustomerSection/model/CustomerUpdatePanelModel.coffee
  5. +3 −1 public/javascripts/plugins/CustomerSection/model/CustomerUpdatePanelModel.js
  6. +62 −0 public/javascripts/plugins/CustomerSection/view/CustomerDeleteDialogView.coffee
  7. +57 −0 public/javascripts/plugins/CustomerSection/view/CustomerDeleteDialogView.js
  8. +54 −9 public/javascripts/plugins/CustomerSection/view/CustomerSectionView.coffee
  9. +59 −16 public/javascripts/plugins/CustomerSection/view/CustomerSectionView.js
  10. +42 −12 public/javascripts/plugins/CustomerSection/view/CustomerUpdatePanelView.coffee
  11. +46 −14 public/javascripts/plugins/CustomerSection/view/CustomerUpdatePanelView.js
  12. +52 −2 public/javascripts/plugins/CustomerSection/view/Templates.js
  13. +15 −0 public/javascripts/plugins/CustomerSection/view/res/css/customerDeleteDialog.css
  14. +5 −0 public/javascripts/plugins/CustomerSection/view/res/css/customerSection.css
  15. +3 −2 public/javascripts/plugins/CustomerSection/view/res/css/customerUpdatePanel.css
  16. +10 −0 public/javascripts/plugins/CustomerSection/view/res/templates/customerDeleteDialog.html
  17. +17 −2 public/javascripts/plugins/CustomerSection/view/res/templates/customerRowTemplate.html
  18. +12 −9 public/javascripts/plugins/CustomerSection/view/res/templates/customerSection.html
  19. +41 −15 routes/user.js
View
96 app.js
@@ -13,98 +13,6 @@ var express = require('express')
var nano = require('nano')('http://localhost:5984');
-nano.db.get('users', function(){
-
-
-
- var users = nano.use('users');
-
- users.insert ( { name: 'kankamol', country: 'thailand'}, 'kate', function(err, body, header) {
- if (err){
- console.log("there was an error");
- }
- console.log("we inserted");
- console.log(body);
- });
-
-
-
- console.log(users)
-
- users.list(function(err, body){
-
- console.log("seach users");
- console.log(err);
- console.log(body);
-
- body.rows.forEach(function(row){
-
- console.log(row.value)
-
- });
-
-
- })
-
- users.view('get_users', 'sort_by_last_name', function(err, body){
-
- console.log("i called view");
- console.log("key: " + body.key);
- console.log("value: " + body.value);
- console.log(body.rows);
- console.log("******")
- })
-
-});
-
-// nano.db.get('inventory', function() {
-
-// var inventory = nano.use('inventory');
-// inventory.insert ( { name: 'kankamol', country: 'thailand'}, 'kate', function(err, body, header) {
-// if (err){
-// console.log("there was an error");
-// }
-// console.log("we inserted");
-// console.log(body);
-// });
-
- // inventory.insert ( { name: 'josh', country: 'usa'}, 'josh', function(err, body, header) {
- // if (err){
- // console.log("there was an error");
- // console.log(err)
- // }
- // console.log("we inserted");
- // console.log(body);
- // });
-
- // inventory.get('josh', function(err, body, header){
-
- // console.log("got something out of inventory");
- // console.log(body.name);
-
- // });
-
-// });
-
-// // clean up the database we created previously
-// nano.db.destroy('alice', function() {
-// // create a new database
-// nano.db.create('alice', function() {
-// // specify the database we are going to use
-// var alice = nano.use('alice');
-// // and insert a document in it
-// alice.insert({ crazy: true }, 'rabbit', function(err, body, header) {
-// if (err) {
-// console.log('[alice.insert] ', err.message);
-// return;
-// }
-// console.log('you have inserted the rabbit.')
-// console.log(body);
-// });
-// });
-// });
-
-
var app = express();
app.configure(function(){
@@ -125,8 +33,10 @@ 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);
+app.post('/delete_user', user.delete_user);
+app.post('/test_post', user.test_post);
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
View
22 public/javascripts/plugins/CustomerSection/model/CustomerDeleteDialogModel.coffee
@@ -0,0 +1,22 @@
+###*
+* @author Josh Bass
+*###
+
+define(["vendor/backbone"]
+
+(Backbone, Math2) ->
+
+ customerDeleteDialogModel = Backbone.Model.extend(
+
+
+ ###*
+ * initialize a new model, will automatically initialize a new
+ * search
+ * @method initialize
+ *
+ *###
+ initialize: (options) ->
+
+ );
+
+);
View
20 public/javascripts/plugins/CustomerSection/model/CustomerDeleteDialogModel.js
@@ -0,0 +1,20 @@
+// Generated by CoffeeScript 1.3.3
+/**
+* @author Josh Bass
+*
+*/
+
+define(["vendor/backbone"], function(Backbone, Math2) {
+ var customerDeleteDialogModel;
+ return customerDeleteDialogModel = Backbone.Model.extend({
+ /**
+ * initialize a new model, will automatically initialize a new
+ * search
+ * @method initialize
+ *
+ *
+ */
+
+ initialize: function(options) {}
+ });
+});
View
1 public/javascripts/plugins/CustomerSection/model/CustomerUpdatePanelModel.coffee
@@ -16,6 +16,7 @@ define(["vendor/backbone"]
*
*###
initialize: (options) ->
+ @set("customerViewModel", options.customerViewModel);
);
View
4 public/javascripts/plugins/CustomerSection/model/CustomerUpdatePanelModel.js
@@ -15,6 +15,8 @@ define(["vendor/backbone"], function(Backbone, Math2) {
*
*/
- initialize: function(options) {}
+ initialize: function(options) {
+ return this.set("customerViewModel", options.customerViewModel);
+ }
});
});
View
62 public/javascripts/plugins/CustomerSection/view/CustomerDeleteDialogView.coffee
@@ -0,0 +1,62 @@
+###
+CustomerSectionBarView
+@author Josh Bass
+###
+define(["vendor/backbone",
+ "plugins/CustomerSection/view/Templates",
+ 'css!plugins/CustomerSection/view/res/css/customerDeleteDialog.css'],
+
+(Backbone, Templates, CSS) ->
+
+ Backbone.View.extend(
+
+ className: "customerDeleteDialog",
+
+ events: {"click .dialogYes" : "confirm", \
+ "click .dialogNo" : "cancel"},
+
+
+ initialize: (model) ->
+
+
+ ###
+ Create the Dialog and return its element
+ @method render
+ ###
+ render: () ->
+ @$el.html(Templates.customerDeleteDialog({}));
+ return @$el
+
+ ###
+ Called after Dialog has been appended, this will set up the prog search
+ list with all known searches
+ @method realized
+ ###
+ realized: () ->
+ @$el.css("display", "none");
+ @$el.find(".dialogYes").button();
+ @$el.find(".dialogNo").button();
+
+
+ confirmDelete: (deleteAction) ->
+
+ @$el.dialog({title: "Customer Delete Confirm", \
+ close: () =>
+ console.log("I was closed...");
+ if (@model.get("actionConfirmed"))
+ console.log("I Was confirmed!! :)");
+ deleteAction();
+
+ @model.set("actionConfirmed", false);
+ });
+
+ confirm: () ->
+
+ @model.set("actionConfirmed", true);
+ @$el.dialog("close");
+
+ cancel: () ->
+ @$el.dialog("close");
+
+ )
+)
View
57 public/javascripts/plugins/CustomerSection/view/CustomerDeleteDialogView.js
@@ -0,0 +1,57 @@
+// Generated by CoffeeScript 1.3.3
+/*
+CustomerSectionBarView
+@author Josh Bass
+*/
+
+define(["vendor/backbone", "plugins/CustomerSection/view/Templates", 'css!plugins/CustomerSection/view/res/css/customerDeleteDialog.css'], function(Backbone, Templates, CSS) {
+ return Backbone.View.extend({
+ className: "customerDeleteDialog",
+ events: {
+ "click .dialogYes": "confirm",
+ "click .dialogNo": "cancel"
+ },
+ initialize: function(model) {},
+ /*
+ Create the Dialog and return its element
+ @method render
+ */
+
+ render: function() {
+ this.$el.html(Templates.customerDeleteDialog({}));
+ return this.$el;
+ },
+ /*
+ Called after Dialog has been appended, this will set up the prog search
+ list with all known searches
+ @method realized
+ */
+
+ realized: function() {
+ this.$el.css("display", "none");
+ this.$el.find(".dialogYes").button();
+ return this.$el.find(".dialogNo").button();
+ },
+ confirmDelete: function(deleteAction) {
+ var _this = this;
+ return this.$el.dialog({
+ title: "Customer Delete Confirm",
+ close: function() {
+ console.log("I was closed...");
+ if (_this.model.get("actionConfirmed")) {
+ console.log("I Was confirmed!! :)");
+ deleteAction();
+ }
+ return _this.model.set("actionConfirmed", false);
+ }
+ });
+ },
+ confirm: function() {
+ this.model.set("actionConfirmed", true);
+ return this.$el.dialog("close");
+ },
+ cancel: function() {
+ return this.$el.dialog("close");
+ }
+ });
+});
View
63 public/javascripts/plugins/CustomerSection/view/CustomerSectionView.coffee
@@ -5,12 +5,16 @@ CustomerSectionBarView
define(["vendor/backbone",
"plugins/CustomerSection/model/CustomerUpdatePanelModel",
"plugins/CustomerSection/view/CustomerUpdatePanelView",
+ "plugins/CustomerSection/model/CustomerDeleteDialogModel",
+ "plugins/CustomerSection/view/CustomerDeleteDialogView",
"plugins/CustomerSection/view/Templates",
'css!plugins/CustomerSection/view/res/css/customerSection.css'],
-(Backbone, CustomerUpdatePanelModel, CustomerUpdatePanelView, Templates, CSS) ->
+(Backbone, CustomerUpdatePanelModel, CustomerUpdatePanelView,
+ CustomerDeleteDialogModel, CustomerDeleteDialogView, Templates, CSS) ->
Backbone.View.extend(
+
className: "customerSection",
events: {"click .insertCustomerButton" : "insertCustomerEvent", \
@@ -22,9 +26,17 @@ define(["vendor/backbone",
console.log("I am the customer section!!!")
- @customerUpdateModel = new CustomerUpdatePanelModel();
+ @customerUpdateModel = new CustomerUpdatePanelModel({customerViewModel: @model});
@customerUpdateView = new CustomerUpdatePanelView({model: @customerUpdateModel});
+ @customerDeleteDialogModel = new CustomerDeleteDialogModel();
+ @customerDeleteDialogView = new CustomerDeleteDialogView({model: @customerDeleteDialogModel});
+
+ @model.on("change:customerEvent", ()=>
+ window.setTimeout(() =>
+ @populateTable();
+ 5000);
+ );
###
Create the Dialog and return its element
@@ -40,6 +52,9 @@ define(["vendor/backbone",
elem.css("position", "absolute");
@customerUpdateView.toggleHidden(false);
+ elem = @customerDeleteDialogView.render();
+ @$el.find(".contentDiv").append(elem);
+
return @$el
###
@@ -49,35 +64,65 @@ define(["vendor/backbone",
###
realized: () ->
+ @$el.find(".customerInsertPanel .insertCustomerButton").button();
@customerUpdateView.realized();
+ @customerDeleteDialogView.realized();
+
@populateTable();
window.setInterval(() =>
@populateTable();
- 10000);
+ 20000);
populateTable: () ->
$.get("users_by_last_name", {}, (data) =>
table = @$el.find(".customerTable table");
+ header = @$el.find(".customerTable table tr")[0];
table.html("");
- for row in data.rows
- console.log("wowow");
- table.append(Templates.customerRowTemplate(row.value));
+ table.append(header);
+ for row in data.rows
+ table.append(Templates.customerRowTemplate(row.value));
+
+ @$el.find(".customerTable table button").button();
);
customerTableEdit: (event) ->
console.log("customer table edit");
+ dataset = $(event.currentTarget)[0].dataset;
+ @customerUpdateModel.set("first_name", dataset.first_name);
+ @customerUpdateModel.set("last_name", dataset.last_name);
+ @customerUpdateModel.set("nick_name", dataset.nick_name);
+ @customerUpdateModel.set("email", dataset.email);
+ @customerUpdateModel.set("country", dataset.country);
+ @customerUpdateModel.set("birthday", dataset.birthday);
+ @customerUpdateModel.set("couchid", dataset.couchid);
+ @customerUpdateModel.set("couchrev", dataset.couchrev);
+ @customerUpdateView.toggleHidden(true, true);
customerTableDelete: (event) ->
console.log("customer table delete");
+ deleteAction = () =>
+ dataset = $(event.currentTarget)[0].dataset;
+ $.post("delete_user", {_id: dataset.couchid, _rev: dataset.couchrev});
+ @model.trigger("change:customerEvent");
+
+ @customerDeleteDialogView.confirmDelete(deleteAction);
+
+
+
insertCustomerEvent: (event) ->
+ @customerUpdateModel.set("first_name", "");
+ @customerUpdateModel.set("last_name", "");
+ @customerUpdateModel.set("nick_name", "");
+ @customerUpdateModel.set("email", "");
+ @customerUpdateModel.set("country", "");
+ @customerUpdateModel.set("birthday", "");
+ @customerUpdateModel.set("couchid", "");
+ @customerUpdateModel.set("couchrev", "");
@customerUpdateView.toggleHidden(true, true);
- window.setTimeout(() =>
- @populateTable();
- 2000);
)
)
View
75 public/javascripts/plugins/CustomerSection/view/CustomerSectionView.js
@@ -4,7 +4,7 @@ CustomerSectionBarView
@author Josh Bass
*/
-define(["vendor/backbone", "plugins/CustomerSection/model/CustomerUpdatePanelModel", "plugins/CustomerSection/view/CustomerUpdatePanelView", "plugins/CustomerSection/view/Templates", 'css!plugins/CustomerSection/view/res/css/customerSection.css'], function(Backbone, CustomerUpdatePanelModel, CustomerUpdatePanelView, Templates, CSS) {
+define(["vendor/backbone", "plugins/CustomerSection/model/CustomerUpdatePanelModel", "plugins/CustomerSection/view/CustomerUpdatePanelView", "plugins/CustomerSection/model/CustomerDeleteDialogModel", "plugins/CustomerSection/view/CustomerDeleteDialogView", "plugins/CustomerSection/view/Templates", 'css!plugins/CustomerSection/view/res/css/customerSection.css'], function(Backbone, CustomerUpdatePanelModel, CustomerUpdatePanelView, CustomerDeleteDialogModel, CustomerDeleteDialogView, Templates, CSS) {
return Backbone.View.extend({
className: "customerSection",
events: {
@@ -13,11 +13,23 @@ define(["vendor/backbone", "plugins/CustomerSection/model/CustomerUpdatePanelMod
"click .customerTable .deleteButton": "customerTableDelete"
},
initialize: function(model) {
+ var _this = this;
console.log("I am the customer section!!!");
- this.customerUpdateModel = new CustomerUpdatePanelModel();
- return this.customerUpdateView = new CustomerUpdatePanelView({
+ this.customerUpdateModel = new CustomerUpdatePanelModel({
+ customerViewModel: this.model
+ });
+ this.customerUpdateView = new CustomerUpdatePanelView({
model: this.customerUpdateModel
});
+ this.customerDeleteDialogModel = new CustomerDeleteDialogModel();
+ this.customerDeleteDialogView = new CustomerDeleteDialogView({
+ model: this.customerDeleteDialogModel
+ });
+ return this.model.on("change:customerEvent", function() {
+ return window.setTimeout(function() {
+ return _this.populateTable();
+ }, 5000);
+ });
},
/*
Create the Dialog and return its element
@@ -32,6 +44,8 @@ define(["vendor/backbone", "plugins/CustomerSection/model/CustomerUpdatePanelMod
elem.draggable();
elem.css("position", "absolute");
this.customerUpdateView.toggleHidden(false);
+ elem = this.customerDeleteDialogView.render();
+ this.$el.find(".contentDiv").append(elem);
return this.$el;
},
/*
@@ -42,40 +56,69 @@ define(["vendor/backbone", "plugins/CustomerSection/model/CustomerUpdatePanelMod
realized: function() {
var _this = this;
+ this.$el.find(".customerInsertPanel .insertCustomerButton").button();
this.customerUpdateView.realized();
+ this.customerDeleteDialogView.realized();
this.populateTable();
return window.setInterval(function() {
return _this.populateTable();
- }, 10000);
+ }, 20000);
},
populateTable: function() {
var _this = this;
return $.get("users_by_last_name", {}, function(data) {
- var row, table, _i, _len, _ref, _results;
+ var header, row, table, _i, _len, _ref;
table = _this.$el.find(".customerTable table");
+ header = _this.$el.find(".customerTable table tr")[0];
table.html("");
+ table.append(header);
_ref = data.rows;
- _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
row = _ref[_i];
- console.log("wowow");
- _results.push(table.append(Templates.customerRowTemplate(row.value)));
+ table.append(Templates.customerRowTemplate(row.value));
}
- return _results;
+ return _this.$el.find(".customerTable table button").button();
});
},
customerTableEdit: function(event) {
- return console.log("customer table edit");
+ var dataset;
+ console.log("customer table edit");
+ dataset = $(event.currentTarget)[0].dataset;
+ this.customerUpdateModel.set("first_name", dataset.first_name);
+ this.customerUpdateModel.set("last_name", dataset.last_name);
+ this.customerUpdateModel.set("nick_name", dataset.nick_name);
+ this.customerUpdateModel.set("email", dataset.email);
+ this.customerUpdateModel.set("country", dataset.country);
+ this.customerUpdateModel.set("birthday", dataset.birthday);
+ this.customerUpdateModel.set("couchid", dataset.couchid);
+ this.customerUpdateModel.set("couchrev", dataset.couchrev);
+ return this.customerUpdateView.toggleHidden(true, true);
},
customerTableDelete: function(event) {
- return console.log("customer table delete");
+ var deleteAction,
+ _this = this;
+ console.log("customer table delete");
+ deleteAction = function() {
+ var dataset;
+ dataset = $(event.currentTarget)[0].dataset;
+ $.post("delete_user", {
+ _id: dataset.couchid,
+ _rev: dataset.couchrev
+ });
+ return _this.model.trigger("change:customerEvent");
+ };
+ return this.customerDeleteDialogView.confirmDelete(deleteAction);
},
insertCustomerEvent: function(event) {
- var _this = this;
- this.customerUpdateView.toggleHidden(true, true);
- return window.setTimeout(function() {
- return _this.populateTable();
- }, 2000);
+ this.customerUpdateModel.set("first_name", "");
+ this.customerUpdateModel.set("last_name", "");
+ this.customerUpdateModel.set("nick_name", "");
+ this.customerUpdateModel.set("email", "");
+ this.customerUpdateModel.set("country", "");
+ this.customerUpdateModel.set("birthday", "");
+ this.customerUpdateModel.set("couchid", "");
+ this.customerUpdateModel.set("couchrev", "");
+ return this.customerUpdateView.toggleHidden(true, true);
}
});
});
View
54 public/javascripts/plugins/CustomerSection/view/CustomerUpdatePanelView.coffee
@@ -19,6 +19,24 @@ define(["vendor/backbone",
initialize: (model) ->
+ @model.on("change:first_name", () =>
+ @$el.find(".firstNameArea").val(@model.get("first_name"));
+ );
+ @model.on("change:last_name", () =>
+ @$el.find(".lastNameArea").val(@model.get("last_name"));
+ );
+ @model.on("change:nick_name", () =>
+ @$el.find(".nickNameArea").val(@model.get("nick_name"));
+ );
+ @model.on("change:email", () =>
+ @$el.find(".emailArea").val(@model.get("email"));
+ );
+ @model.on("change:country", () =>
+ @$el.find(".countryArea").val(@model.get("country"));
+ );
+ @model.on("change:birthday", () =>
+ @$el.find(".birthdayArea").val(@model.get("birthday"));
+ );
###
Create the Dialog and return its element
@@ -47,6 +65,22 @@ define(["vendor/backbone",
closePanel: () ->
@toggleHidden(false, true);
+ @model.set("first_name", "");
+ @model.trigger("change:first_name", "");
+ @model.set("last_name", "");
+ @model.trigger("change:last_name", "");
+ @model.set("nick_name", "");
+ @model.trigger("change:nick_name", "");
+ @model.set("email", "");
+ @model.trigger("change:email", "");
+ @model.set("country", "");
+ @model.trigger("change:country", "");
+ @model.set("birthday", "");
+ @model.trigger("change:birthday", "");
+ @model.set("couchid", "");
+ @model.trigger("change:couchid", "");
+ @model.set("couchrev", "");
+ @model.trigger("change:couchrev", "");
###
Called after Dialog has been appended, this will set up the prog search
@@ -57,27 +91,23 @@ define(["vendor/backbone",
@$el.find(".birthdayArea").datepicker();
- 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);
+ birthday: @$el.find(".birthdayArea").val(), \
+ _id: @model.get("couchid"), \
+ _rev: @model.get("couchrev")}
+
+ console.log("############################### I am inserting");
+ $.post("update_user", update);
+ @closePanel();
+ @model.get("customerViewModel").trigger("change:customerEvent");
)
)
View
60 public/javascripts/plugins/CustomerSection/view/CustomerUpdatePanelView.js
@@ -13,7 +13,27 @@ define(["vendor/backbone", "plugins/CustomerSection/view/Templates", "css!plugin
"click .cancelButton": "closePanel",
"click .updateButton": "updateCustomer"
},
- initialize: function(model) {},
+ initialize: function(model) {
+ var _this = this;
+ this.model.on("change:first_name", function() {
+ return _this.$el.find(".firstNameArea").val(_this.model.get("first_name"));
+ });
+ this.model.on("change:last_name", function() {
+ return _this.$el.find(".lastNameArea").val(_this.model.get("last_name"));
+ });
+ this.model.on("change:nick_name", function() {
+ return _this.$el.find(".nickNameArea").val(_this.model.get("nick_name"));
+ });
+ this.model.on("change:email", function() {
+ return _this.$el.find(".emailArea").val(_this.model.get("email"));
+ });
+ this.model.on("change:country", function() {
+ return _this.$el.find(".countryArea").val(_this.model.get("country"));
+ });
+ return this.model.on("change:birthday", function() {
+ return _this.$el.find(".birthdayArea").val(_this.model.get("birthday"));
+ });
+ },
/*
Create the Dialog and return its element
@method render
@@ -40,7 +60,23 @@ define(["vendor/backbone", "plugins/CustomerSection/view/Templates", "css!plugin
}
},
closePanel: function() {
- return this.toggleHidden(false, true);
+ this.toggleHidden(false, true);
+ this.model.set("first_name", "");
+ this.model.trigger("change:first_name", "");
+ this.model.set("last_name", "");
+ this.model.trigger("change:last_name", "");
+ this.model.set("nick_name", "");
+ this.model.trigger("change:nick_name", "");
+ this.model.set("email", "");
+ this.model.trigger("change:email", "");
+ this.model.set("country", "");
+ this.model.trigger("change:country", "");
+ this.model.set("birthday", "");
+ this.model.trigger("change:birthday", "");
+ this.model.set("couchid", "");
+ this.model.trigger("change:couchid", "");
+ this.model.set("couchrev", "");
+ return this.model.trigger("change:couchrev", "");
},
/*
Called after Dialog has been appended, this will set up the prog search
@@ -50,29 +86,25 @@ define(["vendor/backbone", "plugins/CustomerSection/view/Templates", "css!plugin
realized: function() {
this.$el.find(".birthdayArea").datepicker();
- 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());
+ var update;
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()
+ birthday: this.$el.find(".birthdayArea").val(),
+ _id: this.model.get("couchid"),
+ _rev: this.model.get("couchrev")
};
- 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);
+ console.log("############################### I am inserting");
+ $.post("update_user", update);
+ this.closePanel();
+ return this.model.get("customerViewModel").trigger("change:customerEvent");
}
});
});
View
54 public/javascripts/plugins/CustomerSection/view/Templates.js
@@ -2,6 +2,16 @@
define(["vendor/handlebars"], function(Handlebars) {
return {
+"customerDeleteDialog": Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
+ this.compilerInfo = [2,'>= 1.0.0-rc.3'];
+helpers = helpers || Handlebars.helpers; data = data || {};
+
+
+
+ return "<span>Do you wish to confirm this action?</span>\r\n\r\n<div class=\"buttonPanel\">\r\n <button id=\"button\" class=\"ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only dialogYes\" role=\"button\" aria-disabled=\"false\">\r\n Yes\r\n </button>\r\n <button id=\"button\" class=\"ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only dialogNo\" role=\"button\" aria-disabled=\"false\">\r\n No\r\n </button>\r\n</div>";
+ }
+
+),
"customerRowTemplate": Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
@@ -32,7 +42,47 @@ helpers = helpers || Handlebars.helpers; data = data || {};
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>";
+ + "</td>\r\n \r\n <td> <button class=\"editButton pressedBorder\" data-couchid=\"";
+ if (stack1 = helpers._id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0._id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "\"\r\n data-couchrev=\"";
+ if (stack1 = helpers._rev) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0._rev; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "\" \r\n data-first_name=\"";
+ 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)
+ + "\" data-last_name=\"";
+ 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)
+ + "\"\r\n data-nick_name=\"";
+ 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)
+ + "\" data-email=\"";
+ 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)
+ + "\"\r\n data-country=\"";
+ 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)
+ + "\" data-birthday=\"";
+ 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)
+ + "\"> \r\n \r\n <span class=\"ui-icon ui-icon-wrench\"></span>\r\n </button> \r\n </td>\r\n \r\n <td> \r\n <button class=\"deleteButton pressedBorder\" data-couchid=\"";
+ if (stack1 = helpers._id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0._id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "\"\r\n data-couchrev=\"";
+ if (stack1 = helpers._rev) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
+ else { stack1 = depth0._rev; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
+ buffer += escapeExpression(stack1)
+ + "\"> \r\n <span class=\"ui-icon ui-icon-closethick\"></span> \r\n </button> \r\n </td>\r\n</tr>";
return buffer;
}
@@ -43,7 +93,7 @@ helpers = helpers || Handlebars.helpers; data = data || {};
- return "\r\n<div class=\"contentDiv\">\r\n <h2 class=\"customerSectionTitle\">Customer Section</h2>\r\n\r\n <div style=\"clear: both\"></div>\r\n\r\n <div class=\"customerInsertPanel\">\r\n <button class=\"insertCustomerButton\">Insert Customer</button>\r\n </div>\r\n\r\n <div style=\"clear: both\"></div>\r\n\r\n <div class=\"customerTable\">\r\n <table border=\"1\" class=\"pressedBorder\">\r\n <tr>\r\n <th>Last Name</th>\r\n <th>First Name</th>\r\n <th>NickName</th>\r\n <th>Email</th>\r\n <th>Country</th>\r\n <th>Birthday</th>\r\n </tr>\r\n </table>\r\n </div>\r\n</div>\r\n";
+ return "\r\n<div class=\"contentDiv\">\r\n <h2 class=\"customerSectionTitle\">Customer Section</h2>\r\n\r\n <div style=\"clear: both\"></div>\r\n\r\n <div class=\"customerInsertPanel\">\r\n <button id=\"button\" class=\"ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only insertCustomerButton\" role=\"button\" aria-disabled=\"false\">\r\n <span class=\"ui-button-text\">InsertCustomer</span>\r\n </button>\r\n\r\n </div>\r\n\r\n <div style=\"clear: both\"></div>\r\n\r\n <div class=\"customerTable\">\r\n <table border=\"1\" class=\"pressedBorder\">\r\n <tr>\r\n <th>Last Name</th>\r\n <th>First Name</th>\r\n <th>NickName</th>\r\n <th>Email</th>\r\n <th>Country</th>\r\n <th>Birthday</th>\r\n </tr>\r\n </table>\r\n </div>\r\n</div>\r\n";
}
),
View
15 public/javascripts/plugins/CustomerSection/view/res/css/customerDeleteDialog.css
@@ -0,0 +1,15 @@
+.customerDeleteDialog{
+
+ width: 200px;
+ height: 200px;
+}
+
+.customerDeleteDialog span{
+ text-align: center;
+}
+
+.customerDeleteDialog .buttonPanel{
+
+ padding-top: 20px;
+ text-align: center;
+}
View
5 public/javascripts/plugins/CustomerSection/view/res/css/customerSection.css
@@ -35,6 +35,11 @@
display: inline-block;
}
+.customerSection .customerTable button{
+ background: grey;
+ color: white;
+}
+
.customerSection .customerInsertPanel{
text-align: center;
View
5 public/javascripts/plugins/CustomerSection/view/res/css/customerUpdatePanel.css
@@ -17,7 +17,7 @@
left: 30%;
width: 20%;
- height: 65%;
+ height: 40%;
z-index: 7;
@@ -60,4 +60,5 @@
.customerUpdatePanel .infoPanel span{
padding-top: 5px;
width: 20%;
-}
+}
+
View
10 public/javascripts/plugins/CustomerSection/view/res/templates/customerDeleteDialog.html
@@ -0,0 +1,10 @@
+<span>Do you wish to confirm this action?</span>
+
+<div class="buttonPanel">
+ <button id="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only dialogYes" role="button" aria-disabled="false">
+ Yes
+ </button>
+ <button id="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only dialogNo" role="button" aria-disabled="false">
+ No
+ </button>
+</div>
View
19 public/javascripts/plugins/CustomerSection/view/res/templates/customerRowTemplate.html
@@ -5,6 +5,21 @@
<td>{{email}}</td>
<td>{{country}}</td>
<td>{{birthday}}</td>
- <td> <button class="editButton"> Edit </button> </td>
- <td> <button class="deleteButton"> Delete </button> </td>
+
+ <td> <button class="editButton pressedBorder" data-couchid="{{_id}}"
+ data-couchrev="{{_rev}}"
+ data-first_name="{{first_name}}" data-last_name="{{last_name}}"
+ data-nick_name="{{nick_name}}" data-email="{{email}}"
+ data-country="{{country}}" data-birthday="{{birthday}}">
+
+ <span class="ui-icon ui-icon-wrench"></span>
+ </button>
+ </td>
+
+ <td>
+ <button class="deleteButton pressedBorder" data-couchid="{{_id}}"
+ data-couchrev="{{_rev}}">
+ <span class="ui-icon ui-icon-closethick"></span>
+ </button>
+ </td>
</tr>
View
21 public/javascripts/plugins/CustomerSection/view/res/templates/customerSection.html
@@ -5,21 +5,24 @@ <h2 class="customerSectionTitle">Customer Section</h2>
<div style="clear: both"></div>
<div class="customerInsertPanel">
- <button class="insertCustomerButton">Insert Customer</button>
+ <button id="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only insertCustomerButton" role="button" aria-disabled="false">
+ <span class="ui-button-text">InsertCustomer</span>
+ </button>
+
</div>
<div style="clear: both"></div>
<div class="customerTable">
<table border="1" class="pressedBorder">
- <tr>
- <th>Last Name</th>
- <th>First Name</th>
- <th>NickName</th>
- <th>Email</th>
- <th>Country</th>
- <th>Birthday</th>
- </tr>
+ <tr>
+ <th>Last Name</th>
+ <th>First Name</th>
+ <th>NickName</th>
+ <th>Email</th>
+ <th>Country</th>
+ <th>Birthday</th>
+ </tr>
</table>
</div>
</div>
View
56 routes/user.js
@@ -4,7 +4,6 @@
*/
exports.users_by_last_name = function(req, res){
- //res.send("respond with a resource");
var nano = require('nano')('http://localhost:5984');
nano.db.get('users', function() {
@@ -12,35 +11,62 @@ exports.users_by_last_name = function(req, res){
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);
});
});
};
exports.update_user = function(req, res){
- //res.send("respond with a resource");
+
+ console.log("the update user http request was made...");
+
+ var nano = require('nano')('http://localhost:5984');
+ nano.db.get('users', function() {
+
+ var users = nano.use('users');
+
+ if (!req.body._id){
+ delete req.body._id;
+ }
+ if (!req.body._rev){
+ delete req.body._rev
+ }
+
+ console.log("inserting into user db... " + 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");
+ console.log(err);
+ }
+ res.send({});
+ });
+ });
+};
+
+exports.delete_user = function(req, res){
+
+ console.log("the update user http request was made...");
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 (req.body._id && req.body._rev){
+ console.log("deleting entry in user db... " + req.body._id);
+ users.destroy(req.body._id, req.body._rev, function(err, body){
if (err){
- console.log("There was an error updating the user");
+ console.log("There was an error deleting the user");
+ console.log(err);
}
+ res.send({});
});
-
}
+
+
});
+};
+
+exports.test_post = function(req, res){
+ console.log("test_post...");
};

0 comments on commit 9553fd3

Please sign in to comment.
Something went wrong with that request. Please try again.