Permalink
Browse files

Merge pull request #84 from karthikv/backbone

Refactor project and screen pages to use Backbone.js.
  • Loading branch information...
2 parents ce332a2 + 6e0159f commit 515c3b6c9efaef5fbd9774c0f82a3309e43552ab Jennifer Fong committed Sep 6, 2012
Showing with 2,114 additions and 5,103 deletions.
  1. +11 −0 public/javascripts/collections/component.js
  2. +12 −0 public/javascripts/collections/element.js
  3. +15 −0 public/javascripts/collections/extended.js
  4. +11 −0 public/javascripts/collections/project.js
  5. +13 −0 public/javascripts/collections/screen.js
  6. +0 −64 public/javascripts/controllers/component-list.js
  7. +0 −331 public/javascripts/controllers/component.js
  8. +0 −93 public/javascripts/controllers/element-list.js
  9. +0 −327 public/javascripts/controllers/element.js
  10. +0 −38 public/javascripts/controllers/extended.js
  11. +0 −111 public/javascripts/controllers/layout-modification.js
  12. +0 −35 public/javascripts/controllers/project-list.js
  13. +0 −127 public/javascripts/controllers/project.js
  14. +0 −63 public/javascripts/controllers/screen-actions.js
  15. +0 −161 public/javascripts/controllers/screen-layout.js
  16. +0 −95 public/javascripts/controllers/screen-list.js
  17. +0 −54 public/javascripts/controllers/screen.js
  18. +0 −23 public/javascripts/controllers/switch.js
  19. +0 −11 public/javascripts/controllers/window.js
  20. +1 −1 public/javascripts/helpers/errors.js
  21. +30 −10 public/javascripts/helpers/shared-models.js
  22. +0 −40 public/javascripts/helpers/utils.js
  23. +39 −0 public/javascripts/lib/backbone.min.js
  24. +0 −42 public/javascripts/lib/can.construct.super.js
  25. +0 −2,994 public/javascripts/lib/can.jquery.js
  26. +0 −1 public/javascripts/lib/can.jquery.min.js
  27. +0 −181 public/javascripts/lib/can.observe.list.sort.js
  28. +32 −0 public/javascripts/lib/underscore.min.js
  29. +2 −8 public/javascripts/models/component.js
  30. +2 −8 public/javascripts/models/element.js
  31. +15 −38 public/javascripts/models/extended.js
  32. +2 −15 public/javascripts/models/project.js
  33. +5 −14 public/javascripts/models/screen.js
  34. +12 −0 public/javascripts/routers/project-page.js
  35. +7 −7 public/javascripts/scripts/index.js
  36. +9 −8 public/javascripts/scripts/prototype.js
  37. +76 −0 public/javascripts/views/component-list.js
  38. +312 −0 public/javascripts/views/component.js
  39. +100 −0 public/javascripts/views/element-list.js
  40. +384 −0 public/javascripts/views/element.js
  41. +143 −0 public/javascripts/views/extended.js
  42. +13 −0 public/javascripts/views/key-manager.js
  43. +105 −0 public/javascripts/views/layout-modification.js
  44. +54 −0 public/javascripts/views/project-list.js
  45. +143 −0 public/javascripts/views/project.js
  46. +74 −0 public/javascripts/views/screen-actions.js
  47. +162 −0 public/javascripts/views/screen-layout.js
  48. +87 −0 public/javascripts/views/screen-list.js
  49. +71 −0 public/javascripts/views/screen.js
  50. +2 −1 public/stylesheets/main.styl
  51. +10 −0 todo.txt
  52. +12 −9 views/helpers/share-login-form.jade
  53. +3 −4 views/templates/collections/project.jade
  54. +15 −16 views/templates/collections/screen.jade
  55. +5 −7 views/templates/elements/auth.jade
  56. +3 −5 views/templates/elements/external-link.jade
  57. +14 −29 views/templates/elements/heading.jade
  58. +6 −9 views/templates/elements/input-checkbox.jade
  59. +6 −9 views/templates/elements/input-radio.jade
  60. +6 −9 views/templates/elements/input-text.jade
  61. +2 −5 views/templates/elements/paragraph.jade
  62. +3 −5 views/templates/elements/screen-link.jade
  63. +6 −9 views/templates/elements/textarea.jade
  64. +4 −0 views/templates/helpers/screen-selection.jade
  65. +4 −5 views/templates/layouts/layout.jade
  66. +1 −1 views/templates/lists/article-element.jade
  67. +38 −38 views/templates/lists/component.jade
  68. +3 −3 views/templates/lists/form-element.jade
  69. +2 −11 views/templates/lists/navigation-element.jade
  70. +2 −2 views/templates/popovers/auth.jade
  71. +3 −3 views/templates/popovers/external-link.jade
  72. +4 −4 views/templates/popovers/heading.jade
  73. +2 −2 views/templates/popovers/input-checkbox.jade
  74. +2 −2 views/templates/popovers/input-radio.jade
  75. +2 −2 views/templates/popovers/input-text.jade
  76. +2 −2 views/templates/popovers/paragraph.jade
  77. +3 −3 views/templates/popovers/screen-link.jade
  78. +2 −2 views/templates/popovers/textarea.jade
  79. +5 −6 views/templates/wrappers/form.jade
