Browse files

add coffeescript and built js file

  • Loading branch information...
1 parent f5e47c2 commit 11d64bc0828f0df4b2f27c6b97a5e4a152fa79bd @joshvermaire committed Aug 3, 2011
Showing with 849 additions and 0 deletions.
  1. +381 −0 public/javascripts/index.coffee
  2. +468 −0 public/javascripts/index.js
View
381 public/javascripts/index.coffee
@@ -0,0 +1,381 @@
+$ ->
+ server = "http://localhost:3000/"
+
+ isLoggedIn = ->
+ if typeof (window.interfaith) == "undefined"
+ false
+ else
+ true
+
+ interfaith = window.interfaith or {
+ user_id: 1
+ }
+
+ msg = (msg) ->
+ bubble = $("#app .msg").html(msg)
+ bubble.fadeIn("slow").delay(2000).fadeOut "fast"
+
+ Po = Backbone.Model.extend
+ urlRoot: "/pos"
+ template: "po"
+
+ User = Backbone.Model.extend
+
+ Vendor = Backbone.Model.extend
+ urlRoot: "/vendors"
+ template: "vendor"
+
+ PoList = Backbone.Collection.extend
+ url: "/pos"
+ model: Po
+
+ UserList = Backbone.Collection.extend
+ url: "/users"
+ model: User
+
+ VendorList = Backbone.Collection.extend
+ url: "/vendors"
+ model: Vendor
+
+ window.Pos = new PoList
+
+ window.Users = new UserList
+
+ window.Vendors = new VendorList
+
+ App.View.Resource = Backbone.View.extend
+ initialize: ->
+ _.bindAll @, "render"
+ @JSON = @model.toJSON()
+
+ tagName: "li"
+
+ render: ->
+ if @model.collection == Pos
+ @metadata() if !@JSON.vendor or @JSON.user
+ @JSON.approved = @approve()
+ @JSON.confirmed = @confirm()
+ $(@el).html JST[@options.template](@JSON)
+ $(@el).addClass('po'+@JSON.id)
+ @
+
+ metadata: ->
+ @JSON.vendor = @JSON.vendor or Vendors.get(@JSON.vendor_id).toJSON()
+ @JSON.user = @JSON.user or Users.get(@JSON.user_id).toJSON()
+
+ approve: ->
+ if not @JSON.approved and interfaith.can_approve == 1 and @JSON.confirmed isnt interfaith.user_id and @JSON.user_id isnt interfaith.user_id
+ "<a class=\"approved button\" href=\"/#" + @model.template + "/" + @JSON.id + "/approved\"><span class=\"check icon\"></span>Approve</a>"
+ else
+ "<a style=\"height:20px;width:81px; display:inline-block; \"></a>"
+
+ confirm: ->
+ if not @JSON.confirmed and interfaith.can_confirm == 1
+ "<a class=\"confirmed button positive\" href=\"/#" + @model.template + "/" + @JSON.id + "/confirmed\"><span class=\"check icon\"></span>Confirm</a>"
+ else
+ "<a style=\"height:20px;width:81px; display:inline-block; \"></a>"
+
+ App.View.NewResource = Backbone.View.extend(
+ el: $("#middle #sub-right")
+ events:
+ "click a#po-submit": "createPo"
+ "click a#vendor-submit": "createVendor"
+ "keypress input": "check"
+
+ initialize: ->
+ _.bindAll @, "render", "check"
+ @render()
+
+ render: ->
+ $(@el).html JST[@options.template]
+ @
+
+ createVendor: ->
+ @collection.create
+ name: $(".resource-vendor [name=name]").val(),
+ success: (model, response) ->
+ $("[name=name").val ""
+ location.hash = ""
+ error: (model, response) ->
+ console.log 'error createVendor'
+
+ createPo: ->
+ vendor = Vendors.find((po) ->
+ po.get("name") == $(".resource-po [name=name]").val()
+ )
+ unless vendor == "undefined"
+ @collection.create
+ vendor_id: vendor.id
+ needed: $(".resource-po [name=date-needed]").val()
+ amount: $(".resource-po [name=amount]").val()
+ user_id: interfaith.user_id
+ , success: (model, response) ->
+ msg('PO created')
+ console.log(model)
+ location.hash = ""
+ error: (model, error) ->
+ console.log model
+ console.log error
+
+ check: (event) ->
+ $(".resource-results").html('')
+ search = $("#search").val()
+ search += String.fromCharCode(event.which)
+ search = search.toLowerCase()
+ return if search == ""
+ self = @
+ vendorArray = []
+ vendors = Vendors.each (model) ->
+ lcname = model.attributes.name
+ if lcname
+ lcname = lcname.toLowerCase()
+ chara = lcname.indexOf(search)
+ vendorArray.push(model) if chara >=0
+ _(vendorArray).chain()
+ .sortBy((model) -> model.attributes.name)
+ .each((model) -> self.addResult(model))
+
+ addResult: (model) ->
+ $(".resource-results").append "<div>" + model.get("name") + "</div>"
+ )
+
+ SimpleView = Backbone.View.extend(
+ initialize: ->
+ _.bindAll @, "render"
+ @data = @model or {}
+ @data = @data.toJSON() if $.isEmptyObject(@data) == false
+ if @model and not @model.get("user_id")
+ @model.set user_id: "1"
+ @data = @model.toJSON()
+ if @model.template == "po"
+ @data.vendor = @data.vendor or Vendors.get(@data.vendor_id).toJSON()
+ @data.user = @data.user or Users.get(@data.user_id).toJSON()
+ @render()
+
+ render: ->
+ $(@el).html JST[@options.template](@data)
+ @
+ )
+
+ App.View.App = Backbone.View.extend(
+ el: $("#app")
+ events:
+ "click li#sign_in": "signInForm"
+ "click #signinlogin": "login"
+ "click #signout": "logout"
+ "click #sign_in_form": "stopPropagation"
+ "click #sign_in_over": "signInFormClose"
+
+ initialize: ->
+ _.bindAll @, "addOne", "addAll"
+ bottomView = new SimpleView
+ el: $("#bottom")
+ template: "footer"
+
+ stopPropagation: (event) ->
+ event.stopPropagation()
+
+ signInForm: ->
+ App.Router.navigate "users/sign_in"
+ $("#sign_in_over").fadeIn()
+
+ signInFormClose: ->
+ App.Router.navigate ""
+ $("#sign_in_over").fadeOut()
+
+ addOne: (resource) ->
+ view = new App.View.Resource
+ model: resource
+ template: resource.template
+ @$("#resource-list").append view.render().el
+
+ addAll: (collection) ->
+ collection.each @addOne
+
+ login: ->
+ login = user:
+ email: $("#signinemail").val()
+ password: $("#signinpw").val()
+ remember_me: $("#sign_in_form [name=remember_me]").val()
+
+ currentUser = new Backbone.Model()
+ url = server + "users/sign_in.json"
+ currentUser.url = url
+ currentUser.save login,
+ success: (model, response) ->
+ window.location = server
+
+ error: (model, response) ->
+ console.log model
+ console.log response
+
+ logout: ->
+ App.Router.navigate "users/sign_out"
+ currentUser = new Backbone.Model()
+ url = server + "users/sign_out.json"
+ currentUser.url = url
+ currentUser.fetch success: (model, response) ->
+ window.location = server
+ )
+
+ AppRouter = Backbone.Router.extend(
+ initialize: ->
+ @navigate ""
+
+ routes:
+ "": "index"
+ "po": "resourcePo"
+ "po/new": "newPo"
+ "po/approve": "approvePo"
+ "po/confirm": "confirmPo"
+ "po/:id/approved": "approvedPo"
+ "po/:id/confirmed": "confirmedPo"
+ "po/:id": "showPo"
+ "vendor": "resourceVendor"
+ "vendor/new": "newVendor"
+ "vendor/:id": "showVendor"
+ "users/sign_in": "sign_in"
+ "users/sign_out": "sign_out"
+ "*path": "fourohfour"
+
+ index: ->
+ if isLoggedIn()
+ $("#sub-right").html "<h1>WELCOME, " + window.interfaith.email + "</h1><p>You have <span class='num'></span> POs waiting to be approved.</p>"
+ $('.num').html(
+ Pos.filter((model) ->
+ model.get("approved") == null
+ ).length)
+ else
+ $("#sub-right").html "<h1>Log in mothabrotha</h1>"
+
+ resourcePo: ->
+ $("#sub-right").html "<div class=\"header cf\"><div class=\"po-vendor\">Vendor Name</div><div class=\"po-date\">Date Needed</div><div class=\"po-user\">User Email</div><div class=\"po-amount\">Amount</div></div><ul id=\"resource-list\" class=\"resource-list\"></ul>"
+ Pos.template = "po"
+ MainView.addAll Pos
+
+ newPo: ->
+ new App.View.NewResource(
+ model: new Po
+ template: "newPo"
+ collection: Pos
+ )
+
+ approvePo: ->
+ $("#sub-right").html "<div class=\"header cf\"><div class=\"po-vendor\">Vendor Name</div><div class=\"po-date\">Date Needed</div><div class=\"po-user\">User Email</div><div class=\"po-amount\">Amount</div></div><ul id=\"resource-list\" class=\"resource-list\"></ul>"
+ Pos.template = "po"
+ num = Pos.filter((model) ->
+ model.get("approved") == null
+ )
+ nums = _.each(num, (n) ->
+ MainView.addOne n
+ )
+
+ confirmPo: ->
+ $("#sub-right").html "<div class=\"header cf\"><div class=\"po-vendor\">Vendor Name</div><div class=\"po-date\">Date Needed</div><div class=\"po-user\">User Email</div><div class=\"po-amount\">Amount</div></div><ul id=\"resource-list\" class=\"resource-list\"></ul>"
+ Pos.template = "po"
+ num = Pos.filter((model) ->
+ model.get("confirmed") == null
+ )
+ nums = _.each(num, (n) ->
+ MainView.addOne n
+ )
+
+ approvedPo: (id) ->
+ po = new Po(id: id)
+ po.save approved: interfaith.user_id,
+ success: (model, resp) ->
+ listItem = $('.po'+id)
+ if listItem.length
+ listItem.fadeOut('500')
+ else
+ @navigate "po/"+id, true
+ msg "PO #"+id+" approved"
+ error: (model, resp) ->
+ console.log "Error approvedPo"
+ console.log model
+ console.log resp
+
+ confirmedPo: (id) ->
+ po = new Po(id: id)
+ po.save confirmed: interfaith.user_id,
+ success: (model, resp) ->
+ li = $('.po'+id)
+ if li.length
+ li.fadeOut('500')
+ else
+ @navigate "po/"+id, true
+ msg "PO #"+id+" confirmed"
+ error: (model, resp) ->
+ console.log "Error confirmedPo"
+ console.log model
+ console.log resp
+
+ showPo: (id) ->
+ po = new Po(id: id)
+ po.fetch
+ success: (model, resp) ->
+ appNum = model.get("approved")
+ confNum = model.get("confirmed")
+ approve_name = Users.get(appNum).get("email") or null if appNum
+ confirm_name = Users.get(confNum).get("email") or null if confNum
+ if approve_name
+ approve_name = "This PO approved by: " + approve_name
+ else
+ approve_name = "<div class=\"approved\">Approve</div>"
+ if confirm_name
+ confirm_name = "This PO confirmed by: " + confirm_name
+ else
+ confirm_name = "<div class=\"confirmed\">Confirm</div>"
+ po.set
+ aname: approve_name
+ cname: confirm_name
+
+ new SimpleView
+ el: $("#sub-right")
+ model: po
+ template: "viewPo"
+
+ error: (model, resp) ->
+ console.log "Error showPo"
+ console.log model
+ console.log resp
+
+ resourceVendor: ->
+ $("#sub-right").html "<div class='header cf'><div class='po-vendor'>Vendor Name</div><div class='po-amount'>Approved</div></div><ul id='resource-list' class='resource-list'></ul>"
+ Vendors.template = "vendor"
+ MainView.addAll Vendors
+
+ newVendor: ->
+ new App.View.NewResource
+ model: new Vendor
+ template: "newVendor"
+ collection: Vendors
+
+ showVendor: (id) ->
+ vendor = new Vendor(id: id)
+ vendor.fetch
+ success: (model, resp) ->
+ new SimpleView
+ model: vendor
+ el: $("#sub-right")
+ template: "viewVendor"
+
+
+ error: (model, resp) ->
+ console.log "Error showResource"
+ console.log model
+
+ sign_in: ->
+ MainView.signInForm()
+
+ sign_out: ->
+ MainView.logout()
+
+ fourohfour: (path) ->
+ alert path + " 404 baby"
+ )
+ Users.fetch()
+ Vendors.fetch()
+ Pos.fetch()
+ App.Router = new AppRouter()
+ MainView = new App.View.App()
View
468 public/javascripts/index.js
@@ -0,0 +1,468 @@
+(function() {
+ $(function() {
+ var AppRouter, MainView, Po, PoList, SimpleView, User, UserList, Vendor, VendorList, interfaith, isLoggedIn, msg, server;
+ server = "http://localhost:3000/";
+ isLoggedIn = function() {
+ if (typeof window.interfaith === "undefined") {
+ return false;
+ } else {
+ return true;
+ }
+ };
+ interfaith = window.interfaith || {
+ user_id: 1
+ };
+ msg = function(msg) {
+ var bubble;
+ bubble = $("#app .msg").html(msg);
+ return bubble.fadeIn("slow").delay(2000).fadeOut("fast");
+ };
+ Po = Backbone.Model.extend({
+ urlRoot: "/pos",
+ template: "po"
+ });
+ User = Backbone.Model.extend;
+ Vendor = Backbone.Model.extend({
+ urlRoot: "/vendors",
+ template: "vendor"
+ });
+ PoList = Backbone.Collection.extend({
+ url: "/pos",
+ model: Po
+ });
+ UserList = Backbone.Collection.extend({
+ url: "/users",
+ model: User
+ });
+ VendorList = Backbone.Collection.extend({
+ url: "/vendors",
+ model: Vendor
+ });
+ window.Pos = new PoList;
+ window.Users = new UserList;
+ window.Vendors = new VendorList;
+ App.View.Resource = Backbone.View.extend({
+ initialize: function() {
+ _.bindAll(this, "render");
+ return this.JSON = this.model.toJSON();
+ },
+ tagName: "li",
+ render: function() {
+ if (this.model.collection === Pos) {
+ if (!this.JSON.vendor || this.JSON.user) {
+ this.metadata();
+ }
+ this.JSON.approved = this.approve();
+ this.JSON.confirmed = this.confirm();
+ }
+ $(this.el).html(JST[this.options.template](this.JSON));
+ $(this.el).addClass('po' + this.JSON.id);
+ return this;
+ },
+ metadata: function() {
+ this.JSON.vendor = this.JSON.vendor || Vendors.get(this.JSON.vendor_id).toJSON();
+ return this.JSON.user = this.JSON.user || Users.get(this.JSON.user_id).toJSON();
+ },
+ approve: function() {
+ if (!this.JSON.approved && interfaith.can_approve === 1 && this.JSON.confirmed !== interfaith.user_id && this.JSON.user_id !== interfaith.user_id) {
+ return "<a class=\"approved button\" href=\"/#" + this.model.template + "/" + this.JSON.id + "/approved\"><span class=\"check icon\"></span>Approve</a>";
+ } else {
+ return "<a style=\"height:20px;width:81px; display:inline-block; \"></a>";
+ }
+ },
+ confirm: function() {
+ if (!this.JSON.confirmed && interfaith.can_confirm === 1) {
+ return "<a class=\"confirmed button positive\" href=\"/#" + this.model.template + "/" + this.JSON.id + "/confirmed\"><span class=\"check icon\"></span>Confirm</a>";
+ } else {
+ return "<a style=\"height:20px;width:81px; display:inline-block; \"></a>";
+ }
+ }
+ });
+ App.View.NewResource = Backbone.View.extend({
+ el: $("#middle #sub-right"),
+ events: {
+ "click a#po-submit": "createPo",
+ "click a#vendor-submit": "createVendor",
+ "keypress input": "check"
+ },
+ initialize: function() {
+ _.bindAll(this, "render", "check");
+ return this.render();
+ },
+ render: function() {
+ $(this.el).html(JST[this.options.template]);
+ return this;
+ },
+ createVendor: function() {
+ return this.collection.create({
+ name: $(".resource-vendor [name=name]").val(),
+ success: function(model, response) {
+ $("[name=name").val("");
+ return location.hash = "";
+ },
+ error: function(model, response) {
+ return console.log('error createVendor');
+ }
+ });
+ },
+ createPo: function() {
+ var vendor;
+ vendor = Vendors.find(function(po) {
+ return po.get("name") === $(".resource-po [name=name]").val();
+ });
+ if (vendor !== "undefined") {
+ return this.collection.create({
+ vendor_id: vendor.id,
+ needed: $(".resource-po [name=date-needed]").val(),
+ amount: $(".resource-po [name=amount]").val(),
+ user_id: interfaith.user_id
+ }, {
+ success: function(model, response) {
+ msg('PO created');
+ console.log(model);
+ return location.hash = "";
+ },
+ error: function(model, error) {
+ console.log(model);
+ return console.log(error);
+ }
+ });
+ }
+ },
+ check: function(event) {
+ var search, self, vendorArray, vendors;
+ $(".resource-results").html('');
+ search = $("#search").val();
+ search += String.fromCharCode(event.which);
+ search = search.toLowerCase();
+ if (search === "") {
+ return;
+ }
+ self = this;
+ vendorArray = [];
+ vendors = Vendors.each(function(model) {
+ var chara, lcname;
+ lcname = model.attributes.name;
+ if (lcname) {
+ lcname = lcname.toLowerCase();
+ chara = lcname.indexOf(search);
+ if (chara >= 0) {
+ return vendorArray.push(model);
+ }
+ }
+ });
+ return _(vendorArray).chain().sortBy(function(model) {
+ return model.attributes.name;
+ }).each(function(model) {
+ return self.addResult(model);
+ });
+ },
+ addResult: function(model) {
+ return $(".resource-results").append("<div>" + model.get("name") + "</div>");
+ }
+ });
+ SimpleView = Backbone.View.extend({
+ initialize: function() {
+ _.bindAll(this, "render");
+ this.data = this.model || {};
+ if ($.isEmptyObject(this.data) === false) {
+ this.data = this.data.toJSON();
+ }
+ if (this.model && !this.model.get("user_id")) {
+ this.model.set({
+ user_id: "1"
+ });
+ this.data = this.model.toJSON();
+ if (this.model.template === "po") {
+ this.data.vendor = this.data.vendor || Vendors.get(this.data.vendor_id).toJSON();
+ this.data.user = this.data.user || Users.get(this.data.user_id).toJSON();
+ }
+ }
+ return this.render();
+ },
+ render: function() {
+ $(this.el).html(JST[this.options.template](this.data));
+ return this;
+ }
+ });
+ App.View.App = Backbone.View.extend({
+ el: $("#app"),
+ events: {
+ "click li#sign_in": "signInForm",
+ "click #signinlogin": "login",
+ "click #signout": "logout",
+ "click #sign_in_form": "stopPropagation",
+ "click #sign_in_over": "signInFormClose"
+ },
+ initialize: function() {
+ var bottomView;
+ _.bindAll(this, "addOne", "addAll");
+ return bottomView = new SimpleView({
+ el: $("#bottom"),
+ template: "footer"
+ });
+ },
+ stopPropagation: function(event) {
+ return event.stopPropagation();
+ },
+ signInForm: function() {
+ App.Router.navigate("users/sign_in");
+ return $("#sign_in_over").fadeIn();
+ },
+ signInFormClose: function() {
+ App.Router.navigate("");
+ return $("#sign_in_over").fadeOut();
+ },
+ addOne: function(resource) {
+ var view;
+ view = new App.View.Resource({
+ model: resource,
+ template: resource.template
+ });
+ return this.$("#resource-list").append(view.render().el);
+ },
+ addAll: function(collection) {
+ return collection.each(this.addOne);
+ },
+ login: function() {
+ var currentUser, login, url;
+ login = {
+ user: {
+ email: $("#signinemail").val(),
+ password: $("#signinpw").val(),
+ remember_me: $("#sign_in_form [name=remember_me]").val()
+ }
+ };
+ currentUser = new Backbone.Model();
+ url = server + "users/sign_in.json";
+ currentUser.url = url;
+ return currentUser.save(login, {
+ success: function(model, response) {
+ return window.location = server;
+ },
+ error: function(model, response) {
+ console.log(model);
+ return console.log(response);
+ }
+ });
+ },
+ logout: function() {
+ var currentUser, url;
+ App.Router.navigate("users/sign_out");
+ currentUser = new Backbone.Model();
+ url = server + "users/sign_out.json";
+ currentUser.url = url;
+ return currentUser.fetch({
+ success: function(model, response) {
+ return window.location = server;
+ }
+ });
+ }
+ });
+ AppRouter = Backbone.Router.extend({
+ initialize: function() {
+ return this.navigate("");
+ },
+ routes: {
+ "": "index",
+ "po": "resourcePo",
+ "po/new": "newPo",
+ "po/approve": "approvePo",
+ "po/confirm": "confirmPo",
+ "po/:id/approved": "approvedPo",
+ "po/:id/confirmed": "confirmedPo",
+ "po/:id": "showPo",
+ "vendor": "resourceVendor",
+ "vendor/new": "newVendor",
+ "vendor/:id": "showVendor",
+ "users/sign_in": "sign_in",
+ "users/sign_out": "sign_out",
+ "*path": "fourohfour"
+ },
+ index: function() {
+ if (isLoggedIn()) {
+ $("#sub-right").html("<h1>WELCOME, " + window.interfaith.email + "</h1><p>You have <span class='num'></span> POs waiting to be approved.</p>");
+ return $('.num').html(Pos.filter(function(model) {
+ return model.get("approved") === null;
+ }).length);
+ } else {
+ return $("#sub-right").html("<h1>Log in mothabrotha</h1>");
+ }
+ },
+ resourcePo: function() {
+ $("#sub-right").html("<div class=\"header cf\"><div class=\"po-vendor\">Vendor Name</div><div class=\"po-date\">Date Needed</div><div class=\"po-user\">User Email</div><div class=\"po-amount\">Amount</div></div><ul id=\"resource-list\" class=\"resource-list\"></ul>");
+ Pos.template = "po";
+ return MainView.addAll(Pos);
+ },
+ newPo: function() {
+ return new App.View.NewResource({
+ model: new Po,
+ template: "newPo",
+ collection: Pos
+ });
+ },
+ approvePo: function() {
+ var num, nums;
+ $("#sub-right").html("<div class=\"header cf\"><div class=\"po-vendor\">Vendor Name</div><div class=\"po-date\">Date Needed</div><div class=\"po-user\">User Email</div><div class=\"po-amount\">Amount</div></div><ul id=\"resource-list\" class=\"resource-list\"></ul>");
+ Pos.template = "po";
+ num = Pos.filter(function(model) {
+ return model.get("approved") === null;
+ });
+ return nums = _.each(num, function(n) {
+ return MainView.addOne(n);
+ });
+ },
+ confirmPo: function() {
+ var num, nums;
+ $("#sub-right").html("<div class=\"header cf\"><div class=\"po-vendor\">Vendor Name</div><div class=\"po-date\">Date Needed</div><div class=\"po-user\">User Email</div><div class=\"po-amount\">Amount</div></div><ul id=\"resource-list\" class=\"resource-list\"></ul>");
+ Pos.template = "po";
+ num = Pos.filter(function(model) {
+ return model.get("confirmed") === null;
+ });
+ return nums = _.each(num, function(n) {
+ return MainView.addOne(n);
+ });
+ },
+ approvedPo: function(id) {
+ var po;
+ po = new Po({
+ id: id
+ });
+ return po.save({
+ approved: interfaith.user_id
+ }, {
+ success: function(model, resp) {
+ var listItem;
+ listItem = $('.po' + id);
+ if (listItem.length) {
+ listItem.fadeOut('500');
+ } else {
+ this.navigate("po/" + id, true);
+ }
+ return msg("PO #" + id + " approved");
+ },
+ error: function(model, resp) {
+ console.log("Error approvedPo");
+ console.log(model);
+ return console.log(resp);
+ }
+ });
+ },
+ confirmedPo: function(id) {
+ var po;
+ po = new Po({
+ id: id
+ });
+ return po.save({
+ confirmed: interfaith.user_id
+ }, {
+ success: function(model, resp) {
+ var li;
+ li = $('.po' + id);
+ if (li.length) {
+ li.fadeOut('500');
+ } else {
+ this.navigate("po/" + id, true);
+ }
+ return msg("PO #" + id + " confirmed");
+ },
+ error: function(model, resp) {
+ console.log("Error confirmedPo");
+ console.log(model);
+ return console.log(resp);
+ }
+ });
+ },
+ showPo: function(id) {
+ var po;
+ po = new Po({
+ id: id
+ });
+ return po.fetch({
+ success: function(model, resp) {
+ var appNum, approve_name, confNum, confirm_name;
+ appNum = model.get("approved");
+ confNum = model.get("confirmed");
+ if (appNum) {
+ approve_name = Users.get(appNum).get("email") || null;
+ }
+ if (confNum) {
+ confirm_name = Users.get(confNum).get("email") || null;
+ }
+ if (approve_name) {
+ approve_name = "This PO approved by: " + approve_name;
+ } else {
+ approve_name = "<div class=\"approved\">Approve</div>";
+ }
+ if (confirm_name) {
+ confirm_name = "This PO confirmed by: " + confirm_name;
+ } else {
+ confirm_name = "<div class=\"confirmed\">Confirm</div>";
+ }
+ po.set({
+ aname: approve_name,
+ cname: confirm_name
+ });
+ return new SimpleView({
+ el: $("#sub-right"),
+ model: po,
+ template: "viewPo"
+ });
+ },
+ error: function(model, resp) {
+ console.log("Error showPo");
+ console.log(model);
+ return console.log(resp);
+ }
+ });
+ },
+ resourceVendor: function() {
+ $("#sub-right").html("<div class='header cf'><div class='po-vendor'>Vendor Name</div><div class='po-amount'>Approved</div></div><ul id='resource-list' class='resource-list'></ul>");
+ Vendors.template = "vendor";
+ return MainView.addAll(Vendors);
+ },
+ newVendor: function() {
+ return new App.View.NewResource({
+ model: new Vendor,
+ template: "newVendor",
+ collection: Vendors
+ });
+ },
+ showVendor: function(id) {
+ var vendor;
+ vendor = new Vendor({
+ id: id
+ });
+ return vendor.fetch({
+ success: function(model, resp) {
+ return new SimpleView({
+ model: vendor,
+ el: $("#sub-right"),
+ template: "viewVendor"
+ });
+ },
+ error: function(model, resp) {
+ console.log("Error showResource");
+ return console.log(model);
+ }
+ });
+ },
+ sign_in: function() {
+ return MainView.signInForm();
+ },
+ sign_out: function() {
+ return MainView.logout();
+ },
+ fourohfour: function(path) {
+ return alert(path + " 404 baby");
+ }
+ });
+ Users.fetch();
+ Vendors.fetch();
+ Pos.fetch(success(a, b)(function() {}), $('.num').length && App.Router && isLoggedIn() ? $('.num').html(Pos.filter(function(model) {
+ return model.get("approved") === null;
+ }).length) : void 0);
+ App.Router = new AppRouter();
+ return MainView = new App.View.App();
+ });
+}).call(this);

0 comments on commit 11d64bc

Please sign in to comment.