Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.16 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var App = App || {};
  2. App.Controllers = App.Controllers || {};
  3. App.Controllers.UserEdit = function() {
  4.   this.model = new App.Models.Users();
  5.   this.view = new App.Views.UserEdit();
  6.   App.Routes.addRoute("/users/:user_uuid/edit/", $.proxy(this.handleUserEditRoute, this));
  7.   // This is a little jQuery plugin that provides custom events
  8.   $.subscribe("UserEditFormSubmitted", $.proxy(this.handleFormSubmitted, this));
  9. }
  10. App.Controllers.UserList.prototype.handleUserEditRoute = function(params) {
  11.   this.model.getRecord({uuid: params.user_uuid, success: $.proxy(this.renderUserEditView, this)})
  12. }
  13. App.Controllers.UserList.prototype.renderUserEditView = function(response) {
  14.   this.view.render(response);
  15. }
  16. App.Controllers.UserList.prototype.handleFormSubmitted = function(formData) {
  17.   var formDataObject = stringToObj(formData); // this function just turns "some=value&someOther=value2" into {some: "value", someOther: "value2"}
  18.   this.model.updateRecord({
  19.     uuid: formDataObject.uuid,
  20.     data: formData,
  21.     success: $.proxy(this.handleUpdateSuccess, this)
  22.   });
  23. }
  24. App.Controllers.UserList.prototype.handleUpdateSuccess = function(response) {
  25.   document.location.hash = "/users/";
  26. }