@@ -0,0 +1,11 @@
+define(['jquery', 'backbone', './extended', 'models/component'],
+ function($, Backbone, ExtendedCollection, ComponentModel) {
+ return ExtendedCollection.extend({
+ url: function() {
+ return '/projects/' + this.options.projectId + '/screens/' +
+ this.options.screenId + '/components';
+ },
+
+ model: ComponentModel
+ });
+ });
@@ -0,0 +1,12 @@
+define(['jquery', 'backbone', './extended', 'models/element'],
+ function($, Backbone, ExtendedCollection, ElementModel) {
+ return ExtendedCollection.extend({
+ url: function() {
+ return '/projects/' + this.options.projectId + '/screens/' +
+ this.options.screenId + '/components/' + this.options.componentId +
+ '/elements';
+ },
+
+ model: ElementModel
+ });
+ });
@@ -0,0 +1,15 @@
+define(['jquery', 'backbone'],
+ function($, Backbone) {
+ var ExtendedCollection = Backbone.Collection.extend({
+ initialize: function(models, options) {
+ this.options = options;
+ },
+
+ constructParent: function(args) {
+ args = Array.prototype.slice.call(args, 0);
+ ExtendedCollection.prototype.initialize.apply(this, args);
+ }
+ });
+
+ return ExtendedCollection;
+ });
@@ -0,0 +1,11 @@
+define(['jquery', 'backbone', './extended', 'models/project'],
+ function($, Backbone, ExtendedCollection, ProjectModel) {
+ return ExtendedCollection.extend({
+ url: '/projects',
+ model: ProjectModel,
+
+ comparator: function(project) {
+ return project.get('id');
+ }
+ });
+ });
@@ -0,0 +1,13 @@
+define(['jquery', 'backbone', './extended', 'models/screen'],
+ function($, Backbone, ExtendedCollection, ScreenModel) {
+ return ExtendedCollection.extend({
+ url: function() {
+ return '/projects/' + this.options.projectId + '/screens';
+ },
+
+ model: ScreenModel,
+ comparator: function(screen) {
+ return screen.get('id');
+ }
+ });
+ });
@@ -1,64 +0,0 @@
-define(['jquery', 'can', './switch', 'helpers/shared-models', 'helpers/errors',
- './layout-modification', 'can.super', 'jquery.serialize', 'jquery.ui'],
- function($, can, SwitchControl, sharedModels, errors, LayoutModificationControl) {
- return SwitchControl({
- init: function($element, options) {
- this._super($element, options);
- var self = this;
-
- sharedModels.getCurrentScreen()
- .then(function(screen) {
- self.screen = screen;
- self.activate();
- }, function() {
- // TODO: handle error
- });
- },
-
- dragOptions: {
- revert: 'invalid',
- // don't cancel if input is dragged
- cancel: ''
- },
-
- render: function() {
- this.element.html(can.view('component-list-template', this.screen));
- this.$('.component').draggable(this.dragOptions);
-
- // to control screen layout modifications
- new LayoutModificationControl(this.$('#layout-modifications'), {});
- this.$('.dropdown-toggle').dropdown();
- },
-
- '#screen-config submit': function($form, event) {
- event.preventDefault();
- var $submit = $form.find('[type="submit"]');
- $submit.attr('disabled', 'disabled');
-
- var formData = $form.serializeObject();
- // secure will not be set to false if the checkbox is not checked;
- // instead, it will remain undefined; in this case, set it manually
- if (!formData.secure) {
- formData.secure = false;
- }
-
- // merge form data with screen attributes
- this.screen.attr(formData);
- this.screen.withRouteData()
- .save()
- .then(function(screen) {
- // visual feedback with a check icon
- var $check = $form.find('.icon-ok');
- $check.show();
-
- $submit.removeAttr('disabled');
- setTimeout(function() {
- $check.hide();
- }, 1000);
- }, function(xhr) {
- $submit.removeAttr('disabled');
- errors.tooltipHandler($submit)(xhr);
- });
- }
- });
- });
Oops, something went wrong.

0 comments on commit 515c3b6

Please sign in to comment.