luca 0.9.4 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. data/CHANGELOG +41 -1
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +2 -0
  4. data/README.md +5 -0
  5. data/Rakefile +4 -0
  6. data/assets/javascripts/dependencies/underscore-min.js +5 -31
  7. data/assets/javascripts/luca-templates.js +1 -0
  8. data/assets/javascripts/luca-ui-base.coffee +1 -1
  9. data/assets/javascripts/luca-ui-development-tools.coffee +1 -1
  10. data/assets/javascripts/luca-ui-full.js +1 -1
  11. data/assets/javascripts/luca-ui-spec.coffee +1 -1
  12. data/assets/javascripts/luca-ui.js +3 -0
  13. data/assets/javascripts/luca/index.coffee +1 -0
  14. data/lib/generators/luca/application/application_generator.rb +71 -0
  15. data/lib/generators/luca/application/templates/controller.rb +6 -0
  16. data/lib/generators/luca/application/templates/index.html.erb +7 -0
  17. data/lib/generators/luca/application/templates/index.html.haml +6 -0
  18. data/lib/generators/luca/application/templates/javascripts/application.js +28 -0
  19. data/lib/generators/luca/application/templates/javascripts/application.js.coffee +20 -0
  20. data/lib/generators/luca/application/templates/javascripts/config.js +15 -0
  21. data/lib/generators/luca/application/templates/javascripts/config.js.coffee +9 -0
  22. data/lib/generators/luca/application/templates/javascripts/dependencies.js +5 -0
  23. data/lib/generators/luca/application/templates/javascripts/dependencies.js.coffee +5 -0
  24. data/lib/generators/luca/application/templates/javascripts/index.js +9 -0
  25. data/lib/generators/luca/application/templates/javascripts/index.js.coffee +9 -0
  26. data/lib/generators/luca/application/templates/javascripts/main.js +8 -0
  27. data/lib/generators/luca/application/templates/javascripts/main.js.coffee +3 -0
  28. data/lib/generators/luca/application/templates/javascripts/main.jst.ejs +1 -0
  29. data/lib/generators/luca/application/templates/javascripts/router.js +12 -0
  30. data/lib/generators/luca/application/templates/javascripts/router.js.coffee +7 -0
  31. data/lib/luca/rails/version.rb +1 -1
  32. data/lib/luca/template.rb +1 -1
  33. data/spec/components/collection_view_spec.coffee +37 -0
  34. data/spec/components/multi_collection_view_spec.coffee +5 -0
  35. data/spec/components/table_view_spec.coffee +17 -0
  36. data/spec/core/container_spec.coffee +112 -5
  37. data/spec/core/model_spec.coffee +21 -3
  38. data/spec/define_spec.coffee +19 -0
  39. data/spec/mixin_spec.coffee +49 -0
  40. data/src/components/application.coffee +33 -19
  41. data/src/components/collection_view.coffee +109 -38
  42. data/src/components/fields/checkbox_field.coffee +2 -2
  43. data/src/components/fields/file_upload_field.coffee +0 -3
  44. data/src/components/fields/hidden_field.coffee +0 -3
  45. data/src/components/fields/label_field.coffee +1 -4
  46. data/src/components/fields/select_field.coffee +6 -6
  47. data/src/components/fields/text_area_field.coffee +1 -0
  48. data/src/components/fields/text_field.coffee +4 -0
  49. data/src/components/fields/type_ahead_field.coffee +5 -9
  50. data/src/components/form_view.coffee +2 -0
  51. data/src/components/index.coffee +1 -0
  52. data/src/components/multi_collection_view.coffee +94 -0
  53. data/src/components/pagination_control.coffee +100 -0
  54. data/src/components/table_view.coffee +62 -0
  55. data/src/containers/card_view.coffee +44 -11
  56. data/src/containers/panel_toolbar.coffee +88 -82
  57. data/src/containers/tab_view.coffee +3 -3
  58. data/src/containers/viewport.coffee +10 -4
  59. data/src/core/collection.coffee +11 -4
  60. data/src/core/container.coffee +189 -113
  61. data/src/core/field.coffee +13 -10
  62. data/src/core/model.coffee +23 -27
  63. data/src/core/registry.coffee +48 -35
  64. data/src/core/view.coffee +60 -140
  65. data/src/define.coffee +91 -19
  66. data/src/framework.coffee +10 -8
  67. data/src/index.coffee +23 -0
  68. data/src/managers/collection_manager.coffee +24 -8
  69. data/src/modules/application_event_bindings.coffee +19 -0
  70. data/src/modules/collection_event_bindings.coffee +26 -0
  71. data/src/modules/deferrable.coffee +3 -1
  72. data/src/modules/dom_helpers.coffee +49 -0
  73. data/src/modules/enhanced_properties.coffee +23 -0
  74. data/src/modules/filterable.coffee +60 -0
  75. data/src/modules/grid_layout.coffee +15 -0
  76. data/src/modules/{load_mask.coffee → loadmaskable.coffee} +10 -4
  77. data/src/modules/modal_view.coffee +38 -0
  78. data/src/modules/paginatable.coffee +79 -0
  79. data/src/modules/state_model.coffee +16 -0
  80. data/src/modules/templating.coffee +8 -0
  81. data/src/plugins/events.coffee +30 -2
  82. data/src/templates/components/bootstrap_form_controls.jst.ejs +10 -0
  83. data/src/templates/components/collection_loader_view.jst.ejs +6 -0
  84. data/src/templates/components/form_alert.jst.ejs +4 -0
  85. data/src/templates/components/grid_view.jst.ejs +11 -0
  86. data/src/templates/components/grid_view_empty_text.jst.ejs +3 -0
  87. data/src/templates/components/load_mask.jst.ejs +5 -0
  88. data/src/templates/components/nav_bar.jst.ejs +4 -0
  89. data/src/templates/components/pagination.jst.ejs +10 -0
  90. data/src/templates/containers/basic.jst.ejs +1 -0
  91. data/src/templates/containers/tab_selector_container.jst.ejs +12 -0
  92. data/src/templates/containers/tab_view.jst.ejs +2 -0
  93. data/src/templates/containers/toolbar_wrapper.jst.ejs +1 -0
  94. data/src/templates/fields/button_field.jst.ejs +2 -0
  95. data/src/templates/fields/button_field_link.jst.ejs +6 -0
  96. data/src/templates/fields/checkbox_array.jst.ejs +4 -0
  97. data/src/templates/fields/checkbox_array_item.jst.ejs +3 -0
  98. data/src/templates/fields/checkbox_field.jst.ejs +10 -0
  99. data/src/templates/fields/file_upload_field.jst.ejs +10 -0
  100. data/src/templates/fields/hidden_field.jst.ejs +1 -0
  101. data/src/templates/fields/select_field.jst.ejs +11 -0
  102. data/src/templates/fields/text_area_field.jst.ejs +11 -0
  103. data/src/templates/fields/text_field.jst.ejs +16 -0
  104. data/src/templates/table_view.jst.ejs +4 -0
  105. data/src/tools/console.coffee +51 -21
  106. data/src/util.coffee +17 -4
  107. data/vendor/assets/javascripts/luca-ui-base.js +3288 -613
  108. data/vendor/assets/javascripts/luca-ui-development-tools.js +49 -21
  109. data/vendor/assets/javascripts/luca-ui-development-tools.min.js +1 -1
  110. data/vendor/assets/javascripts/luca-ui-full.js +1704 -554
  111. data/vendor/assets/javascripts/luca-ui-full.min.js +7 -6
  112. data/vendor/assets/javascripts/luca-ui-spec.js +1783 -830
  113. data/vendor/assets/javascripts/luca-ui-templates.js +92 -0
  114. data/vendor/assets/javascripts/luca-ui.js +1694 -523
  115. data/vendor/assets/javascripts/luca-ui.min.js +4 -4
  116. metadata +69 -31
  117. data/assets/javascripts/luca-ui.coffee +0 -3
  118. data/src/luca.coffee +0 -22
  119. data/src/templates/components/bootstrap_form_controls.luca +0 -7
  120. data/src/templates/components/collection_loader_view.luca +0 -5
  121. data/src/templates/components/form_alert +0 -0
  122. data/src/templates/components/form_alert.luca +0 -3
  123. data/src/templates/components/grid_view.luca +0 -7
  124. data/src/templates/components/grid_view_empty_text.luca +0 -3
  125. data/src/templates/components/load_mask.luca +0 -3
  126. data/src/templates/components/nav_bar.luca +0 -2
  127. data/src/templates/containers/basic.luca +0 -1
  128. data/src/templates/containers/tab_selector_container.luca +0 -8
  129. data/src/templates/containers/tab_view.luca +0 -2
  130. data/src/templates/containers/toolbar_wrapper.luca +0 -1
  131. data/src/templates/fields/button_field.luca +0 -2
  132. data/src/templates/fields/button_field_link.luca +0 -5
  133. data/src/templates/fields/checkbox_array.luca +0 -4
  134. data/src/templates/fields/checkbox_array_item.luca +0 -4
  135. data/src/templates/fields/checkbox_field.luca +0 -9
  136. data/src/templates/fields/file_upload_field.luca +0 -8
  137. data/src/templates/fields/hidden_field.luca +0 -1
  138. data/src/templates/fields/select_field.luca +0 -8
  139. data/src/templates/fields/text_area_field.luca +0 -8
  140. data/src/templates/fields/text_field.luca +0 -17
  141. data/src/templates/sample/contents.luca +0 -1
  142. data/src/templates/sample/welcome.luca +0 -1
  143. data/vendor/assets/javascripts/luca-spec-dependencies.js +0 -6135
  144. data/vendor/assets/javascripts/luca-ui-development-dependencies.js +0 -12845
data/src/util.coffee CHANGED
@@ -3,14 +3,26 @@
3
3
  # references on objects which don't yet exist, as strings, which get
4
4
  # evaluated at runtime when such references will be available
5
5
  Luca.util.resolve = (accessor, source_object)->
6
- source_object ||= (window || global)
7
- _( accessor.split(/\./) ).inject (obj,key)->
8
- obj = obj?[key]
9
- , source_object
6
+ try
7
+ source_object ||= (window || global)
8
+ resolved = _( accessor.split(/\./) ).inject (obj,key)->
9
+ obj = obj?[key]
10
+ , source_object
11
+ catch e
12
+ console.log "Error resolving", accessor, source_object
13
+ throw e
14
+
15
+ resolved
10
16
 
11
17
  # A better name for Luca.util.nestedValue
12
18
  Luca.util.nestedValue = Luca.util.resolve
13
19
 
20
+ Luca.util.argumentsLogger = (prompt)->
21
+ ()-> console.log prompt, arguments
22
+
23
+ Luca.util.read = (property, args...)->
24
+ if _.isFunction(property) then property.apply(@, args) else property
25
+
14
26
  # turns a word like form_view into FormView
15
27
  Luca.util.classify = (string="")->
16
28
  _.string.camelize( _.string.capitalize( string ) )
@@ -105,3 +117,4 @@ Luca.util.badge = (contents="", type, baseClass="badge")->
105
117
  cssClass = baseClass
106
118
  cssClass += " #{ baseClass }-#{ type }" if type?
107
119
  Luca.util.make("span",{class:cssClass},contents)
120
+
@@ -18,7 +18,7 @@
18
18
  };
19
19
 
20
20
  _.extend(Luca, {
21
- VERSION: "0.9.2",
21
+ VERSION: "0.9.45",
22
22
  core: {},
23
23
  containers: {},
24
24
  components: {},
@@ -55,8 +55,8 @@
55
55
  return memo;
56
56
  }, {});
57
57
 
58
- Luca.find = function() {
59
- return;
58
+ Luca.find = function(el) {
59
+ return Luca($(el).data('luca-id'));
60
60
  };
61
61
 
62
62
  Luca.supportsEvents = Luca.supportsBackboneEvents = function(obj) {
@@ -228,62 +228,96 @@
228
228
 
229
229
  }).call(this);
230
230
  (function() {
231
- var DeferredBindingProxy;
232
-
233
- DeferredBindingProxy = (function() {
234
-
235
- function DeferredBindingProxy(object, operation, wrapWithUnderscore) {
236
- var fn,
237
- _this = this;
238
- this.object = object;
239
- if (wrapWithUnderscore == null) wrapWithUnderscore = true;
240
- if (_.isFunction(operation)) {
241
- fn = operation;
242
- } else if (_.isString(operation) && _.isFunction(this.object[operation])) {
243
- fn = this.object[operation];
244
- }
245
- if (!_.isFunction(fn)) {
246
- throw "Must pass a function or a string representing one";
247
- }
248
- if (wrapWithUnderscore === true) {
249
- this.fn = function() {
250
- return _.defer(fn);
251
- };
252
- } else {
253
- this.fn = fn;
254
- }
255
- this;
256
- }
257
-
258
- DeferredBindingProxy.prototype.until = function(watch, trigger) {
259
- if ((watch != null) && !(trigger != null)) {
260
- trigger = watch;
261
- watch = this.object;
262
- }
263
- watch.once(trigger, this.fn);
264
- return this.object;
265
- };
266
-
267
- return DeferredBindingProxy;
268
-
269
- })();
270
-
271
- Luca.Events = {
272
- defer: function(operation, wrapWithUnderscore) {
273
- if (wrapWithUnderscore == null) wrapWithUnderscore = true;
274
- return new DeferredBindingProxy(this, operation, wrapWithUnderscore);
275
- },
276
- once: function(trigger, callback, context) {
277
- var onceFn;
278
- context || (context = this);
279
- onceFn = function() {
280
- callback.apply(context, arguments);
281
- return this.unbind(trigger, onceFn);
282
- };
283
- return this.bind(trigger, onceFn);
284
- }
285
- };
286
-
231
+ this.JST || (this.JST = {});
232
+ this.JST["luca-src/templates/components/bootstrap_form_controls"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="btn-group form-actions">\n <a class="btn btn-primary submit-button">\n <i class="icon icon-ok icon-white"></i>\n Save Changes\n </a>\n <a class="btn reset-button cancel-button">\n <i class="icon icon-remove"></i>\n Cancel\n </a>\n</div>\n');}return __p.join('');};
233
+ }).call(this);
234
+ (function() {
235
+ this.JST || (this.JST = {});
236
+ this.JST["luca-src/templates/components/collection_loader_view"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div id="progress-modal" class="modal" style="display: none">\n <div class="progress progress-info progress-striped active">\n <div class="bar" style="width:0%;"></div>\n </div>\n <div class="message">Initializing...</div>\n</div>\n');}return __p.join('');};
237
+ }).call(this);
238
+ (function() {
239
+ this.JST || (this.JST = {});
240
+ this.JST["luca-src/templates/components/form_alert"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="', className ,'">\n <a class="close" href="#" data-dismiss="alert">x</a>\n ', message ,'\n</div>\n');}return __p.join('');};
241
+ }).call(this);
242
+ (function() {
243
+ this.JST || (this.JST = {});
244
+ this.JST["luca-src/templates/components/grid_view"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="luca-ui-g-view-wrapper">\n <div class="g-view-header"></div>\n <div class="luca-ui-g-view-body">\n <table class="luca-ui-g-view scrollable-table" width="100%" cellpadding=0 cellspacing=0>\n <thead class="fixed"></thead>\n <tbody class="scrollable"></tbody>\n <tfoot></tfoot>\n </table>\n </div>\n <div class="luca-ui-g-view-header"></div>\n</div>\n');}return __p.join('');};
245
+ }).call(this);
246
+ (function() {
247
+ this.JST || (this.JST = {});
248
+ this.JST["luca-src/templates/components/grid_view_empty_text"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="empty-text empty-text-wrapper">\n <p>', text ,'</p>\n</div>\n');}return __p.join('');};
249
+ }).call(this);
250
+ (function() {
251
+ this.JST || (this.JST = {});
252
+ this.JST["luca-src/templates/components/load_mask"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="load-mask">\n <div class="progress progress-striped active">\n <div class="bar" style="width:0%"></div>\n </div>\n</div>\n');}return __p.join('');};
253
+ }).call(this);
254
+ (function() {
255
+ this.JST || (this.JST = {});
256
+ this.JST["luca-src/templates/components/nav_bar"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="navbar-inner">\n <div class="luca-ui-navbar-body container">\n </div>\n</div>\n');}return __p.join('');};
257
+ }).call(this);
258
+ (function() {
259
+ this.JST || (this.JST = {});
260
+ this.JST["luca-src/templates/components/pagination"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="pagination">\n <a class="btn previous">\n <i class="icon icon-chevron-left"></i>\n </a>\n <div class="pagination-group">\n </div>\n <a class="btn next">\n <i class="icon icon-chevron-right"></i>\n </a>\n</div>\n');}return __p.join('');};
261
+ }).call(this);
262
+ (function() {
263
+ this.JST || (this.JST = {});
264
+ this.JST["luca-src/templates/containers/basic"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div id="', id ,'" class="', classes ,'" style="', style ,'"></div>\n');}return __p.join('');};
265
+ }).call(this);
266
+ (function() {
267
+ this.JST || (this.JST = {});
268
+ this.JST["luca-src/templates/containers/tab_selector_container"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div id="', cid ,'-tab-selector" class="tab-selector-container">\n <ul id="', cid ,'-tabs-nav" class="nav nav-tabs">\n '); for(var i = 0; i < components.length; i++ ) { __p.push('\n '); var component = components[i];__p.push('\n <li class="tab-selector" data-target="', i ,'">\n <a data-target="', i ,'">\n ', component.title ,'\n </a>\n </li>\n '); } __p.push('\n </ul>\n</div>\n');}return __p.join('');};
269
+ }).call(this);
270
+ (function() {
271
+ this.JST || (this.JST = {});
272
+ this.JST["luca-src/templates/containers/tab_view"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<ul id="', cid ,'-tabs-selector" class="nav ', navClass ,'"></ul>\n<div id="', cid ,'-tab-view-content" class="tab-content"></div>\n');}return __p.join('');};
273
+ }).call(this);
274
+ (function() {
275
+ this.JST || (this.JST = {});
276
+ this.JST["luca-src/templates/containers/toolbar_wrapper"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="luca-ui-toolbar-wrapper" id="', id ,'"></div>\n');}return __p.join('');};
277
+ }).call(this);
278
+ (function() {
279
+ this.JST || (this.JST = {});
280
+ this.JST["luca-src/templates/fields/button_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label>&nbsp;</label>\n<input style="', inputStyles ,'" class="btn ', input_class ,'" value="', input_value ,'" type="', input_type ,'" id="<%= input_id" />\n');}return __p.join('');};
281
+ }).call(this);
282
+ (function() {
283
+ this.JST || (this.JST = {});
284
+ this.JST["luca-src/templates/fields/button_field_link"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<a class="btn ', input_class ,'">\n '); if(icon_class.length) { __p.push('\n <i class="', icon_class ,'"></i>\n ', input_value ,'\n '); } __p.push('\n</a>\n');}return __p.join('');};
285
+ }).call(this);
286
+ (function() {
287
+ this.JST || (this.JST = {});
288
+ this.JST["luca-src/templates/fields/checkbox_array"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class="control-group">\n <label for="', input_id ,'"><%= label =>\n <div class="controls"><div>\n</div>\n');}return __p.join('');};
289
+ }).call(this);
290
+ (function() {
291
+ this.JST || (this.JST = {});
292
+ this.JST["luca-src/templates/fields/checkbox_array_item"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for="', input_id ,'">\n <input id="', input_id ,'" type="checkbox" name="', input_name ,'" value="', value ,'" />\n</label>\n');}return __p.join('');};
293
+ }).call(this);
294
+ (function() {
295
+ this.JST || (this.JST = {});
296
+ this.JST["luca-src/templates/fields/checkbox_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for="', input_id ,'">\n ', label ,'\n <input type="checkbox" name="', input_name ,'" value="', input_value ,'" style="', inputStyles ,'" />\n</label>\n\n'); if(helperText) { __p.push('\n<p class="helper-text help-block">\n ', helperText ,'\n</p>\n'); } __p.push('\n');}return __p.join('');};
297
+ }).call(this);
298
+ (function() {
299
+ this.JST || (this.JST = {});
300
+ this.JST["luca-src/templates/fields/file_upload_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for="', input_id ,'">\n ', label ,'\n <input type="file" name="', input_name ,'" value="', input_value ,'" style="', inputStyles ,'" />\n</label>\n\n'); if(helperText) { __p.push('\n<p class="helper-text help-block">\n ', helperText ,'\n</p>\n'); } __p.push('\n');}return __p.join('');};
301
+ }).call(this);
302
+ (function() {
303
+ this.JST || (this.JST = {});
304
+ this.JST["luca-src/templates/fields/hidden_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(' <input type="hidden" name="', input_name ,'" value="', input_value ,'" style="', inputStyles ,'" />\n');}return __p.join('');};
305
+ }).call(this);
306
+ (function() {
307
+ this.JST || (this.JST = {});
308
+ this.JST["luca-src/templates/fields/select_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for="', input_id ,'">\n ', label ,'\n</label>\n<div class="controls">\n <select name="', input_name ,'" value="', input_value ,'" style="', inputStyles ,'" ></select>\n '); if(helperText) { __p.push('\n <p class="helper-text help-block">\n ', helperText ,'\n </p>\n '); } __p.push('\n</div>\n');}return __p.join('');};
309
+ }).call(this);
310
+ (function() {
311
+ this.JST || (this.JST = {});
312
+ this.JST["luca-src/templates/fields/text_area_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for="', input_id ,'">\n ', label ,'\n</label>\n<div class="controls">\n <textarea name="', input_name ,'" style="', inputStyles ,'" >', input_value ,'</textarea>\n '); if(helperText) { __p.push('\n <p class="helper-text help-block">\n ', helperText ,'\n </p>\n '); } __p.push('\n</div>\n');}return __p.join('');};
313
+ }).call(this);
314
+ (function() {
315
+ this.JST || (this.JST = {});
316
+ this.JST["luca-src/templates/fields/text_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(''); if(typeof(label)!=="undefined" && (typeof(hideLabel) !== "undefined" && !hideLabel) || (typeof(hideLabel)==="undefined")) {__p.push('\n<label class="control-label" for="', input_id ,'">', label ,'</label>\n'); } __p.push('\n\n<div class="controls">\n'); if( typeof(addOn) !== "undefined" ) { __p.push('\n <span class="add-on">', addOn ,'</span>\n'); } __p.push('\n<input type="text" name="', input_name ,'" style="', inputStyles ,'" value="', input_value ,'" />\n'); if(helperText) { __p.push('\n<p class="helper-text help-block">\n ', helperText ,'\n</p>\n'); } __p.push('\n\n</div>\n');}return __p.join('');};
317
+ }).call(this);
318
+ (function() {
319
+ this.JST || (this.JST = {});
320
+ this.JST["luca-src/templates/table_view"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<thead></thead>\n<tbody class="table-body"></tbody>\n<tfoot></tfoot>\n<caption></caption>\n');}return __p.join('');};
287
321
  }).call(this);
288
322
  (function() {
289
323
  var currentNamespace;
@@ -297,6 +331,12 @@
297
331
 
298
332
  Luca.util.nestedValue = Luca.util.resolve;
299
333
 
334
+ Luca.util.argumentsLogger = function(prompt) {
335
+ return function() {
336
+ return console.log(prompt, arguments);
337
+ };
338
+ };
339
+
300
340
  Luca.util.classify = function(string) {
301
341
  if (string == null) string = "";
302
342
  return _.string.camelize(_.string.capitalize(string));
@@ -371,6 +411,20 @@
371
411
 
372
412
  Luca.util.make = Backbone.View.prototype.make;
373
413
 
414
+ Luca.util.list = function(list, options, ordered) {
415
+ var container, item, _i, _len;
416
+ if (options == null) options = {};
417
+ container = ordered ? "ol" : "ul";
418
+ container = Luca.util.make(container, options);
419
+ if (_.isArray(list)) {
420
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
421
+ item = list[_i];
422
+ $(container).append(Luca.util.make("li", {}, item));
423
+ }
424
+ }
425
+ return container.outerHTML;
426
+ };
427
+
374
428
  Luca.util.label = function(contents, type, baseClass) {
375
429
  var cssClass;
376
430
  if (contents == null) contents = "";
@@ -395,7 +449,164 @@
395
449
 
396
450
  }).call(this);
397
451
  (function() {
398
- var DefineProxy;
452
+
453
+ Luca.DevelopmentToolHelpers = {
454
+ refreshCode: function() {
455
+ var view;
456
+ view = this;
457
+ _(this.eventHandlerProperties()).each(function(prop) {
458
+ return view[prop] = view.definitionClass()[prop];
459
+ });
460
+ if (this.autoBindEventHandlers === true) this.bindAllEventHandlers();
461
+ return this.delegateEvents();
462
+ },
463
+ eventHandlerProperties: function() {
464
+ var handlerIds;
465
+ handlerIds = _(this.events).values();
466
+ return _(handlerIds).select(function(v) {
467
+ return _.isString(v);
468
+ });
469
+ },
470
+ eventHandlerFunctions: function() {
471
+ var handlerIds,
472
+ _this = this;
473
+ handlerIds = _(this.events).values();
474
+ return _(handlerIds).map(function(handlerId) {
475
+ if (_.isFunction(handlerId)) {
476
+ return handlerId;
477
+ } else {
478
+ return _this[handlerId];
479
+ }
480
+ });
481
+ }
482
+ };
483
+
484
+ }).call(this);
485
+ (function() {
486
+ var DeferredBindingProxy,
487
+ __slice = Array.prototype.slice;
488
+
489
+ DeferredBindingProxy = (function() {
490
+
491
+ function DeferredBindingProxy(object, operation, wrapWithUnderscore) {
492
+ var fn;
493
+ this.object = object;
494
+ if (wrapWithUnderscore == null) wrapWithUnderscore = true;
495
+ if (_.isFunction(operation)) {
496
+ fn = operation;
497
+ } else if (_.isString(operation) && _.isFunction(this.object[operation])) {
498
+ fn = this.object[operation];
499
+ }
500
+ if (!_.isFunction(fn)) {
501
+ throw "Must pass a function or a string representing one";
502
+ }
503
+ if (wrapWithUnderscore === true) {
504
+ this.fn = _.bind(function() {
505
+ return _.defer(fn);
506
+ }, this.object);
507
+ } else {
508
+ this.fn = _.bind(fn, this.object);
509
+ }
510
+ this;
511
+ }
512
+
513
+ DeferredBindingProxy.prototype.until = function(watch, trigger) {
514
+ if ((watch != null) && !(trigger != null)) {
515
+ trigger = watch;
516
+ watch = this.object;
517
+ }
518
+ watch.once(trigger, this.fn);
519
+ return this.object;
520
+ };
521
+
522
+ return DeferredBindingProxy;
523
+
524
+ })();
525
+
526
+ Luca.Events = {
527
+ defer: function(operation, wrapWithUnderscore) {
528
+ if (wrapWithUnderscore == null) wrapWithUnderscore = true;
529
+ return new DeferredBindingProxy(this, operation, wrapWithUnderscore);
530
+ },
531
+ once: function(trigger, callback, context) {
532
+ var onceFn;
533
+ context || (context = this);
534
+ onceFn = function() {
535
+ callback.apply(context, arguments);
536
+ return this.unbind(trigger, onceFn);
537
+ };
538
+ return this.bind(trigger, onceFn);
539
+ }
540
+ };
541
+
542
+ Luca.EventsExt = {
543
+ waitUntil: function(trigger, context) {
544
+ return this.waitFor.call(this, trigger, context);
545
+ },
546
+ waitFor: function(trigger, context) {
547
+ var proxy, self;
548
+ self = this;
549
+ return proxy = {
550
+ on: function(target) {
551
+ return target.waitFor.call(target, trigger, context);
552
+ },
553
+ and: function() {
554
+ var fn, runList, _i, _len, _results;
555
+ runList = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
556
+ _results = [];
557
+ for (_i = 0, _len = runList.length; _i < _len; _i++) {
558
+ fn = runList[_i];
559
+ fn = _.isFunction(fn) ? fn : self[fn];
560
+ _results.push(self.once(trigger, fn, context));
561
+ }
562
+ return _results;
563
+ },
564
+ andThen: function() {
565
+ return self.and.apply(self, arguments);
566
+ }
567
+ };
568
+ },
569
+ relayEvent: function(trigger) {
570
+ var _this = this;
571
+ return {
572
+ on: function() {
573
+ var components;
574
+ components = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
575
+ return {
576
+ to: function() {
577
+ var component, target, targets, _i, _len, _results;
578
+ targets = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
579
+ _results = [];
580
+ for (_i = 0, _len = targets.length; _i < _len; _i++) {
581
+ target = targets[_i];
582
+ _results.push((function() {
583
+ var _j, _len2, _results2,
584
+ _this = this;
585
+ _results2 = [];
586
+ for (_j = 0, _len2 = components.length; _j < _len2; _j++) {
587
+ component = components[_j];
588
+ _results2.push(component.on(trigger, function() {
589
+ var args;
590
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
591
+ args.unshift(trigger);
592
+ return target.trigger.apply(target, args);
593
+ }));
594
+ }
595
+ return _results2;
596
+ }).call(_this));
597
+ }
598
+ return _results;
599
+ }
600
+ };
601
+ }
602
+ };
603
+ }
604
+ };
605
+
606
+ }).call(this);
607
+ (function() {
608
+ var DefineProxy,
609
+ __slice = Array.prototype.slice;
399
610
 
400
611
  Luca.define = function(componentName) {
401
612
  return new DefineProxy(componentName);
@@ -443,14 +654,44 @@
443
654
  return this;
444
655
  };
445
656
 
657
+ DefineProxy.prototype.defaultsTo = function(properties) {
658
+ if (properties != null) return this["with"](properties);
659
+ return this;
660
+ };
661
+
662
+ DefineProxy.prototype.defaults = function(properties) {
663
+ if (properties != null) return this["with"](properties);
664
+ return this;
665
+ };
666
+
667
+ DefineProxy.prototype.hasDefaultProperties = function(properties) {
668
+ if (properties != null) return this["with"](properties);
669
+ return this;
670
+ };
671
+
672
+ DefineProxy.prototype.behavesAs = function() {
673
+ var mixin, mixins, _i, _len;
674
+ mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
675
+ _.defaults(this.properties || (this.properties = {}), {
676
+ mixins: []
677
+ });
678
+ for (_i = 0, _len = mixins.length; _i < _len; _i++) {
679
+ mixin = mixins[_i];
680
+ this.properties.mixins.push(mixin);
681
+ }
682
+ return this;
683
+ };
684
+
446
685
  DefineProxy.prototype["with"] = function(properties) {
447
686
  var at, componentType, _base;
687
+ if (properties == null) properties = {};
688
+ _.defaults((this.properties || (this.properties = {})), properties);
448
689
  at = this.namespaced ? Luca.util.resolve(this.namespace, window || global) : window || global;
449
690
  if (this.namespaced && !(at != null)) {
450
691
  eval("(window||global)." + this.namespace + " = {}");
451
692
  at = Luca.util.resolve(this.namespace, window || global);
452
693
  }
453
- at[this.componentId] = Luca.extend(this.superClassName, this.componentName, properties);
694
+ at[this.componentId] = Luca.extend(this.superClassName, this.componentName, this.properties);
454
695
  if (Luca.autoRegister === true) {
455
696
  if (Luca.isViewPrototype(at[this.componentId])) componentType = "view";
456
697
  if (Luca.isCollectionPrototype(at[this.componentId])) {
@@ -469,7 +710,7 @@
469
710
  })();
470
711
 
471
712
  Luca.extend = function(superClassName, childName, properties) {
472
- var superClass;
713
+ var definition, include, superClass, _i, _len, _ref;
473
714
  if (properties == null) properties = {};
474
715
  superClass = Luca.util.resolve(superClassName, window || global);
475
716
  if (!_.isFunction(superClass != null ? superClass.extend : void 0)) {
@@ -484,39 +725,453 @@
484
725
  var _ref;
485
726
  return (_ref = this._superClass().prototype[method]) != null ? _ref.apply(context, args) : void 0;
486
727
  };
487
- return superClass.extend(properties);
728
+ definition = superClass.extend(properties);
729
+ if (_.isArray(properties != null ? properties.include : void 0)) {
730
+ _ref = properties.include;
731
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
732
+ include = _ref[_i];
733
+ if (_.isString(include)) include = Luca.util.resolve(include);
734
+ _.extend(definition.prototype, include);
735
+ }
736
+ }
737
+ return definition;
488
738
  };
489
739
 
490
- _.mixin({
491
- def: Luca.define
492
- });
740
+ Luca.mixin = function(mixinName) {
741
+ var namespace, resolved;
742
+ namespace = _(Luca.mixin.namespaces).detect(function(space) {
743
+ var _ref;
744
+ return ((_ref = Luca.util.resolve(space)) != null ? _ref[mixinName] : void 0) != null;
745
+ });
746
+ namespace || (namespace = "Luca.modules");
747
+ resolved = Luca.util.resolve(namespace)[mixinName];
748
+ if (resolved == null) {
749
+ console.log("Could not find " + mixinName + " in ", Luca.mixin.namespaces);
750
+ }
751
+ return resolved;
752
+ };
493
753
 
494
- }).call(this);
495
- (function() {
496
- var component_cache, registry;
754
+ Luca.mixin.namespaces = ["Luca.modules"];
497
755
 
498
- registry = {
499
- classes: {},
500
- model_classes: {},
501
- collection_classes: {},
502
- namespaces: ['Luca.containers', 'Luca.components']
756
+ Luca.mixin.namespace = function(namespace) {
757
+ Luca.mixin.namespaces.push(namespace);
758
+ return Luca.mixin.namespaces = _(Luca.mixin.namespaces).uniq();
503
759
  };
504
760
 
505
- component_cache = {
506
- cid_index: {},
507
- name_index: {}
761
+ Luca.decorate = function(componentPrototype) {
762
+ if (_.isString(componentPrototype)) {
763
+ componentPrototype = Luca.util.resolve(componentPrototype).prototype;
764
+ }
765
+ return {
766
+ "with": function(mixin) {
767
+ _.extend(componentPrototype, Luca.mixin(mixin));
768
+ componentPrototype.mixins || (componentPrototype.mixins = []);
769
+ componentPrototype.mixins.push(mixin);
770
+ componentPrototype.mixins = _(componentPrototype.mixins).uniq();
771
+ return componentPrototype;
772
+ }
773
+ };
508
774
  };
509
775
 
510
- Luca.defaultComponentType = 'view';
776
+ _.mixin({
777
+ def: Luca.define
778
+ });
511
779
 
512
- Luca.register = function(component, prototypeName, componentType) {
513
- if (componentType == null) componentType = "view";
514
- Luca.trigger("component:registered", component, prototypeName);
515
- switch (componentType) {
780
+ }).call(this);
781
+ (function() {
782
+
783
+ Luca.modules.Deferrable = {
784
+ configure_collection: function(setAsDeferrable) {
785
+ var collectionManager, _ref, _ref2;
786
+ if (setAsDeferrable == null) setAsDeferrable = true;
787
+ if (!this.collection) return;
788
+ if (_.isString(this.collection) && (collectionManager = (_ref = Luca.CollectionManager) != null ? _ref.get() : void 0)) {
789
+ this.collection = collectionManager.getOrCreate(this.collection);
790
+ }
791
+ if (!(this.collection && _.isFunction(this.collection.fetch) && _.isFunction(this.collection.reset))) {
792
+ this.collection = new Luca.Collection(this.collection.initial_set, this.collection);
793
+ }
794
+ if ((_ref2 = this.collection) != null ? _ref2.deferrable_trigger : void 0) {
795
+ this.deferrable_trigger = this.collection.deferrable_trigger;
796
+ }
797
+ if (setAsDeferrable) return this.deferrable = this.collection;
798
+ }
799
+ };
800
+
801
+ }).call(this);
802
+ (function() {
803
+ var FilterModel,
804
+ __hasProp = Object.prototype.hasOwnProperty,
805
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
806
+
807
+ Luca.modules.Filterable = {
808
+ _initializer: function(component, module) {
809
+ var oldOptions, oldQuery, sortBy, _ref, _ref2;
810
+ if (this.filterable === false) return;
811
+ this.filterState = this.getFilterModel();
812
+ if (oldQuery = this.getQuery) {
813
+ this.getQuery = function() {
814
+ return _.extend(oldQuery.call(this), this.filterState.toQuery());
815
+ };
816
+ }
817
+ if (oldOptions = this.getQueryOptions) {
818
+ this.getQueryOptions = function() {
819
+ return {};
820
+ return _.extend(oldOptions.call(this), this.filterState.toOptions());
821
+ };
822
+ }
823
+ if (sortBy = (_ref = this.filterable) != null ? (_ref2 = _ref.options) != null ? _ref2.sortBy : void 0 : void 0) {
824
+ return this.setSortBy(sortBy);
825
+ }
826
+ },
827
+ setSortBy: function(sortBy, options) {
828
+ if (options == null) options = {};
829
+ return this.filterState.setOption('sortBy', sortBy, options);
830
+ },
831
+ getFilterModel: function() {
832
+ if (this.filterState != null) return this.filterState;
833
+ this.filterState = new FilterModel(this.filterable || (this.filterable = {}));
834
+ this.filterState.on("change", function() {
835
+ return this.trigger("collection:change");
836
+ }, this);
837
+ return this.filterState;
838
+ },
839
+ applyFilter: function(query, options) {
840
+ var silent;
841
+ if (query == null) query = {};
842
+ if (options == null) options = {};
843
+ if (_.isEmpty(options)) {
844
+ options = _.defaults(options, this.getQueryOptions());
845
+ }
846
+ if (_.isEmpty(query)) query = _.defaults(query, this.getQuery());
847
+ silent = _(options)["delete"]('silent') === true;
848
+ return this.filterState.set({
849
+ query: query,
850
+ options: options
851
+ }, {
852
+ silent: silent
853
+ });
854
+ }
855
+ };
856
+
857
+ FilterModel = (function(_super) {
858
+
859
+ __extends(FilterModel, _super);
860
+
861
+ function FilterModel() {
862
+ FilterModel.__super__.constructor.apply(this, arguments);
863
+ }
864
+
865
+ FilterModel.prototype.setOption = function(option, value, options) {
866
+ var payload;
867
+ payload = {};
868
+ payload[option] = value;
869
+ return this.set('options', _.extend(this.toOptions(), payload), options);
870
+ };
871
+
872
+ FilterModel.prototype.setQueryOption = function(option, value, options) {
873
+ var payload;
874
+ payload = {};
875
+ payload[option] = value;
876
+ return this.set('query', _.extend(this.toQuery(), payload), options);
877
+ };
878
+
879
+ FilterModel.prototype.toOptions = function() {
880
+ return this.get("options");
881
+ };
882
+
883
+ FilterModel.prototype.toQuery = function() {
884
+ return this.get("query");
885
+ };
886
+
887
+ return FilterModel;
888
+
889
+ })(Backbone.Model);
890
+
891
+ }).call(this);
892
+ (function() {
893
+
894
+ Luca.modules.GridLayout = {
895
+ _initializer: function() {
896
+ if (this.gridSpan) this.$el.addClass("span" + this.gridSpan);
897
+ if (this.gridOffset) this.$el.addClass("offset" + this.gridOffset);
898
+ if (this.gridRowFluid) this.$el.addClass("row-fluid");
899
+ if (this.gridRow) return this.$el.addClass("row");
900
+ }
901
+ };
902
+
903
+ }).call(this);
904
+ (function() {
905
+
906
+ Luca.modules.LoadMaskable = {
907
+ _initializer: function() {
908
+ var _this = this;
909
+ if (this.loadMask !== true) return;
910
+ if (this.loadMask === true) {
911
+ this.defer(function() {
912
+ _this.$el.addClass('with-mask');
913
+ if (_this.$('.load-mask').length === 0) {
914
+ _this.loadMaskTarget().prepend(Luca.template(_this.loadMaskTemplate, _this));
915
+ return _this.$('.load-mask').hide();
916
+ }
917
+ }).until("after:render");
918
+ this.on(this.loadmaskEnableEvent || "enable:loadmask", this.applyLoadMask, this);
919
+ return this.on(this.loadmaskDisableEvent || "disable:loadmask", this.applyLoadMask, this);
920
+ }
921
+ },
922
+ showLoadMask: function() {
923
+ return this.trigger("enable:loadmask");
924
+ },
925
+ hideLoadMask: function() {
926
+ return this.trigger("disable:loadmask");
927
+ },
928
+ loadMaskTarget: function() {
929
+ if (this.loadMaskEl != null) {
930
+ return this.$(this.loadMaskEl);
931
+ } else {
932
+ return this.$bodyEl();
933
+ }
934
+ },
935
+ disableLoadMask: function() {
936
+ this.$('.load-mask .bar').css("width", "100%");
937
+ this.$('.load-mask').hide();
938
+ return clearInterval(this.loadMaskInterval);
939
+ },
940
+ enableLoadMask: function() {
941
+ var maxWidth,
942
+ _this = this;
943
+ this.$('.load-mask').show().find('.bar').css("width", "0%");
944
+ maxWidth = this.$('.load-mask .progress').width();
945
+ if (maxWidth < 20 && (maxWidth = this.$el.width()) < 20) {
946
+ maxWidth = this.$el.parent().width();
947
+ }
948
+ this.loadMaskInterval = setInterval(function() {
949
+ var currentWidth, newWidth;
950
+ currentWidth = _this.$('.load-mask .bar').width();
951
+ newWidth = currentWidth + 12;
952
+ return _this.$('.load-mask .bar').css('width', newWidth);
953
+ }, 200);
954
+ if (this.loadMaskTimeout == null) return;
955
+ return _.delay(function() {
956
+ return _this.disableLoadMask();
957
+ }, this.loadMaskTimeout);
958
+ },
959
+ applyLoadMask: function() {
960
+ if (this.$('.load-mask').is(":visible")) {
961
+ return this.disableLoadMask();
962
+ } else {
963
+ return this.enableLoadMask();
964
+ }
965
+ }
966
+ };
967
+
968
+ }).call(this);
969
+ (function() {
970
+
971
+ Luca.LocalStore = (function() {
972
+
973
+ function LocalStore(name) {
974
+ var store;
975
+ this.name = name;
976
+ store = localStorage.getItem(this.name);
977
+ this.data = (store && JSON.parse(store)) || {};
978
+ }
979
+
980
+ LocalStore.prototype.guid = function() {
981
+ var S4;
982
+ S4 = function() {
983
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
984
+ };
985
+ return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
986
+ };
987
+
988
+ LocalStore.prototype.save = function() {
989
+ return localStorage.setItem(this.name, JSON.stringify(this.data));
990
+ };
991
+
992
+ LocalStore.prototype.create = function(model) {
993
+ if (!model.id) model.id = model.attribtues.id = this.guid();
994
+ this.data[model.id] = model;
995
+ this.save();
996
+ return model;
997
+ };
998
+
999
+ LocalStore.prototype.update = function(model) {
1000
+ this.data[model.id] = model;
1001
+ this.save();
1002
+ return model;
1003
+ };
1004
+
1005
+ LocalStore.prototype.find = function(model) {
1006
+ return this.data[model.id];
1007
+ };
1008
+
1009
+ LocalStore.prototype.findAll = function() {
1010
+ return _.values(this.data);
1011
+ };
1012
+
1013
+ LocalStore.prototype.destroy = function(model) {
1014
+ delete this.data[model.id];
1015
+ this.save();
1016
+ return model;
1017
+ };
1018
+
1019
+ return LocalStore;
1020
+
1021
+ })();
1022
+
1023
+ Backbone.LocalSync = function(method, model, options) {
1024
+ var resp, store;
1025
+ store = model.localStorage || model.collection.localStorage;
1026
+ resp = (function() {
1027
+ switch (method) {
1028
+ case "read":
1029
+ if (model.id) {
1030
+ return store.find(model);
1031
+ } else {
1032
+ return store.findAll();
1033
+ }
1034
+ case "create":
1035
+ return store.create(model);
1036
+ case "update":
1037
+ return store.update(model);
1038
+ case "delete":
1039
+ return store.destroy(model);
1040
+ }
1041
+ })();
1042
+ if (resp) {
1043
+ return options.success(resp);
1044
+ } else {
1045
+ return options.error("Record not found");
1046
+ }
1047
+ };
1048
+
1049
+ }).call(this);
1050
+ (function() {
1051
+
1052
+ Luca.modules.Paginatable = {
1053
+ paginatorViewClass: 'Luca.components.PaginationControl',
1054
+ _initializer: function() {
1055
+ var old;
1056
+ if (this.paginatable === false) return;
1057
+ _.bindAll(this, "paginationControl");
1058
+ this.getCollection || (this.getCollection = function() {
1059
+ return this.collection;
1060
+ });
1061
+ if (old = this.getQueryOptions) {
1062
+ this.getQueryOptions = function() {
1063
+ var filtered, p;
1064
+ p = this.paginationControl();
1065
+ filtered = _.extend(old.call(this), {
1066
+ limit: p.limit(),
1067
+ page: p.page()
1068
+ });
1069
+ return filtered;
1070
+ };
1071
+ }
1072
+ if (this.paginationContainer().length === 0) {
1073
+ return this.$bodyEl().after(this.make("div", {
1074
+ "class": "toolbar bottom"
1075
+ }));
1076
+ }
1077
+ },
1078
+ paginationContainer: function() {
1079
+ return this.$('.toolbar.bottom');
1080
+ },
1081
+ setCurrentPage: function(page, options) {
1082
+ if (page == null) page = 1;
1083
+ if (options == null) options = {};
1084
+ return this.paginationControl().state.set('page', page, options);
1085
+ },
1086
+ setLimit: function(limit, options) {
1087
+ if (limit == null) limit = 0;
1088
+ if (options == null) options = {};
1089
+ return this.paginationControl().state.set('limit', limit, options);
1090
+ },
1091
+ updatePagination: function(models, query, options) {
1092
+ var itemCount, paginator, totalCount, _ref;
1093
+ if (models == null) models = [];
1094
+ if (query == null) query = {};
1095
+ if (options == null) options = {};
1096
+ _.defaults(options, this.getQueryOptions(), {
1097
+ limit: 0
1098
+ });
1099
+ paginator = this.paginationControl();
1100
+ itemCount = (models != null ? models.length : void 0) || 0;
1101
+ totalCount = (_ref = this.getCollection()) != null ? _ref.length : void 0;
1102
+ if (itemCount === 0 || totalCount <= options.limit) {
1103
+ paginator.$el.hide();
1104
+ } else {
1105
+ paginator.$el.show();
1106
+ }
1107
+ return paginator.state.set({
1108
+ page: options.page,
1109
+ limit: options.limit
1110
+ });
1111
+ },
1112
+ paginationControl: function() {
1113
+ if (this.paginator != null) return this.paginator;
1114
+ _.defaults(this.paginatable || (this.paginatable = {}), {
1115
+ page: 1,
1116
+ limit: 20
1117
+ });
1118
+ this.paginator = Luca.util.lazyComponent({
1119
+ type: "pagination_control",
1120
+ collection: this.getCollection(),
1121
+ parent: this
1122
+ });
1123
+ this.paginator.setPage(this.paginatable.page);
1124
+ this.paginator.setLimit(this.paginatable.limit);
1125
+ this.paginator.state.on("change", function() {
1126
+ return this.trigger("collection:change");
1127
+ }, this);
1128
+ this.on("after:refresh", this.updatePagination, this);
1129
+ this.paginationContainer().append(this.paginator.render().$el);
1130
+ return this.paginator;
1131
+ }
1132
+ };
1133
+
1134
+ }).call(this);
1135
+ (function() {
1136
+ var component_cache, registry;
1137
+
1138
+ registry = {
1139
+ classes: {},
1140
+ model_classes: {},
1141
+ collection_classes: {},
1142
+ namespaces: ['Luca.containers', 'Luca.components']
1143
+ };
1144
+
1145
+ component_cache = {
1146
+ cid_index: {},
1147
+ name_index: {}
1148
+ };
1149
+
1150
+ Luca.defaultComponentType = 'view';
1151
+
1152
+ Luca.registry.aliases = {
1153
+ grid: "grid_view",
1154
+ form: "form_view",
1155
+ text: "text_field",
1156
+ button: "button_field",
1157
+ select: "select_field",
1158
+ card: "card_view",
1159
+ paged: "card_view",
1160
+ wizard: "card_view",
1161
+ collection: "collection_view",
1162
+ list: "collection_view",
1163
+ multi: "collection_multi_view",
1164
+ table: "table_view"
1165
+ };
1166
+
1167
+ Luca.register = function(component, prototypeName, componentType) {
1168
+ if (componentType == null) componentType = "view";
1169
+ Luca.trigger("component:registered", component, prototypeName);
1170
+ switch (componentType) {
516
1171
  case "model":
517
1172
  return registry.model_classes[component] = prototypeName;
518
1173
  case "collection":
519
- return registry.model_classes[component] = prototypeName;
1174
+ return registry.collection_classes[component] = prototypeName;
520
1175
  default:
521
1176
  return registry.classes[component] = prototypeName;
522
1177
  }
@@ -536,7 +1191,7 @@
536
1191
  return Luca.register(component, prototypeName);
537
1192
  };
538
1193
 
539
- Luca.registry.addNamespace = function(identifier) {
1194
+ Luca.registry.addNamespace = Luca.registry.namespace = function(identifier) {
540
1195
  registry.namespaces.push(identifier);
541
1196
  return registry.namespaces = _(registry.namespaces).uniq();
542
1197
  };
@@ -553,7 +1208,8 @@
553
1208
  };
554
1209
 
555
1210
  Luca.registry.lookup = function(ctype) {
556
- var c, className, fullPath, parents, _ref;
1211
+ var alias, c, className, fullPath, parents, _ref;
1212
+ if (alias = Luca.registry.aliases[ctype]) ctype = alias;
557
1213
  c = registry.classes[ctype];
558
1214
  if (c != null) return c;
559
1215
  className = Luca.util.classify(ctype);
@@ -563,9 +1219,13 @@
563
1219
  }).compact().value()) != null ? _ref[0] : void 0;
564
1220
  };
565
1221
 
1222
+ Luca.registry.instances = function() {
1223
+ return _(component_cache.cid_index).values();
1224
+ };
1225
+
566
1226
  Luca.registry.findInstancesByClassName = function(className) {
567
1227
  var instances;
568
- instances = _(component_cache.cid_index).values();
1228
+ instances = Luca.registry.instances();
569
1229
  return _(instances).select(function(instance) {
570
1230
  var _ref;
571
1231
  return instance.displayName === className || (typeof instance._superClass === "function" ? (_ref = instance._superClass()) != null ? _ref.displayName : void 0 : void 0) === className;
@@ -591,10 +1251,8 @@
591
1251
  if (component != null) component_cache.cid_index[needle] = component;
592
1252
  component = component_cache.cid_index[needle];
593
1253
  if ((component != null ? component.component_name : void 0) != null) {
594
- Luca.trigger("component:created:" + component.component_name, component);
595
1254
  component_cache.name_index[component.component_name] = component.cid;
596
1255
  } else if ((component != null ? component.name : void 0) != null) {
597
- Luca.trigger("component:created:" + component.component_name, component);
598
1256
  component_cache.name_index[component.name] = component.cid;
599
1257
  }
600
1258
  if (component != null) return component;
@@ -604,60 +1262,84 @@
604
1262
 
605
1263
  }).call(this);
606
1264
  (function() {
607
- var customizeRender, originalExtend;
1265
+ var __slice = Array.prototype.slice;
608
1266
 
609
- _.def("Luca.View")["extends"]("Backbone.View")["with"]({
610
- include: ['Luca.Events'],
611
- additionalClassNames: [],
612
- hooks: ["after:initialize", "before:render", "after:render", "first:activation", "activation", "deactivation"],
613
- debug: function() {
614
- var message, _i, _len, _results;
615
- if (!(this.debugMode || (window.LucaDebugMode != null))) return;
616
- _results = [];
617
- for (_i = 0, _len = arguments.length; _i < _len; _i++) {
618
- message = arguments[_i];
619
- _results.push(console.log([this.name || this.cid, message]));
620
- }
621
- return _results;
622
- },
623
- trigger: function() {
624
- if (Luca.enableGlobalObserver) {
625
- if (Luca.developmentMode === true || this.observeEvents === true) {
626
- Luca.ViewObserver || (Luca.ViewObserver = new Luca.Observer({
627
- type: "view"
628
- }));
629
- Luca.ViewObserver.relay(this, arguments);
630
- }
1267
+ Luca.Observer = (function() {
1268
+
1269
+ function Observer(options) {
1270
+ var _this = this;
1271
+ this.options = options != null ? options : {};
1272
+ _.extend(this, Backbone.Events);
1273
+ this.type = this.options.type;
1274
+ if (this.options.debugAll) {
1275
+ this.bind("all", function(trigger, one, two) {
1276
+ return console.log("ALL", trigger, one, two);
1277
+ });
631
1278
  }
632
- return Backbone.View.prototype.trigger.apply(this, arguments);
633
- },
1279
+ }
1280
+
1281
+ Observer.prototype.relay = function() {
1282
+ var args, triggerer;
1283
+ triggerer = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
1284
+ console.log("Relaying", trigger, args);
1285
+ this.trigger("event", triggerer, args);
1286
+ return this.trigger("event:" + args[0], triggerer, args.slice(1));
1287
+ };
1288
+
1289
+ return Observer;
1290
+
1291
+ })();
1292
+
1293
+ Luca.Observer.enableObservers = function(options) {
1294
+ if (options == null) options = {};
1295
+ Luca.enableGlobalObserver = true;
1296
+ Luca.ViewObserver = new Luca.Observer(_.extend(options, {
1297
+ type: "view"
1298
+ }));
1299
+ return Luca.CollectionObserver = new Luca.Observer(_.extend(options, {
1300
+ type: "collection"
1301
+ }));
1302
+ };
1303
+
1304
+ }).call(this);
1305
+ (function() {
1306
+ var bindAllEventHandlers, registerApplicationEvents, registerCollectionEvents, setupBodyTemplate, setupClassHelpers, setupStateMachine, setupTemplate;
1307
+
1308
+ _.def("Luca.View")["extends"]("Backbone.View")["with"]({
1309
+ include: ['Luca.Events'],
1310
+ additionalClassNames: [],
1311
+ hooks: ["before:initialize", "after:initialize", "before:render", "after:render", "first:activation", "activation", "deactivation"],
634
1312
  initialize: function(options) {
635
- var additional, template, unique, _i, _len, _ref;
1313
+ var module, _i, _len, _ref, _ref2, _ref3;
636
1314
  this.options = options != null ? options : {};
1315
+ this.trigger("before:initialize", this, this.options);
637
1316
  _.extend(this, this.options);
638
- if (this.name != null) this.cid = _.uniqueId(this.name);
639
- if (template = this.bodyTemplate) {
640
- this.$el.empty();
641
- Luca.View.prototype.$html.call(this, Luca.template(template, this));
1317
+ if (this.autoBindEventHandlers === true || this.bindAllEvents === true) {
1318
+ bindAllEventHandlers.call(this);
642
1319
  }
1320
+ setupBodyTemplate.call(this);
1321
+ if (this.name != null) this.cid = _.uniqueId(this.name);
1322
+ this.$el.attr("data-luca-id", this.name || this.cid);
643
1323
  Luca.cache(this.cid, this);
644
- unique = _(Luca.View.prototype.hooks.concat(this.hooks)).uniq();
645
- this.setupHooks(unique);
646
- if (this.autoBindEventHandlers === true) this.bindAllEventHandlers();
647
- if (this.additionalClassNames) {
648
- if (_.isString(this.additionalClassNames)) {
649
- this.additionalClassNames = this.additionalClassNames.split(" ");
650
- }
651
- _ref = this.additionalClassNames;
652
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
653
- additional = _ref[_i];
654
- this.$el.addClass(additional);
1324
+ this.setupHooks(_(Luca.View.prototype.hooks.concat(this.hooks)).uniq());
1325
+ setupClassHelpers.call(this);
1326
+ if (this.stateful === true && !(this.state != null)) {
1327
+ setupStateMachine.call(this);
1328
+ }
1329
+ registerCollectionEvents.call(this);
1330
+ registerApplicationEvents.call(this);
1331
+ if (((_ref = this.mixins) != null ? _ref.length : void 0) > 0) {
1332
+ _ref2 = _.uniq(this.mixins);
1333
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
1334
+ module = _ref2[_i];
1335
+ if ((_ref3 = Luca.mixin(module)) != null) {
1336
+ _ref3._initializer.call(this, this, module);
1337
+ }
655
1338
  }
656
1339
  }
657
- if (this.wrapperClass != null) this.$wrap(this.wrapperClass);
658
- this.trigger("after:initialize", this);
659
- this.registerCollectionEvents();
660
- return this.delegateEvents();
1340
+ this.delegateEvents();
1341
+ if (this.template && !this.isField) setupTemplate.call(this);
1342
+ return this.trigger("after:initialize", this);
661
1343
  },
662
1344
  $wrap: function(wrapper) {
663
1345
  if (_.isString(wrapper) && !wrapper.match(/[<>]/)) {
@@ -680,6 +1362,9 @@
680
1362
  $attach: function() {
681
1363
  return this.$container().append(this.el);
682
1364
  },
1365
+ $bodyEl: function() {
1366
+ return this.$el;
1367
+ },
683
1368
  $container: function() {
684
1369
  return $(this.container);
685
1370
  },
@@ -699,72 +1384,15 @@
699
1384
  return _this.bind(eventId, callback);
700
1385
  });
701
1386
  },
702
- getCollectionManager: function() {
703
- var _base;
704
- return this.collectionManager || (typeof (_base = Luca.CollectionManager).get === "function" ? _base.get() : void 0);
705
- },
706
- registerCollectionEvents: function() {
707
- var manager,
708
- _this = this;
709
- manager = this.getCollectionManager();
710
- return _(this.collectionEvents).each(function(handler, signature) {
711
- var collection, event, key, _ref;
712
- _ref = signature.split(" "), key = _ref[0], event = _ref[1];
713
- collection = _this["" + key + "Collection"] = manager.getOrCreate(key);
714
- if (!collection) throw "Could not find collection specified by " + key;
715
- if (_.isString(handler)) handler = _this[handler];
716
- if (!_.isFunction(handler)) throw "invalid collectionEvents configuration";
717
- try {
718
- return collection.bind(event, handler);
719
- } catch (e) {
720
- console.log("Error Binding To Collection in registerCollectionEvents", _this);
721
- throw e;
722
- }
723
- });
724
- },
725
1387
  registerEvent: function(selector, handler) {
726
1388
  this.events || (this.events = {});
727
1389
  this.events[selector] = handler;
728
1390
  return this.delegateEvents();
729
1391
  },
730
- bindAllEventHandlers: function() {
731
- var _this = this;
732
- return _(this.events).each(function(handler, event) {
733
- if (_.isString(handler)) return _.bindAll(_this, handler);
734
- });
735
- },
736
1392
  definitionClass: function() {
737
1393
  var _ref;
738
1394
  return (_ref = Luca.util.resolve(this.displayName, window)) != null ? _ref.prototype : void 0;
739
1395
  },
740
- refreshCode: function() {
741
- var view;
742
- view = this;
743
- _(this.eventHandlerProperties()).each(function(prop) {
744
- return view[prop] = view.definitionClass()[prop];
745
- });
746
- if (this.autoBindEventHandlers === true) this.bindAllEventHandlers();
747
- return this.delegateEvents();
748
- },
749
- eventHandlerProperties: function() {
750
- var handlerIds;
751
- handlerIds = _(this.events).values();
752
- return _(handlerIds).select(function(v) {
753
- return _.isString(v);
754
- });
755
- },
756
- eventHandlerFunctions: function() {
757
- var handlerIds,
758
- _this = this;
759
- handlerIds = _(this.events).values();
760
- return _(handlerIds).map(function(handlerId) {
761
- if (_.isFunction(handlerId)) {
762
- return handlerId;
763
- } else {
764
- return _this[handlerId];
765
- }
766
- });
767
- },
768
1396
  collections: function() {
769
1397
  return Luca.util.selectProperties(Luca.isBackboneCollection, this);
770
1398
  },
@@ -773,12 +1401,33 @@
773
1401
  },
774
1402
  views: function() {
775
1403
  return Luca.util.selectProperties(Luca.isBackboneView, this);
1404
+ },
1405
+ debug: function() {
1406
+ var message, _i, _len, _results;
1407
+ if (!(this.debugMode || (window.LucaDebugMode != null))) return;
1408
+ _results = [];
1409
+ for (_i = 0, _len = arguments.length; _i < _len; _i++) {
1410
+ message = arguments[_i];
1411
+ _results.push(console.log([this.name || this.cid, message]));
1412
+ }
1413
+ return _results;
1414
+ },
1415
+ trigger: function() {
1416
+ if (Luca.enableGlobalObserver) {
1417
+ if (Luca.developmentMode === true || this.observeEvents === true) {
1418
+ Luca.ViewObserver || (Luca.ViewObserver = new Luca.Observer({
1419
+ type: "view"
1420
+ }));
1421
+ Luca.ViewObserver.relay(this, arguments);
1422
+ }
1423
+ }
1424
+ return Backbone.View.prototype.trigger.apply(this, arguments);
776
1425
  }
777
1426
  });
778
1427
 
779
- originalExtend = Backbone.View.extend;
1428
+ Luca.View._originalExtend = Backbone.View.extend;
780
1429
 
781
- customizeRender = function(definition) {
1430
+ Luca.View.renderWrapper = function(definition) {
782
1431
  var _base;
783
1432
  _base = definition.render;
784
1433
  _base || (_base = Luca.View.prototype.$attach);
@@ -792,7 +1441,7 @@
792
1441
  this.deferrable = this.collection;
793
1442
  }
794
1443
  target || (target = this.deferrable);
795
- trigger = this.deferrable_event ? this.deferrable_event : "reset";
1444
+ trigger = this.deferrable_event ? this.deferrable_event : Luca.View.deferrableEvent;
796
1445
  deferred = function() {
797
1446
  _base.call(view);
798
1447
  return view.trigger("after:render", view);
@@ -820,11 +1469,126 @@
820
1469
  return definition;
821
1470
  };
822
1471
 
1472
+ bindAllEventHandlers = function() {
1473
+ var _this = this;
1474
+ return _(this.events).each(function(handler, event) {
1475
+ if (_.isString(handler)) return _.bindAll(_this, handler);
1476
+ });
1477
+ };
1478
+
1479
+ registerApplicationEvents = function() {
1480
+ var app, eventTrigger, handler, _len, _ref, _ref2, _results;
1481
+ if (_.isEmpty(this.applicationEvents)) return;
1482
+ app = this.app;
1483
+ if (_.isString(app) || _.isUndefined(app)) {
1484
+ app = (_ref = Luca.Application) != null ? typeof _ref.get === "function" ? _ref.get(app) : void 0 : void 0;
1485
+ }
1486
+ if (!Luca.supportsEvents(app)) {
1487
+ throw "Error binding to the application object on " + (this.name || this.cid);
1488
+ }
1489
+ _ref2 = this.applicationEvents;
1490
+ _results = [];
1491
+ for (handler = 0, _len = _ref2.length; handler < _len; handler++) {
1492
+ eventTrigger = _ref2[handler];
1493
+ if (_.isString(handler)) handler = this[handler];
1494
+ if (!_.isFunction(handler)) {
1495
+ throw "Error registering application event " + eventTrigger + " on " + (this.name || this.cid);
1496
+ }
1497
+ _results.push(app.on(eventTrigger, handler));
1498
+ }
1499
+ return _results;
1500
+ };
1501
+
1502
+ registerCollectionEvents = function() {
1503
+ var collection, eventTrigger, handler, key, manager, signature, _ref, _ref2, _results;
1504
+ if (_.isEmpty(this.collectionEvents)) return;
1505
+ manager = this.collectionManager;
1506
+ if (_.isString(manager) || _.isUndefined(manager)) {
1507
+ manager = Luca.CollectionManager.get(manager);
1508
+ }
1509
+ _ref = this.collectionEvents;
1510
+ _results = [];
1511
+ for (signature in _ref) {
1512
+ handler = _ref[signature];
1513
+ _ref2 = signature.split(" "), key = _ref2[0], eventTrigger = _ref2[1];
1514
+ collection = manager.getOrCreate(key);
1515
+ if (!collection) throw "Could not find collection specified by " + key;
1516
+ if (_.isString(handler)) handler = this[handler];
1517
+ if (!_.isFunction(handler)) throw "invalid collectionEvents configuration";
1518
+ try {
1519
+ _results.push(collection.bind(eventTrigger, handler));
1520
+ } catch (e) {
1521
+ console.log("Error Binding To Collection in registerCollectionEvents", this);
1522
+ throw e;
1523
+ }
1524
+ }
1525
+ return _results;
1526
+ };
1527
+
1528
+ setupClassHelpers = function() {
1529
+ var additional, additionalClasses, _i, _len, _results;
1530
+ additionalClasses = _(this.additionalClassNames || []).clone();
1531
+ if (this.wrapperClass != null) this.$wrap(this.wrapperClass);
1532
+ if (_.isString(additionalClasses)) {
1533
+ additionalClasses = additionalClasses.split(" ");
1534
+ }
1535
+ if (this.gridSpan) additionalClasses.push("span" + this.gridSpan);
1536
+ if (this.gridOffset) additionalClasses.push("offset" + this.gridOffset);
1537
+ if (this.gridRowFluid) additionalClasses.push("row-fluid");
1538
+ if (this.gridRow) additionalClasses.push("row");
1539
+ if (additionalClasses == null) return;
1540
+ _results = [];
1541
+ for (_i = 0, _len = additionalClasses.length; _i < _len; _i++) {
1542
+ additional = additionalClasses[_i];
1543
+ _results.push(this.$el.addClass(additional));
1544
+ }
1545
+ return _results;
1546
+ };
1547
+
1548
+ setupStateMachine = function() {
1549
+ var _this = this;
1550
+ this.state = new Backbone.Model(this.defaultState || {});
1551
+ this.set || (this.set = function() {
1552
+ return _this.state.set.apply(_this.state, arguments);
1553
+ });
1554
+ return this.get || (this.get = function() {
1555
+ return _this.state.get.apply(_this.state, arguments);
1556
+ });
1557
+ };
1558
+
1559
+ setupBodyTemplate = function() {
1560
+ var template, templateVars;
1561
+ templateVars = this.bodyTemplateVars ? this.bodyTemplateVars.call(this) : this;
1562
+ if (template = this.bodyTemplate) {
1563
+ this.$el.empty();
1564
+ return Luca.View.prototype.$html.call(this, Luca.template(template, templateVars));
1565
+ }
1566
+ };
1567
+
1568
+ setupTemplate = function() {
1569
+ var _this = this;
1570
+ if (this.template != null) {
1571
+ return this.defer(function() {
1572
+ return _this.$template(_this.template, _this);
1573
+ }).until("before:render");
1574
+ }
1575
+ };
1576
+
823
1577
  Luca.View.extend = function(definition) {
824
- definition = customizeRender(definition);
825
- return originalExtend.call(this, definition);
1578
+ var module, _i, _len, _ref;
1579
+ definition = Luca.View.renderWrapper(definition);
1580
+ if ((definition.mixins != null) && _.isArray(definition.mixins)) {
1581
+ _ref = definition.mixins;
1582
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1583
+ module = _ref[_i];
1584
+ Luca.decorate(definition)["with"](module);
1585
+ }
1586
+ }
1587
+ return Luca.View._originalExtend.call(this, definition);
826
1588
  };
827
1589
 
1590
+ Luca.View.deferrableEvent = "reset";
1591
+
828
1592
  }).call(this);
829
1593
  (function() {
830
1594
  var setupComputedProperties;
@@ -841,6 +1605,7 @@
841
1605
  this.on("change:" + attr, function() {
842
1606
  return _this._computed[attr] = _this[attr].call(_this);
843
1607
  });
1608
+ if (_.isString(dependencies)) dependencies = dependencies.split(',');
844
1609
  _results.push(_(dependencies).each(function(dep) {
845
1610
  _this.on("change:" + dep, function() {
846
1611
  return _this.trigger("change:" + attr);
@@ -1234,60 +1999,10 @@
1234
1999
  loadMask: false,
1235
2000
  loadMaskTemplate: ["components/load_mask"],
1236
2001
  loadMaskTimeout: 3000,
2002
+ mixins: ["LoadMaskable"],
1237
2003
  initialize: function(options) {
1238
- var _this = this;
1239
2004
  this.options = options != null ? options : {};
1240
- Luca.View.prototype.initialize.apply(this, arguments);
1241
- _.bindAll(this, "applyLoadMask", "disableLoadMask");
1242
- if (this.loadMask === true) {
1243
- this.defer(function() {
1244
- _this.$el.addClass('with-mask');
1245
- if (_this.$('.load-mask').length === 0) {
1246
- _this.loadMaskTarget().prepend(Luca.template(_this.loadMaskTemplate, _this));
1247
- return _this.$('.load-mask').hide();
1248
- }
1249
- }).until("after:render");
1250
- this.on("enable:loadmask", this.applyLoadMask);
1251
- return this.on("disable:loadmask", this.applyLoadMask);
1252
- }
1253
- },
1254
- loadMaskTarget: function() {
1255
- if (this.loadMaskEl != null) {
1256
- return this.$(this.loadMaskEl);
1257
- } else {
1258
- return this.$bodyEl();
1259
- }
1260
- },
1261
- disableLoadMask: function() {
1262
- this.$('.load-mask .bar').css("width", "100%");
1263
- this.$('.load-mask').hide();
1264
- return clearInterval(this.loadMaskInterval);
1265
- },
1266
- enableLoadMask: function() {
1267
- var maxWidth,
1268
- _this = this;
1269
- this.$('.load-mask').show().find('.bar').css("width", "0%");
1270
- maxWidth = this.$('.load-mask .progress').width();
1271
- if (maxWidth < 20 && (maxWidth = this.$el.width()) < 20) {
1272
- maxWidth = this.$el.parent().width();
1273
- }
1274
- this.loadMaskInterval = setInterval(function() {
1275
- var currentWidth, newWidth;
1276
- currentWidth = _this.$('.load-mask .bar').width();
1277
- newWidth = currentWidth + 12;
1278
- return _this.$('.load-mask .bar').css('width', newWidth);
1279
- }, 200);
1280
- if (this.loadMaskTimeout == null) return;
1281
- return _.delay(function() {
1282
- return _this.disableLoadMask();
1283
- }, this.loadMaskTimeout);
1284
- },
1285
- applyLoadMask: function() {
1286
- if (this.$('.load-mask').is(":visible")) {
1287
- return this.disableLoadMask();
1288
- } else {
1289
- return this.enableLoadMask();
1290
- }
2005
+ return Luca.View.prototype.initialize.apply(this, arguments);
1291
2006
  },
1292
2007
  applyStyles: function(styles, body) {
1293
2008
  var setting, target, value;
@@ -1338,6 +2053,9 @@
1338
2053
  if (variables == null) variables = {};
1339
2054
  return this.$html(Luca.template(template, variables));
1340
2055
  },
2056
+ $empty: function() {
2057
+ return this.$bodyEl().empty();
2058
+ },
1341
2059
  $html: function(content) {
1342
2060
  return this.$bodyEl().html(content);
1343
2061
  },
@@ -1365,260 +2083,26 @@
1365
2083
  }).call(this);
1366
2084
  (function() {
1367
2085
 
1368
- Luca.modules.Deferrable = {
1369
- configure_collection: function(setAsDeferrable) {
1370
- var collectionManager, _ref, _ref2;
1371
- if (setAsDeferrable == null) setAsDeferrable = true;
1372
- if (!this.collection) return;
1373
- if (_.isString(this.collection) && (collectionManager = (_ref = Luca.CollectionManager) != null ? _ref.get() : void 0)) {
1374
- this.collection = collectionManager.getOrCreate(this.collection);
1375
- }
1376
- if (!(this.collection && _.isFunction(this.collection.fetch) && _.isFunction(this.collection.reset))) {
1377
- this.collection = new Luca.Collection(this.collection.initial_set, this.collection);
1378
- }
1379
- if ((_ref2 = this.collection) != null ? _ref2.deferrable_trigger : void 0) {
1380
- this.deferrable_trigger = this.collection.deferrable_trigger;
1381
- }
1382
- if (setAsDeferrable) return this.deferrable = this.collection;
1383
- }
1384
- };
1385
-
1386
- }).call(this);
1387
- (function() {
1388
-
1389
- Luca.LocalStore = (function() {
1390
-
1391
- function LocalStore(name) {
1392
- var store;
1393
- this.name = name;
1394
- store = localStorage.getItem(this.name);
1395
- this.data = (store && JSON.parse(store)) || {};
1396
- }
1397
-
1398
- LocalStore.prototype.guid = function() {
1399
- var S4;
1400
- S4 = function() {
1401
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
1402
- };
1403
- return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
1404
- };
1405
-
1406
- LocalStore.prototype.save = function() {
1407
- return localStorage.setItem(this.name, JSON.stringify(this.data));
1408
- };
1409
-
1410
- LocalStore.prototype.create = function(model) {
1411
- if (!model.id) model.id = model.attribtues.id = this.guid();
1412
- this.data[model.id] = model;
1413
- this.save();
1414
- return model;
1415
- };
1416
-
1417
- LocalStore.prototype.update = function(model) {
1418
- this.data[model.id] = model;
1419
- this.save();
1420
- return model;
1421
- };
1422
-
1423
- LocalStore.prototype.find = function(model) {
1424
- return this.data[model.id];
1425
- };
1426
-
1427
- LocalStore.prototype.findAll = function() {
1428
- return _.values(this.data);
1429
- };
1430
-
1431
- LocalStore.prototype.destroy = function(model) {
1432
- delete this.data[model.id];
1433
- this.save();
1434
- return model;
1435
- };
1436
-
1437
- return LocalStore;
1438
-
1439
- })();
1440
-
1441
- Backbone.LocalSync = function(method, model, options) {
1442
- var resp, store;
1443
- store = model.localStorage || model.collection.localStorage;
1444
- resp = (function() {
1445
- switch (method) {
1446
- case "read":
1447
- if (model.id) {
1448
- return store.find(model);
1449
- } else {
1450
- return store.findAll();
1451
- }
1452
- case "create":
1453
- return store.create(model);
1454
- case "update":
1455
- return store.update(model);
1456
- case "delete":
1457
- return store.destroy(model);
1458
- }
1459
- })();
1460
- if (resp) {
1461
- return options.success(resp);
1462
- } else {
1463
- return options.error("Record not found");
1464
- }
1465
- };
1466
-
1467
- }).call(this);
1468
- (function() {
1469
- Luca.templates || (Luca.templates = {});
1470
- Luca.templates["components/bootstrap_form_controls"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'form-actions\'>\n <a class=\'btn btn-primary submit-button\'>\n <i class=\'icon-ok icon-white\'></i>\n Save Changes\n </a>\n <a class=\'btn reset-button cancel-button\'>\n <i class=\'icon-remove\'></i>\n Cancel\n </a>\n</div>\n');}return __p.join('');};
1471
- }).call(this);
1472
- (function() {
1473
- Luca.templates || (Luca.templates = {});
1474
- Luca.templates["components/collection_loader_view"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'modal\' id=\'progress-model\' style=\'display: none;\'>\n <div class=\'progress progress-info progress-striped active\'>\n <div class=\'bar\' style=\'width: 0%;\'></div>\n </div>\n <div class=\'message\'>\n Initializing...\n </div>\n</div>\n');}return __p.join('');};
1475
- }).call(this);
1476
- (function() {
1477
- Luca.templates || (Luca.templates = {});
1478
- Luca.templates["components/form_alert"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'', className ,'\'>\n <a class=\'close\' data-dismiss=\'alert\' href=\'#\'>x</a>\n ', message ,'\n</div>\n');}return __p.join('');};
1479
- }).call(this);
1480
- (function() {
1481
- Luca.templates || (Luca.templates = {});
1482
- Luca.templates["components/grid_view"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'luca-ui-g-view-wrapper\'>\n <div class=\'g-view-header\'></div>\n <div class=\'luca-ui-g-view-body\'>\n <table cellpadding=\'0\' cellspacing=\'0\' class=\'luca-ui-g-view scrollable-table\' width=\'100%\'>\n <thead class=\'fixed\'></thead>\n <tbody class=\'scrollable\'></tbody>\n </table>\n </div>\n <div class=\'luca-ui-g-view-footer\'></div>\n</div>\n');}return __p.join('');};
1483
- }).call(this);
1484
- (function() {
1485
- Luca.templates || (Luca.templates = {});
1486
- Luca.templates["components/grid_view_empty_text"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'empty-text-wrapper\'>\n <p>\n ', text ,'\n </p>\n</div>\n');}return __p.join('');};
1487
- }).call(this);
1488
- (function() {
1489
- Luca.templates || (Luca.templates = {});
1490
- Luca.templates["components/load_mask"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'load-mask\'>\n <div class=\'progress progress-striped active\'>\n <div class=\'bar\' style=\'width:1%\'></div>\n </div>\n</div>\n');}return __p.join('');};
1491
- }).call(this);
1492
- (function() {
1493
- Luca.templates || (Luca.templates = {});
1494
- Luca.templates["components/nav_bar"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'navbar-inner\'>\n <div class=\'luca-ui-navbar-body container\'></div>\n</div>\n');}return __p.join('');};
1495
- }).call(this);
1496
- (function() {
1497
- Luca.templates || (Luca.templates = {});
1498
- Luca.templates["containers/basic"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'', classes ,'\' id=\'', id ,'\' style=\'', style ,'\'></div>\n');}return __p.join('');};
1499
- }).call(this);
1500
- (function() {
1501
- Luca.templates || (Luca.templates = {});
1502
- Luca.templates["containers/tab_selector_container"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'tab-selector-container\' id=\'', cid ,'-tab-selector\'>\n <ul class=\'nav nav-tabs\' id=\'', cid ,'-tabs-nav\'>\n '); for(var i = 0; i < components.length; i++ ) { __p.push('\n '); var component = components[i];__p.push('\n <li class=\'tab-selector\' data-target=\'', i ,'\'>\n <a data-target=\'', i ,'\'>\n ', component.title ,'\n </a>\n </li>\n '); } __p.push('\n </ul>\n</div>\n');}return __p.join('');};
1503
- }).call(this);
1504
- (function() {
1505
- Luca.templates || (Luca.templates = {});
1506
- Luca.templates["containers/tab_view"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<ul class=\'nav ', navClass ,'\' id=\'', cid ,'-tabs-selector\'></ul>\n<div class=\'tab-content\' id=\'', cid ,'-tab-view-content\'></div>\n');}return __p.join('');};
1507
- }).call(this);
1508
- (function() {
1509
- Luca.templates || (Luca.templates = {});
1510
- Luca.templates["containers/toolbar_wrapper"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'luca-ui-toolbar-wrapper\' id=\'', id ,'\'></div>\n');}return __p.join('');};
1511
- }).call(this);
1512
- (function() {
1513
- Luca.templates || (Luca.templates = {});
1514
- Luca.templates["fields/button_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label>&nbsp</label>\n<input class=\'btn ', input_class ,'\' id=\'', input_id ,'\' style=\'', inputStyles ,'\' type=\'', input_type ,'\' value=\'', input_value ,'\' />\n');}return __p.join('');};
1515
- }).call(this);
1516
- (function() {
1517
- Luca.templates || (Luca.templates = {});
1518
- Luca.templates["fields/button_field_link"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<a class=\'btn ', input_class ,'\'>\n '); if(icon_class.length) { __p.push('\n <i class=\'', icon_class ,'\'></i>\n '); } __p.push('\n ', input_value ,'\n</a>\n');}return __p.join('');};
1519
- }).call(this);
1520
- (function() {
1521
- Luca.templates || (Luca.templates = {});
1522
- Luca.templates["fields/checkbox_array"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<div class=\'control-group\'>\n <label for=\'', input_id ,'\'>\n ', label ,'\n </label>\n <div class=\'controls\'></div>\n</div>\n');}return __p.join('');};
1523
- }).call(this);
1524
- (function() {
1525
- Luca.templates || (Luca.templates = {});
1526
- Luca.templates["fields/checkbox_array_item"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for=\'', input_id ,'\'>\n <input id=\'', input_id ,'\' name=\'', input_name ,'\' type=\'checkbox\' value=\'', value ,'\' />\n ', label ,'\n</label>\n');}return __p.join('');};
1527
- }).call(this);
1528
- (function() {
1529
- Luca.templates || (Luca.templates = {});
1530
- Luca.templates["fields/checkbox_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for=\'', input_id ,'\'>\n ', label ,'\n <input name=\'', input_name ,'\' style=\'', inputStyles ,'\' type=\'checkbox\' value=\'', input_value ,'\' />\n</label>\n'); if(helperText) { __p.push('\n<p class=\'helper-text help-block\'>\n ', helperText ,'\n</p>\n'); } __p.push('\n');}return __p.join('');};
1531
- }).call(this);
1532
- (function() {
1533
- Luca.templates || (Luca.templates = {});
1534
- Luca.templates["fields/file_upload_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for=\'', input_id ,'\'>\n ', label ,'\n</label>\n<input id=\'', input_id ,'\' name=\'', input_name ,'\' style=\'', inputStyles ,'\' type=\'file\' />\n'); if(helperText) { __p.push('\n<p class=\'helper-text help-block\'>\n ', helperText ,'\n</p>\n'); } __p.push('\n');}return __p.join('');};
1535
- }).call(this);
1536
- (function() {
1537
- Luca.templates || (Luca.templates = {});
1538
- Luca.templates["fields/hidden_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<input id=\'', input_id ,'\' name=\'', input_name ,'\' type=\'hidden\' value=\'', input_value ,'\' />\n');}return __p.join('');};
1539
- }).call(this);
1540
- (function() {
1541
- Luca.templates || (Luca.templates = {});
1542
- Luca.templates["fields/select_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for=\'', input_id ,'\'>\n ', label ,'\n</label>\n<select id=\'', input_id ,'\' name=\'', input_name ,'\' style=\'', inputStyles ,'\'></select>\n'); if(helperText) { __p.push('\n<p class=\'helper-text help-block\'>\n ', helperText ,'\n</p>\n'); } __p.push('\n');}return __p.join('');};
1543
- }).call(this);
1544
- (function() {
1545
- Luca.templates || (Luca.templates = {});
1546
- Luca.templates["fields/text_area_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<label for=\'', input_id ,'\'>\n ', label ,'\n</label>\n<textarea class=\'', input_class ,'\' id=\'', input_id ,'\' name=\'', input_name ,'\' style=\'', inputStyles ,'\'></textarea>\n'); if(helperText) { __p.push('\n<p class=\'helper-text help-block\'>\n ', helperText ,'\n</p>\n'); } __p.push('\n');}return __p.join('');};
1547
- }).call(this);
1548
- (function() {
1549
- Luca.templates || (Luca.templates = {});
1550
- Luca.templates["fields/text_field"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(''); if(typeof(label)!=="undefined" && (typeof(hideLabel) !== "undefined" && !hideLabel) || (typeof(hideLabel)==="undefined")) {__p.push('\n<label class=\'control-label\' for=\'', input_id ,'\'>\n ', label ,'\n</label>\n'); } __p.push('\n'); if( typeof(addOn) !== "undefined" ) { __p.push('\n<span class=\'add-on\'>\n ', addOn ,'\n</span>\n'); } __p.push('\n<input class=\'', input_class ,'\' id=\'', input_id ,'\' name=\'', input_name ,'\' placeholder=\'', placeHolder ,'\' style=\'', inputStyles ,'\' type=\'text\' />\n'); if(helperText) { __p.push('\n<p class=\'helper-text help-block\'>\n ', helperText ,'\n</p>\n'); } __p.push('\n');}return __p.join('');};
1551
- }).call(this);
1552
- (function() {
1553
- Luca.templates || (Luca.templates = {});
1554
- Luca.templates["sample/contents"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('<p>Sample Contents</p>\n');}return __p.join('');};
1555
- }).call(this);
1556
- (function() {
1557
- Luca.templates || (Luca.templates = {});
1558
- Luca.templates["sample/welcome"] = function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('welcome.luca\n');}return __p.join('');};
1559
- }).call(this);
1560
- (function() {
1561
- var __slice = Array.prototype.slice;
1562
-
1563
- Luca.Observer = (function() {
1564
-
1565
- function Observer(options) {
1566
- var _this = this;
1567
- this.options = options != null ? options : {};
1568
- _.extend(this, Backbone.Events);
1569
- this.type = this.options.type;
1570
- if (this.options.debugAll) {
1571
- this.bind("all", function(trigger, one, two) {
1572
- return console.log("ALL", trigger, one, two);
1573
- });
1574
- }
1575
- }
1576
-
1577
- Observer.prototype.relay = function() {
1578
- var args, triggerer;
1579
- triggerer = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
1580
- console.log("Relaying", trigger, args);
1581
- this.trigger("event", triggerer, args);
1582
- return this.trigger("event:" + args[0], triggerer, args.slice(1));
1583
- };
1584
-
1585
- return Observer;
1586
-
1587
- })();
1588
-
1589
- Luca.Observer.enableObservers = function(options) {
1590
- if (options == null) options = {};
1591
- Luca.enableGlobalObserver = true;
1592
- Luca.ViewObserver = new Luca.Observer(_.extend(options, {
1593
- type: "view"
1594
- }));
1595
- return Luca.CollectionObserver = new Luca.Observer(_.extend(options, {
1596
- type: "collection"
1597
- }));
1598
- };
1599
-
1600
- }).call(this);
1601
- (function() {
1602
-
1603
- _.def('Luca.core.Field')["extends"]('Luca.View')["with"]({
1604
- className: 'luca-ui-text-field luca-ui-field',
1605
- isField: true,
1606
- template: 'fields/text_field',
1607
- labelAlign: 'top',
1608
- hooks: ["before:validation", "after:validation", "on:change"],
1609
- statuses: ["warning", "error", "success"],
1610
- initialize: function(options) {
1611
- var _ref;
1612
- this.options = options != null ? options : {};
1613
- _.extend(this, this.options);
1614
- this.input_id || (this.input_id = _.uniqueId('field'));
1615
- this.input_name || (this.input_name = this.name);
1616
- this.input_class || (this.input_class = "");
1617
- this.helperText || (this.helperText = "");
1618
- if (this.required && !((_ref = this.label) != null ? _ref.match(/^\*/) : void 0)) {
1619
- this.label || (this.label = "*" + this.label);
2086
+ _.def('Luca.core.Field')["extends"]('Luca.View')["with"]({
2087
+ className: 'luca-ui-text-field luca-ui-field',
2088
+ isField: true,
2089
+ template: 'fields/text_field',
2090
+ labelAlign: 'top',
2091
+ hooks: ["before:validation", "after:validation", "on:change"],
2092
+ statuses: ["warning", "error", "success"],
2093
+ initialize: function(options) {
2094
+ var _ref;
2095
+ this.options = options != null ? options : {};
2096
+ _.extend(this, this.options);
2097
+ this.input_id || (this.input_id = _.uniqueId('field'));
2098
+ this.input_name || (this.input_name = this.name);
2099
+ this.input_class || (this.input_class = "");
2100
+ this.helperText || (this.helperText = "");
2101
+ if (this.required && !((_ref = this.label) != null ? _ref.match(/^\*/) : void 0)) {
2102
+ this.label || (this.label = "*" + this.label);
1620
2103
  }
1621
2104
  this.inputStyles || (this.inputStyles = "");
2105
+ this.input_value || (this.input_value = this.value || "");
1622
2106
  if (this.disabled) this.disable();
1623
2107
  this.updateState(this.state);
1624
2108
  this.placeHolder || (this.placeHolder = "");
@@ -1627,7 +2111,7 @@
1627
2111
  beforeRender: function() {
1628
2112
  if (Luca.enableBootstrap) this.$el.addClass('control-group');
1629
2113
  if (this.required) this.$el.addClass('required');
1630
- this.$el.html(Luca.templates[this.template](this));
2114
+ this.$template(this.template, this);
1631
2115
  return this.input = $('input', this.el);
1632
2116
  },
1633
2117
  change_handler: function(e) {
@@ -1640,7 +2124,19 @@
1640
2124
  return $("input", this.el).attr('disabled', false);
1641
2125
  },
1642
2126
  getValue: function() {
1643
- return this.input.attr('value');
2127
+ var raw;
2128
+ raw = this.input.attr('value');
2129
+ if (_.str.isBlank(raw)) return raw;
2130
+ switch (this.valueType) {
2131
+ case "integer":
2132
+ return parseInt(raw);
2133
+ case "string":
2134
+ return "" + raw;
2135
+ case "float":
2136
+ return parseFloat(raw);
2137
+ default:
2138
+ return raw;
2139
+ }
1644
2140
  },
1645
2141
  render: function() {
1646
2142
  return $(this.container).append(this.$el);
@@ -1681,7 +2177,7 @@
1681
2177
  "class": (panel != null ? panel.classes : void 0) || this.componentClass,
1682
2178
  id: "" + this.cid + "-" + panelIndex,
1683
2179
  style: style_declarations.join(';'),
1684
- "data-luca-owner": this.name || this.cid
2180
+ "data-luca-parent": this.name || this.cid
1685
2181
  };
1686
2182
  if (this.customizeContainerEl != null) {
1687
2183
  config = this.customizeContainerEl(config, panel, panelIndex);
@@ -1710,6 +2206,7 @@
1710
2206
  this.options = options != null ? options : {};
1711
2207
  _.extend(this, this.options);
1712
2208
  this.setupHooks(["before:components", "before:render:components", "before:layout", "after:components", "after:layout", "first:activation"]);
2209
+ this.components || (this.components = this.fields || (this.fields = this.pages || (this.pages = this.cards)));
1713
2210
  return Luca.View.prototype.initialize.apply(this, arguments);
1714
2211
  },
1715
2212
  beforeRender: function() {
@@ -1741,30 +2238,38 @@
1741
2238
  }
1742
2239
  }
1743
2240
  return _(this.components).each(function(component, index) {
1744
- var container, panel, _ref2;
1745
- container = (_ref2 = _this.componentContainers) != null ? _ref2[index] : void 0;
1746
- container["class"] = container["class"] || container.className || container.classes;
1747
- if (_this.appendContainers) {
1748
- panel = _this.make(_this.componentTag, container, '');
2241
+ var ce, componentContainerElement, panel, _ref2;
2242
+ ce = componentContainerElement = (_ref2 = _this.componentContainers) != null ? _ref2[index] : void 0;
2243
+ ce["class"] = ce["class"] || ce.className || ce.classes;
2244
+ if (_this.generateComponentElements) {
2245
+ panel = _this.make(_this.componentTag, componentContainerElement, '');
1749
2246
  _this.$append(panel);
1750
2247
  }
1751
2248
  if (component.container == null) {
1752
- if (_this.appendContainers) component.container = "#" + container.id;
2249
+ if (_this.generateComponentElements) {
2250
+ component.container = "#" + componentContainerElement.id;
2251
+ }
1753
2252
  return component.container || (component.container = _this.$bodyEl());
1754
2253
  }
1755
2254
  });
1756
2255
  },
1757
2256
  createComponents: function() {
1758
- var map,
2257
+ var container, map,
1759
2258
  _this = this;
1760
2259
  if (this.componentsCreated === true) return;
1761
2260
  map = this.componentIndex = {
1762
2261
  name_index: {},
1763
2262
  cid_index: {}
1764
2263
  };
2264
+ container = this;
1765
2265
  this.components = _(this.components).map(function(object, index) {
1766
- var component;
1767
- component = Luca.isBackboneView(object) ? object : (object.type || (object.type = object.ctype), !(object.type != null) ? object.components != null ? object.type = object.ctype = 'container' : object.type = object.ctype = Luca.defaultComponentType : void 0, Luca.util.lazyComponent(object));
2266
+ var component, created;
2267
+ component = Luca.isBackboneView(object) ? object : (object.type || (object.type = object.ctype), !(object.type != null) ? object.components != null ? object.type = object.ctype = 'container' : object.type = object.ctype = Luca.defaultComponentType : void 0, object = _.defaults(object, container.defaults || {}), created = Luca.util.lazyComponent(object));
2268
+ if (_.isString(component.getter)) {
2269
+ container[component.getter] = (function() {
2270
+ return component;
2271
+ });
2272
+ }
1768
2273
  if (!component.container && component.options.container) {
1769
2274
  component.container = component.options.container;
1770
2275
  }
@@ -1779,15 +2284,16 @@
1779
2284
  return map;
1780
2285
  },
1781
2286
  renderComponents: function(debugMode) {
1782
- var _this = this;
2287
+ var container;
1783
2288
  this.debugMode = debugMode != null ? debugMode : "";
1784
2289
  this.debug("container render components");
2290
+ container = this;
1785
2291
  return _(this.components).each(function(component) {
1786
2292
  component.getParent = function() {
1787
- return _this;
2293
+ return container;
1788
2294
  };
1789
- $(component.container).append($(component.el));
1790
2295
  try {
2296
+ $(component.container).append(component.el);
1791
2297
  return component.render();
1792
2298
  } catch (e) {
1793
2299
  console.log("Error Rendering Component " + (component.name || component.cid), component);
@@ -1820,20 +2326,8 @@
1820
2326
  invoke: function(method) {
1821
2327
  return _(this.components).invoke(method);
1822
2328
  },
1823
- select: function(attribute, value, deep) {
1824
- var components;
1825
- if (deep == null) deep = false;
1826
- components = _(this.components).map(function(component) {
1827
- var matches, test;
1828
- matches = [];
1829
- test = component[attribute];
1830
- if (test === value) matches.push(component);
1831
- if (deep === true) {
1832
- matches.push(typeof component.select === "function" ? component.select(attribute, value, true) : void 0);
1833
- }
1834
- return _.compact(matches);
1835
- });
1836
- return _.flatten(components);
2329
+ map: function(fn) {
2330
+ return _(this.components).map(fn);
1837
2331
  },
1838
2332
  componentEvents: {},
1839
2333
  registerComponentEvents: function() {
@@ -1895,32 +2389,63 @@
1895
2389
  return this.components[this.activeItem];
1896
2390
  },
1897
2391
  componentElements: function() {
1898
- return $(">." + this.componentClass, this.el);
2392
+ return this.$("[data-luca-parent='" + (this.name || this.cid) + "']");
1899
2393
  },
1900
2394
  getComponent: function(needle) {
1901
2395
  return this.components[needle];
1902
2396
  },
1903
- rootComponent: function() {
2397
+ isRootComponent: function() {
1904
2398
  return !(this.getParent != null);
1905
2399
  },
1906
2400
  getRootComponent: function() {
1907
- if (this.rootComponent()) {
2401
+ if (this.isRootComponent()) {
1908
2402
  return this;
1909
2403
  } else {
1910
2404
  return this.getParent().getRootComponent();
1911
2405
  }
2406
+ },
2407
+ selectByAttribute: function(attribute, value, deep) {
2408
+ var components;
2409
+ if (deep == null) deep = false;
2410
+ components = _(this.components).map(function(component) {
2411
+ var matches, test;
2412
+ matches = [];
2413
+ test = component[attribute];
2414
+ if (test === value) matches.push(component);
2415
+ if (deep === true) {
2416
+ matches.push(typeof component.selectByAttribute === "function" ? component.selectByAttribute(attribute, value, true) : void 0);
2417
+ }
2418
+ return _.compact(matches);
2419
+ });
2420
+ return _.flatten(components);
2421
+ },
2422
+ select: function(attribute, value, deep) {
2423
+ if (deep == null) deep = false;
2424
+ console.log("Container.select will be replaced by selectByAttribute in 1.0");
2425
+ return Luca.core.Container.prototype.selectByAttribute.apply(this, arguments);
1912
2426
  }
1913
2427
  });
1914
2428
 
2429
+ Luca.core.Container.componentRenderer = function(container, component) {
2430
+ var attachMethod;
2431
+ attachMethod = $(component.container)[component.attachWith || "append"];
2432
+ return attachMethod(component.render().el);
2433
+ };
2434
+
1915
2435
  }).call(this);
1916
2436
  (function() {
2437
+ var guessCollectionClass, handleInitialCollections, loadInitialCollections;
1917
2438
 
1918
2439
  Luca.CollectionManager = (function() {
1919
2440
 
1920
2441
  CollectionManager.prototype.name = "primary";
1921
2442
 
2443
+ CollectionManager.prototype.collectionNamespace = Luca.Collection.namespace;
2444
+
1922
2445
  CollectionManager.prototype.__collections = {};
1923
2446
 
2447
+ CollectionManager.prototype.relayEvents = true;
2448
+
1924
2449
  function CollectionManager(options) {
1925
2450
  var existing, manager, _base, _base2;
1926
2451
  this.options = options != null ? options : {};
@@ -1938,21 +2463,7 @@
1938
2463
  return Luca.CollectionManager.instances[name];
1939
2464
  };
1940
2465
  this.state = new Luca.Model();
1941
- if (this.initialCollections) {
1942
- this.state.set({
1943
- loaded_collections_count: 0,
1944
- collections_count: this.initialCollections.length
1945
- });
1946
- this.state.bind("change:loaded_collections_count", this.collectionCountDidChange);
1947
- if (this.useProgressLoader) {
1948
- this.loaderView || (this.loaderView = new Luca.components.CollectionLoaderView({
1949
- manager: this,
1950
- name: "collection_loader_view"
1951
- }));
1952
- }
1953
- this.loadInitialCollections();
1954
- }
1955
- this;
2466
+ if (this.initialCollections) handleInitialCollections.call(this);
1956
2467
  }
1957
2468
 
1958
2469
  CollectionManager.prototype.add = function(key, collection) {
@@ -1965,19 +2476,23 @@
1965
2476
  };
1966
2477
 
1967
2478
  CollectionManager.prototype.create = function(key, collectionOptions, initialModels) {
1968
- var CollectionClass, collection;
2479
+ var CollectionClass, collection, collectionManager;
1969
2480
  if (collectionOptions == null) collectionOptions = {};
1970
2481
  if (initialModels == null) initialModels = [];
1971
2482
  CollectionClass = collectionOptions.base;
1972
- CollectionClass || (CollectionClass = this.guessCollectionClass(key));
2483
+ CollectionClass || (CollectionClass = guessCollectionClass.call(this, key));
1973
2484
  if (collectionOptions.private) collectionOptions.name = "";
1974
2485
  collection = new CollectionClass(initialModels, collectionOptions);
1975
2486
  this.add(key, collection);
2487
+ collectionManager = this;
2488
+ if (this.relayEvents === true) {
2489
+ this.bind("*", function() {
2490
+ return console.log("Relay Events on Collection Manager *", collection, arguments);
2491
+ });
2492
+ }
1976
2493
  return collection;
1977
2494
  };
1978
2495
 
1979
- CollectionManager.prototype.collectionNamespace = Luca.Collection.namespace;
1980
-
1981
2496
  CollectionManager.prototype.currentScope = function() {
1982
2497
  var current_scope, _base;
1983
2498
  if (current_scope = this.getScope()) {
@@ -1999,48 +2514,28 @@
1999
2514
  return;
2000
2515
  };
2001
2516
 
2517
+ CollectionManager.prototype.destroy = function(key) {
2518
+ var c;
2519
+ c = this.get(key);
2520
+ delete this.currentScope()[key];
2521
+ return c;
2522
+ };
2523
+
2002
2524
  CollectionManager.prototype.getOrCreate = function(key, collectionOptions, initialModels) {
2003
2525
  if (collectionOptions == null) collectionOptions = {};
2004
2526
  if (initialModels == null) initialModels = [];
2005
2527
  return this.get(key) || this.create(key, collectionOptions, initialModels, false);
2006
2528
  };
2007
2529
 
2008
- CollectionManager.prototype.guessCollectionClass = function(key) {
2009
- var classified, guess, guesses, _ref;
2010
- classified = Luca.util.classify(key);
2011
- guess = (this.collectionNamespace || (window || global))[classified];
2012
- guess || (guess = (this.collectionNamespace || (window || global))["" + classified + "Collection"]);
2013
- if (!(guess != null) && ((_ref = Luca.Collection.namespaces) != null ? _ref.length : void 0) > 0) {
2014
- guesses = _(Luca.Collection.namespaces.reverse()).map(function(namespace) {
2015
- return Luca.util.resolve("" + namespace + "." + classified) || Luca.util.resolve("" + namespace + "." + classified + "Collection");
2016
- });
2017
- guesses = _(guesses).compact();
2018
- if (guesses.length > 0) guess = guesses[0];
2530
+ CollectionManager.prototype.collectionCountDidChange = function() {
2531
+ if (this.allCollectionsLoaded()) {
2532
+ this.trigger("all_collections_loaded");
2533
+ return this.trigger("initial:load");
2019
2534
  }
2020
- return guess;
2021
- };
2022
-
2023
- CollectionManager.prototype.loadInitialCollections = function() {
2024
- var collectionDidLoad,
2025
- _this = this;
2026
- collectionDidLoad = function(collection) {
2027
- collection.unbind("reset");
2028
- return _this.trigger("collection_loaded", collection.name);
2029
- };
2030
- return _(this.initialCollections).each(function(name) {
2031
- var collection;
2032
- collection = _this.getOrCreate(name);
2033
- collection.bind("reset", function() {
2034
- return collectionDidLoad(collection);
2035
- });
2036
- return collection.fetch();
2037
- });
2038
2535
  };
2039
2536
 
2040
- CollectionManager.prototype.collectionCountDidChange = function() {
2041
- if (this.totalCollectionsCount() === this.loadedCollectionsCount()) {
2042
- return this.trigger("all_collections_loaded");
2043
- }
2537
+ CollectionManager.prototype.allCollectionsLoaded = function() {
2538
+ return this.totalCollectionsCount() === this.loadedCollectionsCount();
2044
2539
  };
2045
2540
 
2046
2541
  CollectionManager.prototype.totalCollectionsCount = function() {
@@ -2065,10 +2560,64 @@
2065
2560
  return Luca.CollectionManager.instances = {};
2066
2561
  };
2067
2562
 
2068
- }).call(this);
2069
- (function() {
2070
-
2071
- Luca.SocketManager = (function() {
2563
+ guessCollectionClass = function(key) {
2564
+ var classified, guess, guesses, _ref;
2565
+ classified = Luca.util.classify(key);
2566
+ guess = (this.collectionNamespace || (window || global))[classified];
2567
+ guess || (guess = (this.collectionNamespace || (window || global))["" + classified + "Collection"]);
2568
+ if (!(guess != null) && ((_ref = Luca.Collection.namespaces) != null ? _ref.length : void 0) > 0) {
2569
+ guesses = _(Luca.Collection.namespaces.reverse()).map(function(namespace) {
2570
+ return Luca.util.resolve("" + namespace + "." + classified) || Luca.util.resolve("" + namespace + "." + classified + "Collection");
2571
+ });
2572
+ guesses = _(guesses).compact();
2573
+ if (guesses.length > 0) guess = guesses[0];
2574
+ }
2575
+ return guess;
2576
+ };
2577
+
2578
+ loadInitialCollections = function() {
2579
+ var collectionDidLoad,
2580
+ _this = this;
2581
+ collectionDidLoad = function(collection) {
2582
+ var current;
2583
+ current = _this.state.get("loaded_collections_count");
2584
+ _this.state.set("loaded_collections_count", current + 1);
2585
+ _this.trigger("collection_loaded", collection.name);
2586
+ return collection.unbind("reset");
2587
+ };
2588
+ return _(this.initialCollections).each(function(name) {
2589
+ var collection;
2590
+ collection = _this.getOrCreate(name);
2591
+ collection.once("reset", function() {
2592
+ return collectionDidLoad(collection);
2593
+ });
2594
+ return collection.fetch();
2595
+ });
2596
+ };
2597
+
2598
+ handleInitialCollections = function() {
2599
+ var _this = this;
2600
+ this.state.set({
2601
+ loaded_collections_count: 0,
2602
+ collections_count: this.initialCollections.length
2603
+ });
2604
+ this.state.bind("change:loaded_collections_count", function() {
2605
+ return _this.collectionCountDidChange();
2606
+ });
2607
+ if (this.useProgressLoader) {
2608
+ this.loaderView || (this.loaderView = new Luca.components.CollectionLoaderView({
2609
+ manager: this,
2610
+ name: "collection_loader_view"
2611
+ }));
2612
+ }
2613
+ loadInitialCollections.call(this);
2614
+ return this;
2615
+ };
2616
+
2617
+ }).call(this);
2618
+ (function() {
2619
+
2620
+ Luca.SocketManager = (function() {
2072
2621
 
2073
2622
  function SocketManager(options) {
2074
2623
  this.options = options != null ? options : {};
@@ -2136,12 +2685,13 @@
2136
2685
  components: [],
2137
2686
  initialize: function(options) {
2138
2687
  this.options = options != null ? options : {};
2688
+ console.log("Column Views are deprecated in favor of just using grid css on a normal container");
2139
2689
  Luca.core.Container.prototype.initialize.apply(this, arguments);
2140
2690
  return this.setColumnWidths();
2141
2691
  },
2142
2692
  componentClass: 'luca-ui-column',
2143
2693
  containerTemplate: "containers/basic",
2144
- appendContainers: true,
2694
+ generateComponentElements: true,
2145
2695
  autoColumnWidths: function() {
2146
2696
  var widths,
2147
2697
  _this = this;
@@ -2173,33 +2723,32 @@
2173
2723
 
2174
2724
  }).call(this);
2175
2725
  (function() {
2726
+ var component;
2176
2727
 
2177
- _.def("Luca.containers.CardView")["extends"]("Luca.core.Container")["with"]({
2178
- componentType: 'card_view',
2728
+ component = Luca.define("Luca.containers.CardView");
2729
+
2730
+ component["extends"]("Luca.core.Container");
2731
+
2732
+ component.defaults({
2179
2733
  className: 'luca-ui-card-view-wrapper',
2180
2734
  activeCard: 0,
2181
2735
  components: [],
2182
2736
  hooks: ['before:card:switch', 'after:card:switch'],
2183
2737
  componentClass: 'luca-ui-card',
2184
- appendContainers: true,
2738
+ generateComponentElements: true,
2185
2739
  initialize: function(options) {
2186
2740
  this.options = options;
2187
2741
  Luca.core.Container.prototype.initialize.apply(this, arguments);
2188
- return this.setupHooks(this.hooks);
2742
+ this.setupHooks(this.hooks);
2743
+ return this.components || (this.components = this.pages || (this.pages = this.cards));
2189
2744
  },
2190
2745
  prepareComponents: function() {
2191
- var _ref,
2192
- _this = this;
2746
+ var _ref;
2193
2747
  if ((_ref = Luca.core.Container.prototype.prepareComponents) != null) {
2194
2748
  _ref.apply(this, arguments);
2195
2749
  }
2196
- return _(this.components).each(function(component, index) {
2197
- if (index === _this.activeCard) {
2198
- return $(component.container).show();
2199
- } else {
2200
- return $(component.container).hide();
2201
- }
2202
- });
2750
+ this.componentElements().hide();
2751
+ return this.activeComponentElement().show();
2203
2752
  },
2204
2753
  activeComponentElement: function() {
2205
2754
  return this.componentElements().eq(this.activeCard);
@@ -2211,13 +2760,27 @@
2211
2760
  containerEl.style += panelIndex === this.activeCard ? "display:block;" : "display:none;";
2212
2761
  return containerEl;
2213
2762
  },
2763
+ atFirst: function() {
2764
+ return this.activeCard === 0;
2765
+ },
2766
+ atLast: function() {
2767
+ return this.activeCard === this.components.length - 1;
2768
+ },
2769
+ next: function() {
2770
+ if (this.atLast()) return;
2771
+ return this.activate(this.activeCard + 1);
2772
+ },
2773
+ previous: function() {
2774
+ if (this.atFirst()) return;
2775
+ return this.activate(this.activeCard - 1);
2776
+ },
2214
2777
  cycle: function() {
2215
2778
  var nextIndex;
2216
- nextIndex = this.activeCard < this.components.length - 1 ? this.activeCard + 1 : 0;
2779
+ nextIndex = this.atLast() ? 0 : this.activeCard + 1;
2217
2780
  return this.activate(nextIndex);
2218
2781
  },
2219
2782
  find: function(name) {
2220
- return this.findComponentByName(name, true);
2783
+ return Luca(name);
2221
2784
  },
2222
2785
  firstActivation: function() {
2223
2786
  return this.activeComponent().trigger("first:activation", this, this.activeComponent());
@@ -2279,10 +2842,11 @@
2279
2842
  }).call(this);
2280
2843
  (function() {
2281
2844
 
2282
- _.def("Luca.ModalView")["extends"]("Luca.View")["with"]({
2845
+ _.def("Luca.ModalView")["extends"]("Luca.core.Container")["with"]({
2283
2846
  closeOnEscape: true,
2284
2847
  showOnInitialize: false,
2285
2848
  backdrop: false,
2849
+ className: "luca-ui-container modal",
2286
2850
  container: function() {
2287
2851
  return $('body');
2288
2852
  },
@@ -2299,16 +2863,24 @@
2299
2863
  this.$el.addClass('modal');
2300
2864
  if (this.fade === true) this.$el.addClass('fade');
2301
2865
  $('body').append(this.$el);
2302
- return this.$el.modal({
2866
+ this.$el.modal({
2303
2867
  backdrop: this.backdrop === true,
2304
2868
  keyboard: this.closeOnEscape === true,
2305
2869
  show: this.showOnInitialize === true
2306
2870
  });
2871
+ return this;
2307
2872
  }
2308
2873
  });
2309
2874
 
2310
2875
  _.def("Luca.containers.ModalView")["extends"]("Luca.ModalView")["with"]();
2311
2876
 
2877
+ }).call(this);
2878
+ (function() {
2879
+
2880
+ _.def("Luca.PageView")["extends"]("Luca.containers.CardView")["with"]({
2881
+ version: 2
2882
+ });
2883
+
2312
2884
  }).call(this);
2313
2885
  (function() {
2314
2886
  var buildButton, make, prepareButtons;
@@ -2501,11 +3073,12 @@
2501
3073
  return (_ref = Luca.containers.CardView.prototype.beforeLayout) != null ? _ref.apply(this, arguments) : void 0;
2502
3074
  },
2503
3075
  afterRender: function() {
2504
- var _ref;
3076
+ var tabContainerId, _ref;
2505
3077
  if ((_ref = Luca.containers.CardView.prototype.afterRender) != null) {
2506
3078
  _ref.apply(this, arguments);
2507
3079
  }
2508
- this.registerEvent("click #" + this.cid + "-tabs-selector li a", "select");
3080
+ tabContainerId = this.tabContainer().attr("id");
3081
+ this.registerEvent("click #" + tabContainerId + " li a", "select");
2509
3082
  if (Luca.enableBootstrap && (this.tab_position === "left" || this.tab_position === "right")) {
2510
3083
  this.tabContainerWrapper().addClass("span2");
2511
3084
  return this.tabContentWrapper().addClass("span9");
@@ -2516,7 +3089,9 @@
2516
3089
  tabView = this;
2517
3090
  return this.each(function(component, index) {
2518
3091
  var icon, link, selector, _ref;
2519
- if (component.tabIcon) icon = "<i class='icon-" + component.tabIcon;
3092
+ if (component.tabIcon) {
3093
+ icon = "<i class='icon-" + component.tabIcon + "'></i>";
3094
+ }
2520
3095
  link = "<a href='#'>" + (icon || '') + " " + component.title + "</a>";
2521
3096
  selector = tabView.make("li", {
2522
3097
  "class": "tab-selector",
@@ -2569,17 +3144,38 @@
2569
3144
  additionalClassNames: 'luca-ui-viewport',
2570
3145
  fullscreen: true,
2571
3146
  fluid: false,
2572
- wrapperClass: 'row',
2573
3147
  initialize: function(options) {
2574
3148
  this.options = options != null ? options : {};
2575
3149
  _.extend(this, this.options);
2576
3150
  if (Luca.enableBootstrap === true) {
2577
- if (this.fluid === true) {
2578
- this.wrapperClass = "row-fluid fluid-viewport-wrapper";
2579
- }
3151
+ this.wrapperClass = this.fluid === true ? Luca.containers.Viewport.fluidWrapperClass : Luca.containers.Viewport.defaultWrapperClass;
2580
3152
  }
2581
3153
  Luca.core.Container.prototype.initialize.apply(this, arguments);
2582
- if (this.fullscreen) return $('html,body').addClass('luca-ui-fullscreen');
3154
+ if (this.fullscreen === true) return this.enableFullscreen();
3155
+ },
3156
+ enableFluid: function() {
3157
+ return this.enableWrapper();
3158
+ },
3159
+ disableFluid: function() {
3160
+ return this.disableWrapper();
3161
+ },
3162
+ enableWrapper: function() {
3163
+ if (this.wrapperClass != null) {
3164
+ return this.$el.parent().addClass(this.wrapperClass);
3165
+ }
3166
+ },
3167
+ disableWrapper: function() {
3168
+ if (this.wrapperClass != null) {
3169
+ return this.$el.parent().removeClass(this.wrapperClass);
3170
+ }
3171
+ },
3172
+ enableFullscreen: function() {
3173
+ $('html,body').addClass('luca-ui-fullscreen');
3174
+ return this.$el.addClass('fullscreen-enabled');
3175
+ },
3176
+ disableFullscreen: function() {
3177
+ $('html,body').removeClass('luca-ui-fullscreen');
3178
+ return this.$el.removeClass('fullscreen-enabled');
2583
3179
  },
2584
3180
  beforeRender: function() {
2585
3181
  var _ref;
@@ -2589,6 +3185,12 @@
2589
3185
  if (this.topNav != null) this.renderTopNavigation();
2590
3186
  if (this.bottomNav != null) return this.renderBottomNavigation();
2591
3187
  },
3188
+ height: function() {
3189
+ return this.$el.height();
3190
+ },
3191
+ width: function() {
3192
+ return this.$el.width();
3193
+ },
2592
3194
  afterRender: function() {
2593
3195
  var _ref;
2594
3196
  if ((_ref = Luca.containers.CardView.prototype.after) != null) {
@@ -2616,7 +3218,2080 @@
2616
3218
  renderBottomNavigation: function() {}
2617
3219
  });
2618
3220
 
3221
+ Luca.containers.Viewport.defaultWrapperClass = 'row';
3222
+
3223
+ Luca.containers.Viewport.fluidWrapperClass = 'row-fluid';
3224
+
3225
+ }).call(this);
3226
+ (function() {
3227
+
3228
+ _.def('Luca.components.Template')["extends"]('Luca.View')["with"]({
3229
+ initialize: function(options) {
3230
+ this.options = options != null ? options : {};
3231
+ console.log("The Use of Luca.components.Template directly is being DEPRECATED");
3232
+ return Luca.View.prototype.initialize.apply(this, arguments);
3233
+ }
3234
+ });
3235
+
3236
+ }).call(this);
3237
+ (function() {
3238
+ var startHistory;
3239
+
3240
+ startHistory = function() {
3241
+ return Backbone.history.start();
3242
+ };
3243
+
3244
+ _.def('Luca.Application')["extends"]('Luca.containers.Viewport')["with"]({
3245
+ name: "MyApp",
3246
+ defaultState: {},
3247
+ autoBoot: false,
3248
+ autoStartHistory: "before:render",
3249
+ useCollectionManager: true,
3250
+ collectionManager: {},
3251
+ collectionManagerClass: "Luca.CollectionManager",
3252
+ plugin: false,
3253
+ useController: true,
3254
+ useKeyHandler: false,
3255
+ keyEvents: {},
3256
+ components: [
3257
+ {
3258
+ ctype: 'template',
3259
+ name: 'welcome',
3260
+ template: 'sample/welcome',
3261
+ templateContainer: "Luca.templates"
3262
+ }
3263
+ ],
3264
+ initialize: function(options) {
3265
+ var alreadyRunning, app, appName, _base,
3266
+ _this = this;
3267
+ this.options = options != null ? options : {};
3268
+ app = this;
3269
+ appName = this.name;
3270
+ alreadyRunning = typeof Luca.getApplication === "function" ? Luca.getApplication() : void 0;
3271
+ (_base = Luca.Application).instances || (_base.instances = {});
3272
+ Luca.Application.instances[appName] = app;
3273
+ Luca.containers.Viewport.prototype.initialize.apply(this, arguments);
3274
+ this.state = new Luca.Model(this.defaultState);
3275
+ if (this.useController === true) this.setupMainController();
3276
+ this.setupCollectionManager();
3277
+ this.defer(function() {
3278
+ return app.render();
3279
+ }).until(this, "ready");
3280
+ this.setupRouter();
3281
+ if (this.useKeyRouter === true) {
3282
+ console.log("The useKeyRouter property is being deprecated. switch to useKeyHandler instead");
3283
+ }
3284
+ if ((this.useKeyHandler === true || this.useKeyRouter === true) && (this.keyEvents != null)) {
3285
+ this.setupKeyHandler();
3286
+ }
3287
+ if (!(this.plugin === true || alreadyRunning)) {
3288
+ Luca.getApplication = function(name) {
3289
+ if (name == null) return app;
3290
+ return Luca.Application.instances[name];
3291
+ };
3292
+ }
3293
+ if (this.autoBoot) {
3294
+ if (Luca.util.resolve(this.name)) {
3295
+ throw "Attempting to override window." + this.name + " when it already exists";
3296
+ }
3297
+ return $(function() {
3298
+ window[appName] = app;
3299
+ return app.boot();
3300
+ });
3301
+ }
3302
+ },
3303
+ activeView: function() {
3304
+ var active;
3305
+ if (active = this.activeSubSection()) {
3306
+ return this.view(active);
3307
+ } else {
3308
+ return this.view(this.activeSection());
3309
+ }
3310
+ },
3311
+ activeSection: function() {
3312
+ return this.get("active_section");
3313
+ },
3314
+ activeSubSection: function() {
3315
+ return this.get("active_sub_section");
3316
+ },
3317
+ activePages: function() {
3318
+ var _this = this;
3319
+ return this.$('.luca-ui-controller').map(function(index, element) {
3320
+ return $(element).data('active-section');
3321
+ });
3322
+ },
3323
+ boot: function() {
3324
+ return this.trigger("ready");
3325
+ },
3326
+ collection: function() {
3327
+ return this.collectionManager.getOrCreate.apply(this.collectionManager, arguments);
3328
+ },
3329
+ get: function(attribute) {
3330
+ return this.state.get(attribute);
3331
+ },
3332
+ set: function(attribute, value, options) {
3333
+ return this.state.set.apply(this.state, arguments);
3334
+ },
3335
+ view: function(name) {
3336
+ return Luca.cache(name);
3337
+ },
3338
+ navigate_to: function(component_name, callback) {
3339
+ return this.getMainController().navigate_to(component_name, callback);
3340
+ },
3341
+ getMainController: function() {
3342
+ if (this.useController === true) return this.components[0];
3343
+ return Luca.cache('main_controller');
3344
+ },
3345
+ keyHandler: function(e) {
3346
+ var control, isInputEvent, keyEvent, keyname, meta, source, _ref;
3347
+ if (!(e && this.keyEvents)) return;
3348
+ isInputEvent = $(e.target).is('input') || $(e.target).is('textarea');
3349
+ if (isInputEvent) return;
3350
+ keyname = Luca.keyMap[e.keyCode];
3351
+ if (!keyname) return;
3352
+ meta = (e != null ? e.metaKey : void 0) === true;
3353
+ control = (e != null ? e.ctrlKey : void 0) === true;
3354
+ source = this.keyEvents;
3355
+ source = meta ? this.keyEvents.meta : source;
3356
+ source = control ? this.keyEvents.control : source;
3357
+ source = meta && control ? this.keyEvents.meta_control : source;
3358
+ if (keyEvent = source != null ? source[keyname] : void 0) {
3359
+ if ((this[keyEvent] != null) && _.isFunction(this[keyEvent])) {
3360
+ return (_ref = this[keyEvent]) != null ? _ref.call(this) : void 0;
3361
+ } else {
3362
+ return this.trigger(keyEvent, e, keyname);
3363
+ }
3364
+ }
3365
+ },
3366
+ setupControllerBindings: function() {
3367
+ var app, _ref, _ref2,
3368
+ _this = this;
3369
+ app = this;
3370
+ if ((_ref = this.getMainController()) != null) {
3371
+ _ref.bind("after:card:switch", function(previous, current) {
3372
+ _this.state.set({
3373
+ active_section: current.name
3374
+ });
3375
+ return app.trigger("page:change");
3376
+ });
3377
+ }
3378
+ return (_ref2 = this.getMainController()) != null ? _ref2.each(function(component) {
3379
+ if (component.ctype.match(/controller$/)) {
3380
+ return component.bind("after:card:switch", function(previous, current) {
3381
+ _this.state.set({
3382
+ active_sub_section: current.name
3383
+ });
3384
+ return app.trigger("sub:page:change");
3385
+ });
3386
+ }
3387
+ }) : void 0;
3388
+ },
3389
+ setupMainController: function() {
3390
+ var definedComponents;
3391
+ if (this.useController === true) {
3392
+ definedComponents = this.components || [];
3393
+ this.components = [
3394
+ {
3395
+ ctype: 'controller',
3396
+ name: "main_controller",
3397
+ components: definedComponents
3398
+ }
3399
+ ];
3400
+ return this.defer(this.setupControllerBindings, false).until("after:components");
3401
+ }
3402
+ },
3403
+ setupCollectionManager: function() {
3404
+ var collectionManagerOptions, _base, _ref, _ref2;
3405
+ if (this.useCollectionManager === true) {
3406
+ if (_.isString(this.collectionManagerClass)) {
3407
+ this.collectionManagerClass = Luca.util.resolve(this.collectionManagerClass);
3408
+ }
3409
+ collectionManagerOptions = this.collectionManagerOptions;
3410
+ if (_.isObject(this.collectionManager) && !_.isFunction((_ref = this.collectionManager) != null ? _ref.get : void 0)) {
3411
+ collectionManagerOptions = this.collectionManager;
3412
+ this.collectionManager = void 0;
3413
+ }
3414
+ if (_.isString(this.collectionManager)) {
3415
+ collectionManagerOptions = {
3416
+ name: this.collectionManager
3417
+ };
3418
+ }
3419
+ this.collectionManager = typeof (_base = Luca.CollectionManager).get === "function" ? _base.get(collectionManagerOptions.name) : void 0;
3420
+ if (!_.isFunction((_ref2 = this.collectionManager) != null ? _ref2.get : void 0)) {
3421
+ return this.collectionManager = new this.collectionManagerClass(collectionManagerOptions);
3422
+ }
3423
+ }
3424
+ },
3425
+ setupRouter: function() {
3426
+ var app, routerClass;
3427
+ app = this;
3428
+ if (_.isString(this.router)) {
3429
+ routerClass = Luca.util.resolve(this.router);
3430
+ this.router = new routerClass({
3431
+ app: app
3432
+ });
3433
+ }
3434
+ if (this.router && this.autoStartHistory) {
3435
+ if (this.autoStartHistory === true) {
3436
+ this.autoStartHistory = "before:render";
3437
+ }
3438
+ return this.defer(startHistory, false).until(this, this.autoStartHistory);
3439
+ }
3440
+ },
3441
+ setupKeyHandler: function() {
3442
+ var handler, keyEvent, _base, _i, _len, _ref, _results;
3443
+ if (!this.keyEvents) return;
3444
+ (_base = this.keyEvents).control_meta || (_base.control_meta = {});
3445
+ if (this.keyEvents.meta_control) {
3446
+ _.extend(this.keyEvents.control_meta, this.keyEvents.meta_control);
3447
+ }
3448
+ handler = _.bind(this.keyHandler, this);
3449
+ _ref = this.keypressEvents || ["keydown"];
3450
+ _results = [];
3451
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3452
+ keyEvent = _ref[_i];
3453
+ _results.push($(document).on(keyEvent, handler));
3454
+ }
3455
+ return _results;
3456
+ }
3457
+ });
3458
+
3459
+ }).call(this);
3460
+ (function() {
3461
+
3462
+ _.def('Luca.components.Toolbar')["extends"]('Luca.core.Container')["with"]({
3463
+ className: 'luca-ui-toolbar toolbar',
3464
+ position: 'bottom',
3465
+ initialize: function(options) {
3466
+ this.options = options != null ? options : {};
3467
+ return Luca.core.Container.prototype.initialize.apply(this, arguments);
3468
+ },
3469
+ prepareComponents: function() {
3470
+ var _this = this;
3471
+ return _(this.components).each(function(component) {
3472
+ return component.container = _this.$el;
3473
+ });
3474
+ },
3475
+ render: function() {
3476
+ return $(this.container).append(this.el);
3477
+ }
3478
+ });
3479
+
3480
+ }).call(this);
3481
+ (function() {
3482
+
3483
+ _.def('Luca.components.CollectionLoaderView')["extends"]('Luca.components.Template')["with"]({
3484
+ className: 'luca-ui-collection-loader-view',
3485
+ template: "components/collection_loader_view",
3486
+ initialize: function(options) {
3487
+ this.options = options != null ? options : {};
3488
+ Luca.components.Template.prototype.initialize.apply(this, arguments);
3489
+ this.container || (this.container = $('body'));
3490
+ this.manager || (this.manager = Luca.CollectionManager.get());
3491
+ return this.setupBindings();
3492
+ },
3493
+ modalContainer: function() {
3494
+ return $("#progress-modal", this.el);
3495
+ },
3496
+ setupBindings: function() {
3497
+ var _this = this;
3498
+ this.manager.bind("collection_loaded", function(name) {
3499
+ var collectionName, loaded, progress, total;
3500
+ loaded = _this.manager.loadedCollectionsCount();
3501
+ total = _this.manager.totalCollectionsCount();
3502
+ progress = parseInt((loaded / total) * 100);
3503
+ collectionName = _.string.titleize(_.string.humanize(name));
3504
+ _this.modalContainer().find('.progress .bar').attr("style", "width: " + progress + "%;");
3505
+ return _this.modalContainer().find('.message').html("Loaded " + collectionName + "...");
3506
+ });
3507
+ return this.manager.bind("all_collections_loaded", function() {
3508
+ _this.modalContainer().find('.message').html("All done!");
3509
+ return _.delay(function() {
3510
+ return _this.modalContainer().modal('hide');
3511
+ }, 400);
3512
+ });
3513
+ }
3514
+ });
3515
+
3516
+ }).call(this);
3517
+ (function() {
3518
+ var collectionView, make, setupChangeObserver;
3519
+
3520
+ collectionView = Luca.define("Luca.components.CollectionView");
3521
+
3522
+ collectionView["extends"]("Luca.components.Panel");
3523
+
3524
+ collectionView.behavesAs("LoadMaskable", "Filterable", "Paginatable");
3525
+
3526
+ collectionView.defaultsTo({
3527
+ tagName: "ol",
3528
+ className: "luca-ui-collection-view",
3529
+ bodyClassName: "collection-ui-panel",
3530
+ itemTemplate: void 0,
3531
+ itemRenderer: void 0,
3532
+ itemTagName: 'li',
3533
+ itemClassName: 'collection-item',
3534
+ hooks: ["before:refresh", "empty:results", "after:refresh"],
3535
+ initialize: function(options) {
3536
+ var _this = this;
3537
+ this.options = options != null ? options : {};
3538
+ _.extend(this, this.options);
3539
+ _.bindAll(this, "refresh");
3540
+ if (!((this.collection != null) || this.options.collection)) {
3541
+ throw "Collection Views must specify a collection";
3542
+ }
3543
+ if (!((this.itemTemplate != null) || (this.itemRenderer != null) || (this.itemProperty != null))) {
3544
+ throw "Collection Views must specify an item template or item renderer function";
3545
+ }
3546
+ Luca.components.Panel.prototype.initialize.apply(this, arguments);
3547
+ if (_.isString(this.collection) && Luca.CollectionManager.get()) {
3548
+ this.collection = Luca.CollectionManager.get().getOrCreate(this.collection);
3549
+ }
3550
+ if (!Luca.isBackboneCollection(this.collection)) {
3551
+ throw "Collection Views must have a valid backbone collection";
3552
+ this.collection.on("before:fetch", function() {
3553
+ if (_this.loadMask === true) return _this.trigger("enable:loadmask");
3554
+ });
3555
+ this.collection.bind("reset", function() {
3556
+ _this.trigger("collection:change");
3557
+ if (_this.loadMask === true) return _this.trigger("disable:loadmask");
3558
+ });
3559
+ this.collection.bind("remove", function() {
3560
+ return _this.trigger("collection:change");
3561
+ });
3562
+ this.collection.bind("add", function() {
3563
+ return _this.trigger("collection:change");
3564
+ });
3565
+ if (this.observeChanges === true) setupChangeObserver.call(this);
3566
+ }
3567
+ if (this.autoRefreshOnModelsPresent !== false) {
3568
+ this.defer(function() {
3569
+ if (_this.collection.length > 0) return _this.refresh();
3570
+ }).until("after:render");
3571
+ }
3572
+ return this.on("collection:change", this.refresh, this);
3573
+ },
3574
+ attributesForItem: function(item, model) {
3575
+ return _.extend({}, {
3576
+ "class": this.itemClassName,
3577
+ "data-index": item.index,
3578
+ "data-model-id": item.model.get('id')
3579
+ });
3580
+ },
3581
+ contentForItem: function(item) {
3582
+ var content, templateFn;
3583
+ if (item == null) item = {};
3584
+ if ((this.itemTemplate != null) && (templateFn = Luca.template(this.itemTemplate))) {
3585
+ return content = templateFn.call(this, item);
3586
+ }
3587
+ if ((this.itemRenderer != null) && _.isFunction(this.itemRenderer)) {
3588
+ return content = this.itemRenderer.call(this, item, item.model, item.index);
3589
+ }
3590
+ if (this.itemProperty && (item.model != null)) {
3591
+ return content = item.model.read(this.itemProperty);
3592
+ }
3593
+ return "";
3594
+ },
3595
+ makeItem: function(model, index) {
3596
+ var attributes, content, item;
3597
+ item = this.prepareItem != null ? this.prepareItem.call(this, model, index) : {
3598
+ model: model,
3599
+ index: index
3600
+ };
3601
+ attributes = this.attributesForItem(item, model);
3602
+ content = this.contentForItem(item);
3603
+ try {
3604
+ return make(this.itemTagName, attributes, content);
3605
+ } catch (e) {
3606
+ return console.log("Error generating DOM element for CollectionView", this, model, index);
3607
+ }
3608
+ },
3609
+ getCollection: function() {
3610
+ return this.collection;
3611
+ },
3612
+ getQuery: function() {
3613
+ return {};
3614
+ },
3615
+ getQueryOptions: function() {
3616
+ return {};
3617
+ },
3618
+ getModels: function(query, options) {
3619
+ var _ref;
3620
+ if ((_ref = this.collection) != null ? _ref.query : void 0) {
3621
+ query || (query = this.getQuery());
3622
+ options || (options = this.getQueryOptions());
3623
+ return this.collection.query(query, options);
3624
+ } else {
3625
+ return this.collection.models;
3626
+ }
3627
+ },
3628
+ locateItemElement: function(id) {
3629
+ return this.$("." + this.itemClassName + "[data-model-id='" + id + "']");
3630
+ },
3631
+ refreshModel: function(model) {
3632
+ var index;
3633
+ index = this.collection.indexOf(model);
3634
+ return this.locateItemElement(model.get('id')).empty().append(this.contentForItem({
3635
+ model: model,
3636
+ index: index
3637
+ }, model));
3638
+ },
3639
+ refresh: function(query, options) {
3640
+ var index, model, models, _i, _len;
3641
+ this.$bodyEl().empty();
3642
+ models = this.getModels(query, options);
3643
+ this.trigger("before:refresh", models, query, options);
3644
+ if (models.length === 0) this.trigger("empty:results");
3645
+ index = 0;
3646
+ for (_i = 0, _len = models.length; _i < _len; _i++) {
3647
+ model = models[_i];
3648
+ this.$append(this.makeItem(model, index++));
3649
+ }
3650
+ this.trigger("after:refresh", models, query, options);
3651
+ return this;
3652
+ },
3653
+ registerEvent: function(domEvent, selector, handler) {
3654
+ var eventTrigger;
3655
+ if (!(handler != null) && _.isFunction(selector)) {
3656
+ handler = selector;
3657
+ selector = void 0;
3658
+ }
3659
+ eventTrigger = _([domEvent, "" + this.itemTagName + "." + this.itemClassName, selector]).compact().join(" ");
3660
+ return Luca.View.prototype.registerEvent(eventTrigger, handler);
3661
+ },
3662
+ render: function() {
3663
+ this.refresh();
3664
+ if (this.$el.parent().length > 0 && (this.container != null)) this.$attach();
3665
+ return this;
3666
+ }
3667
+ });
3668
+
3669
+ make = Luca.View.prototype.make;
3670
+
3671
+ setupChangeObserver = function() {
3672
+ var _this = this;
3673
+ return this.collection.on("change", function(model) {
3674
+ return _this.refreshModel(model);
3675
+ });
3676
+ };
3677
+
3678
+ }).call(this);
3679
+ (function() {
3680
+
3681
+ _.def('Luca.components.Controller')["extends"]('Luca.containers.CardView')["with"]({
3682
+ additionalClassNames: ['luca-ui-controller'],
3683
+ activeAttribute: "active-section",
3684
+ initialize: function(options) {
3685
+ var _ref;
3686
+ this.options = options;
3687
+ Luca.containers.CardView.prototype.initialize.apply(this, arguments);
3688
+ this.defaultCard || (this.defaultCard = (_ref = this.components[0]) != null ? _ref.name : void 0);
3689
+ if (!this.defaultCard) {
3690
+ throw "Controllers must specify a defaultCard property and/or the first component must have a name";
3691
+ }
3692
+ return this.state = new Backbone.Model({
3693
+ active_section: this.defaultCard
3694
+ });
3695
+ },
3696
+ each: function(fn) {
3697
+ var _this = this;
3698
+ return _(this.components).each(function(component) {
3699
+ return fn.apply(_this, [component]);
3700
+ });
3701
+ },
3702
+ activeSection: function() {
3703
+ return this.get("activeSection");
3704
+ },
3705
+ controllers: function(deep) {
3706
+ if (deep == null) deep = false;
3707
+ return this.select('ctype', 'controller', deep);
3708
+ },
3709
+ availableSections: function() {
3710
+ var base,
3711
+ _this = this;
3712
+ base = {};
3713
+ base[this.name] = this.sectionNames();
3714
+ return _(this.controllers()).reduce(function(memo, controller) {
3715
+ memo[controller.name] = controller.sectionNames();
3716
+ return memo;
3717
+ }, base);
3718
+ },
3719
+ sectionNames: function(deep) {
3720
+ if (deep == null) deep = false;
3721
+ return this.pluck('name');
3722
+ },
3723
+ "default": function(callback) {
3724
+ return this.navigate_to(this.defaultCard, callback);
3725
+ },
3726
+ navigate_to: function(section, callback) {
3727
+ var _this = this;
3728
+ section || (section = this.defaultCard);
3729
+ this.activate(section, false, function(activator, previous, current) {
3730
+ _this.state.set({
3731
+ active_section: current.name
3732
+ });
3733
+ if (_.isFunction(callback)) return callback.apply(current);
3734
+ });
3735
+ return this.find(section);
3736
+ }
3737
+ });
3738
+
2619
3739
  }).call(this);
3740
+ (function() {
3741
+
3742
+ _.def('Luca.fields.ButtonField')["extends"]('Luca.core.Field')["with"]({
3743
+ readOnly: true,
3744
+ events: {
3745
+ "click input": "click_handler"
3746
+ },
3747
+ hooks: ["button:click"],
3748
+ className: 'luca-ui-field luca-ui-button-field',
3749
+ template: 'fields/button_field',
3750
+ click_handler: function(e) {
3751
+ var me, my;
3752
+ me = my = $(e.currentTarget);
3753
+ return this.trigger("button:click");
3754
+ },
3755
+ initialize: function(options) {
3756
+ var _ref;
3757
+ this.options = options != null ? options : {};
3758
+ _.extend(this.options);
3759
+ _.bindAll(this, "click_handler");
3760
+ Luca.core.Field.prototype.initialize.apply(this, arguments);
3761
+ if ((_ref = this.icon_class) != null ? _ref.length : void 0) {
3762
+ return this.template = "fields/button_field_link";
3763
+ }
3764
+ },
3765
+ afterInitialize: function() {
3766
+ this.input_id || (this.input_id = _.uniqueId('button'));
3767
+ this.input_name || (this.input_name = this.name || (this.name = this.input_id));
3768
+ this.input_value || (this.input_value = this.label || (this.label = this.text));
3769
+ this.input_type || (this.input_type = "button");
3770
+ this.input_class || (this.input_class = this["class"]);
3771
+ this.icon_class || (this.icon_class = "");
3772
+ if (this.icon_class.length && !this.icon_class.match(/^icon-/)) {
3773
+ this.icon_class = "icon-" + this.icon_class;
3774
+ }
3775
+ if (this.white) return this.icon_class += " icon-white";
3776
+ },
3777
+ setValue: function() {
3778
+ return true;
3779
+ }
3780
+ });
3781
+
3782
+ }).call(this);
3783
+ (function() {
3784
+ var make;
3785
+
3786
+ make = Luca.View.prototype.make;
3787
+
3788
+ _.def('Luca.fields.CheckboxArray')["extends"]('Luca.core.Field')["with"]({
3789
+ version: 2,
3790
+ template: "fields/checkbox_array",
3791
+ className: "luca-ui-checkbox-array",
3792
+ events: {
3793
+ "click input": "clickHandler"
3794
+ },
3795
+ selectedItems: [],
3796
+ initialize: function(options) {
3797
+ this.options = options != null ? options : {};
3798
+ _.extend(this, this.options);
3799
+ _.extend(this, Luca.modules.Deferrable);
3800
+ _.bindAll(this, "renderCheckboxes", "clickHandler", "checkSelected");
3801
+ Luca.core.Field.prototype.initialize.apply(this, arguments);
3802
+ this.input_id || (this.input_id = _.uniqueId('field'));
3803
+ this.input_name || (this.input_name = this.name);
3804
+ this.label || (this.label = this.name);
3805
+ this.valueField || (this.valueField = "id");
3806
+ return this.displayField || (this.displayField = "name");
3807
+ },
3808
+ afterInitialize: function(options) {
3809
+ var cbArray;
3810
+ this.options = options != null ? options : {};
3811
+ try {
3812
+ this.configure_collection();
3813
+ } catch (e) {
3814
+ console.log("Error Configuring Collection", this, e.message);
3815
+ }
3816
+ cbArray = this;
3817
+ if (this.collection.length > 0) {
3818
+ return this.renderCheckboxes();
3819
+ } else {
3820
+ return this.defer("renderCheckboxes").until(this.collection, "reset");
3821
+ }
3822
+ },
3823
+ clickHandler: function(event) {
3824
+ var checkbox;
3825
+ checkbox = $(event.target);
3826
+ if (checkbox.prop('checked')) {
3827
+ return this.selectedItems.push(checkbox.val());
3828
+ } else {
3829
+ if (_(this.selectedItems).include(checkbox.val())) {
3830
+ return this.selectedItems = _(this.selectedItems).without(checkbox.val());
3831
+ }
3832
+ }
3833
+ },
3834
+ controls: function() {
3835
+ return this.$('.controls');
3836
+ },
3837
+ renderCheckboxes: function() {
3838
+ var _this = this;
3839
+ this.controls().empty();
3840
+ this.selectedItems = [];
3841
+ this.collection.each(function(model) {
3842
+ var element, inputElement, input_id, label, value;
3843
+ value = model.get(_this.valueField);
3844
+ label = model.get(_this.displayField);
3845
+ input_id = _.uniqueId("" + _this.cid + "_checkbox");
3846
+ inputElement = make("input", {
3847
+ type: "checkbox",
3848
+ "class": "array-checkbox",
3849
+ name: _this.input_name,
3850
+ value: value,
3851
+ id: input_id
3852
+ });
3853
+ element = make("label", {
3854
+ "for": input_id
3855
+ }, inputElement);
3856
+ $(element).append(" " + label);
3857
+ return _this.controls().append(element);
3858
+ });
3859
+ this.trigger("checkboxes:rendered", this.checkboxesRendered = true);
3860
+ return this;
3861
+ },
3862
+ uncheckAll: function() {
3863
+ return this.allFields().prop('checked', false);
3864
+ },
3865
+ allFields: function() {
3866
+ return this.controls().find("input[type='checkbox']");
3867
+ },
3868
+ checkSelected: function(items) {
3869
+ var checkbox, value, _i, _len, _ref;
3870
+ if (items != null) this.selectedItems = items;
3871
+ this.uncheckAll();
3872
+ _ref = this.selectedItems;
3873
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3874
+ value = _ref[_i];
3875
+ checkbox = this.controls().find("input[value='" + value + "']");
3876
+ checkbox.prop('checked', true);
3877
+ }
3878
+ return this.selectedItems;
3879
+ },
3880
+ getValue: function() {
3881
+ var field, _i, _len, _ref, _results;
3882
+ _ref = this.allFields();
3883
+ _results = [];
3884
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3885
+ field = _ref[_i];
3886
+ if (this.$(field).prop('checked')) _results.push(this.$(field).val());
3887
+ }
3888
+ return _results;
3889
+ },
3890
+ setValue: function(items) {
3891
+ var cbArray;
3892
+ this.selectedItems = items;
3893
+ if (this.checkboxesRendered === true) {
3894
+ return this.checkSelected(items);
3895
+ } else {
3896
+ cbArray = this;
3897
+ return this.defer(function() {
3898
+ return cbArray.checkSelected(items);
3899
+ }).until("checkboxes:rendered");
3900
+ }
3901
+ },
3902
+ getValues: function() {
3903
+ return this.getValue();
3904
+ },
3905
+ setValues: function(items) {
3906
+ return this.setValue(items);
3907
+ }
3908
+ });
3909
+
3910
+ }).call(this);
3911
+ (function() {
3912
+
3913
+ _.def('Luca.fields.CheckboxField')["extends"]('Luca.core.Field')["with"]({
3914
+ events: {
3915
+ "change input": "change_handler"
3916
+ },
3917
+ className: 'luca-ui-checkbox-field luca-ui-field',
3918
+ template: 'fields/checkbox_field',
3919
+ hooks: ["checked", "unchecked"],
3920
+ send_blanks: true,
3921
+ change_handler: function(e) {
3922
+ var me, my;
3923
+ me = my = $(e.target);
3924
+ if (me.is(":checked")) {
3925
+ this.trigger("checked");
3926
+ } else {
3927
+ this.trigger("unchecked");
3928
+ }
3929
+ return this.trigger("on:change", this, e, me.is(":checked"));
3930
+ },
3931
+ initialize: function(options) {
3932
+ this.options = options != null ? options : {};
3933
+ _.extend(this, this.options);
3934
+ _.bindAll(this, "change_handler");
3935
+ return Luca.core.Field.prototype.initialize.apply(this, arguments);
3936
+ },
3937
+ afterInitialize: function() {
3938
+ this.input_id || (this.input_id = _.uniqueId('field'));
3939
+ this.input_name || (this.input_name = this.name);
3940
+ this.input_value || (this.input_value = 1);
3941
+ return this.label || (this.label = this.name);
3942
+ },
3943
+ setValue: function(checked) {
3944
+ return this.input.attr('checked', checked);
3945
+ },
3946
+ getValue: function() {
3947
+ return this.input.is(":checked");
3948
+ }
3949
+ });
3950
+
3951
+ }).call(this);
3952
+ (function() {
3953
+
3954
+ _.def('Luca.fields.FileUploadField')["extends"]('Luca.core.Field')["with"]({
3955
+ template: 'fields/file_upload_field',
3956
+ initialize: function(options) {
3957
+ this.options = options != null ? options : {};
3958
+ return Luca.core.Field.prototype.initialize.apply(this, arguments);
3959
+ },
3960
+ afterInitialize: function() {
3961
+ this.input_id || (this.input_id = _.uniqueId('field'));
3962
+ this.input_name || (this.input_name = this.name);
3963
+ this.label || (this.label = this.name);
3964
+ return this.helperText || (this.helperText = "");
3965
+ }
3966
+ });
3967
+
3968
+ }).call(this);
3969
+ (function() {
3970
+
3971
+ _.def('Luca.fields.HiddenField')["extends"]('Luca.core.Field')["with"]({
3972
+ template: 'fields/hidden_field',
3973
+ initialize: function(options) {
3974
+ this.options = options != null ? options : {};
3975
+ return Luca.core.Field.prototype.initialize.apply(this, arguments);
3976
+ },
3977
+ afterInitialize: function() {
3978
+ this.input_id || (this.input_id = _.uniqueId('field'));
3979
+ this.input_name || (this.input_name = this.name);
3980
+ this.input_value || (this.input_value = this.value);
3981
+ return this.label || (this.label = this.name);
3982
+ }
3983
+ });
3984
+
3985
+ }).call(this);
3986
+ (function() {
3987
+
3988
+ _.def("Luca.components.LabelField")["extends"]("Luca.core.Field")["with"]({
3989
+ className: "luca-ui-field luca-ui-label-field",
3990
+ getValue: function() {
3991
+ return this.$('input').attr('value');
3992
+ },
3993
+ formatter: function(value) {
3994
+ value || (value = this.getValue());
3995
+ return _.str.titleize(value);
3996
+ },
3997
+ setValue: function(value) {
3998
+ this.trigger("change", value, this.getValue());
3999
+ this.$('input').attr('value', value);
4000
+ return this.$('.value').html(this.formatter(value));
4001
+ }
4002
+ });
4003
+
4004
+ }).call(this);
4005
+ (function() {
4006
+
4007
+ _.def('Luca.fields.SelectField')["extends"]('Luca.core.Field')["with"]({
4008
+ events: {
4009
+ "change select": "change_handler"
4010
+ },
4011
+ hooks: ["after:select"],
4012
+ className: 'luca-ui-select-field luca-ui-field',
4013
+ template: "fields/select_field",
4014
+ includeBlank: true,
4015
+ blankValue: '',
4016
+ blankText: 'Select One',
4017
+ initialize: function(options) {
4018
+ this.options = options != null ? options : {};
4019
+ _.extend(this, this.options);
4020
+ _.extend(this, Luca.modules.Deferrable);
4021
+ _.bindAll(this, "change_handler", "populateOptions", "beforeFetch");
4022
+ Luca.core.Field.prototype.initialize.apply(this, arguments);
4023
+ this.input_id || (this.input_id = _.uniqueId('field'));
4024
+ this.input_name || (this.input_name = this.name);
4025
+ this.label || (this.label = this.name);
4026
+ if (_.isUndefined(this.retainValue)) return this.retainValue = true;
4027
+ },
4028
+ afterInitialize: function() {
4029
+ var _ref;
4030
+ if ((_ref = this.collection) != null ? _ref.data : void 0) {
4031
+ this.valueField || (this.valueField = "id");
4032
+ this.displayField || (this.displayField = "name");
4033
+ this.parseData();
4034
+ }
4035
+ try {
4036
+ this.configure_collection();
4037
+ } catch (e) {
4038
+ console.log("Error Configuring Collection", this, e.message);
4039
+ }
4040
+ this.collection.bind("before:fetch", this.beforeFetch);
4041
+ return this.collection.bind("reset", this.populateOptions);
4042
+ },
4043
+ parseData: function() {
4044
+ var _this = this;
4045
+ return this.collection.data = _(this.collection.data).map(function(record) {
4046
+ var hash;
4047
+ if (!_.isArray(record)) return record;
4048
+ hash = {};
4049
+ hash[_this.valueField] = record[0];
4050
+ hash[_this.displayField] = record[1] || record[0];
4051
+ return hash;
4052
+ });
4053
+ },
4054
+ afterRender: function() {
4055
+ var _ref, _ref2;
4056
+ this.input = $('select', this.el);
4057
+ if (((_ref = this.collection) != null ? (_ref2 = _ref.models) != null ? _ref2.length : void 0 : void 0) > 0) {
4058
+ return this.populateOptions();
4059
+ } else {
4060
+ return this.collection.trigger("reset");
4061
+ }
4062
+ },
4063
+ setValue: function(value) {
4064
+ this.currentValue = value;
4065
+ return Luca.core.Field.prototype.setValue.apply(this, arguments);
4066
+ },
4067
+ beforeFetch: function() {
4068
+ return this.resetOptions();
4069
+ },
4070
+ change_handler: function(e) {
4071
+ return this.trigger("on:change", this, e);
4072
+ },
4073
+ resetOptions: function() {
4074
+ this.input.html('');
4075
+ if (this.includeBlank) {
4076
+ return this.input.append("<option value='" + this.blankValue + "'>" + this.blankText + "</option>");
4077
+ }
4078
+ },
4079
+ populateOptions: function() {
4080
+ var _ref,
4081
+ _this = this;
4082
+ this.resetOptions();
4083
+ if (((_ref = this.collection) != null ? _ref.each : void 0) != null) {
4084
+ this.collection.each(function(model) {
4085
+ var display, option, selected, value;
4086
+ value = model.get(_this.valueField);
4087
+ display = model.get(_this.displayField);
4088
+ if (_this.selected && value === _this.selected) selected = "selected";
4089
+ option = "<option " + selected + " value='" + value + "'>" + display + "</option>";
4090
+ return _this.input.append(option);
4091
+ });
4092
+ }
4093
+ this.trigger("after:populate:options", this);
4094
+ return this.setValue(this.currentValue);
4095
+ }
4096
+ });
4097
+
4098
+ }).call(this);
4099
+ (function() {
4100
+
4101
+ _.def('Luca.fields.TextAreaField')["extends"]('Luca.core.Field')["with"]({
4102
+ events: {
4103
+ "keydown input": "keydown_handler",
4104
+ "blur input": "blur_handler",
4105
+ "focus input": "focus_handler"
4106
+ },
4107
+ template: 'fields/text_area_field',
4108
+ height: "200px",
4109
+ width: "90%",
4110
+ initialize: function(options) {
4111
+ this.options = options != null ? options : {};
4112
+ _.bindAll(this, "keydown_handler");
4113
+ Luca.core.Field.prototype.initialize.apply(this, arguments);
4114
+ this.input_id || (this.input_id = _.uniqueId('field'));
4115
+ this.input_name || (this.input_name = this.name);
4116
+ this.label || (this.label = this.name);
4117
+ this.input_class || (this.input_class = this["class"]);
4118
+ this.input_value || (this.input_value = "");
4119
+ return this.inputStyles || (this.inputStyles = "height:" + this.height + ";width:" + this.width);
4120
+ },
4121
+ setValue: function(value) {
4122
+ return $(this.field()).val(value);
4123
+ },
4124
+ getValue: function() {
4125
+ return $(this.field()).val();
4126
+ },
4127
+ field: function() {
4128
+ return this.input = $("textarea#" + this.input_id, this.el);
4129
+ },
4130
+ keydown_handler: function(e) {
4131
+ var me, my;
4132
+ return me = my = $(e.currentTarget);
4133
+ },
4134
+ blur_handler: function(e) {
4135
+ var me, my;
4136
+ return me = my = $(e.currentTarget);
4137
+ },
4138
+ focus_handler: function(e) {
4139
+ var me, my;
4140
+ return me = my = $(e.currentTarget);
4141
+ }
4142
+ });
4143
+
4144
+ }).call(this);
4145
+ (function() {
4146
+
4147
+ _.def('Luca.fields.TextField')["extends"]('Luca.core.Field')["with"]({
4148
+ events: {
4149
+ "blur input": "blur_handler",
4150
+ "focus input": "focus_handler",
4151
+ "change input": "change_handler"
4152
+ },
4153
+ template: 'fields/text_field',
4154
+ autoBindEventHandlers: true,
4155
+ send_blanks: true,
4156
+ keyEventThrottle: 300,
4157
+ initialize: function(options) {
4158
+ this.options = options != null ? options : {};
4159
+ if (this.enableKeyEvents) this.registerEvent("keyup input", "keyup_handler");
4160
+ this.input_id || (this.input_id = _.uniqueId('field'));
4161
+ this.input_name || (this.input_name = this.name);
4162
+ this.label || (this.label = this.name);
4163
+ this.input_class || (this.input_class = this["class"]);
4164
+ this.input_value || (this.input_value = this.value || "");
4165
+ if (this.prepend) {
4166
+ this.$el.addClass('input-prepend');
4167
+ this.addOn = this.prepend;
4168
+ }
4169
+ if (this.append) {
4170
+ this.$el.addClass('input-append');
4171
+ this.addOn = this.append;
4172
+ }
4173
+ return Luca.core.Field.prototype.initialize.apply(this, arguments);
4174
+ },
4175
+ keyup_handler: function(e) {
4176
+ return this.trigger("on:keyup", this, e);
4177
+ },
4178
+ blur_handler: function(e) {
4179
+ return this.trigger("on:blur", this, e);
4180
+ },
4181
+ focus_handler: function(e) {
4182
+ return this.trigger("on:focus", this, e);
4183
+ },
4184
+ change_handler: function(e) {
4185
+ return this.trigger("on:change", this, e);
4186
+ }
4187
+ });
4188
+
4189
+ }).call(this);
4190
+ (function() {
4191
+
4192
+ _.def('Luca.fields.TypeAheadField')["extends"]('Luca.fields.TextField')["with"]({
4193
+ className: 'luca-ui-field',
4194
+ getSource: function() {
4195
+ if (_.isFunction(this.source)) return this.source.call(this);
4196
+ return this.source || [];
4197
+ },
4198
+ matcher: function(item) {
4199
+ return true;
4200
+ },
4201
+ beforeRender: function() {
4202
+ this._super("beforeRender", this, arguments);
4203
+ return this.$('input').attr('data-provide', 'typeahead');
4204
+ },
4205
+ afterRender: function() {
4206
+ this._super("afterRender", this, arguments);
4207
+ return this.$('input').typeahead({
4208
+ matcher: this.matcher,
4209
+ source: this.getSource()
4210
+ });
4211
+ }
4212
+ });
4213
+
4214
+ }).call(this);
4215
+ (function() {
4216
+
4217
+ _.def('Luca.components.FormButtonToolbar')["extends"]('Luca.components.Toolbar')["with"]({
4218
+ className: 'luca-ui-form-toolbar form-actions',
4219
+ position: 'bottom',
4220
+ includeReset: false,
4221
+ render: function() {
4222
+ return $(this.container).append(this.el);
4223
+ },
4224
+ initialize: function(options) {
4225
+ this.options = options != null ? options : {};
4226
+ Luca.components.Toolbar.prototype.initialize.apply(this, arguments);
4227
+ this.components = [
4228
+ {
4229
+ ctype: 'button_field',
4230
+ label: 'Submit',
4231
+ "class": 'btn submit-button'
4232
+ }
4233
+ ];
4234
+ if (this.includeReset) {
4235
+ return this.components.push({
4236
+ ctype: 'button_field',
4237
+ label: 'Reset',
4238
+ "class": 'btn reset-button'
4239
+ });
4240
+ }
4241
+ }
4242
+ });
4243
+
4244
+ }).call(this);
4245
+ (function() {
4246
+ var defaultToolbar;
4247
+
4248
+ defaultToolbar = {
4249
+ buttons: [
4250
+ {
4251
+ icon: "remove-sign",
4252
+ label: "Reset",
4253
+ eventId: "click:reset",
4254
+ className: "reset-button",
4255
+ align: 'right'
4256
+ }, {
4257
+ icon: "ok-sign",
4258
+ white: true,
4259
+ label: "Save Changes",
4260
+ eventId: "click:submit",
4261
+ color: "success",
4262
+ className: 'submit-button',
4263
+ align: 'right'
4264
+ }
4265
+ ]
4266
+ };
4267
+
4268
+ _.def("Luca.components.FormView")["extends"]('Luca.core.Container')["with"]({
4269
+ tagName: 'form',
4270
+ className: 'luca-ui-form-view',
4271
+ hooks: ["before:submit", "before:reset", "before:load", "before:load:new", "before:load:existing", "after:submit", "after:reset", "after:load", "after:load:new", "after:load:existing", "after:submit:success", "after:submit:fatal_error", "after:submit:error"],
4272
+ events: {
4273
+ "click .submit-button": "submitHandler",
4274
+ "click .reset-button": "resetHandler"
4275
+ },
4276
+ toolbar: true,
4277
+ legend: "",
4278
+ bodyClassName: "form-view-body",
4279
+ version: "0.9.33333333",
4280
+ initialize: function(options) {
4281
+ this.options = options != null ? options : {};
4282
+ if (this.loadMask == null) this.loadMask = Luca.enableBootstrap;
4283
+ Luca.core.Container.prototype.initialize.apply(this, arguments);
4284
+ this.components || (this.components = this.fields);
4285
+ _.bindAll(this, "submitHandler", "resetHandler", "renderToolbars", "applyLoadMask");
4286
+ this.state || (this.state = new Backbone.Model);
4287
+ this.setupHooks(this.hooks);
4288
+ this.applyStyleClasses();
4289
+ if (this.toolbar !== false && (!this.topToolbar && !this.bottomToolbar)) {
4290
+ if (this.toolbar === "both" || this.toolbar === "top") {
4291
+ this.topToolbar = this.getDefaultToolbar();
4292
+ }
4293
+ if (this.toolbar !== "top") {
4294
+ return this.bottomToolbar = this.getDefaultToolbar();
4295
+ }
4296
+ }
4297
+ },
4298
+ getDefaultToolbar: function() {
4299
+ return defaultToolbar;
4300
+ },
4301
+ applyStyleClasses: function() {
4302
+ if (Luca.enableBootstrap) this.applyBootstrapStyleClasses();
4303
+ if (this.labelAlign) this.$el.addClass("label-align-" + this.labelAlign);
4304
+ if (this.fieldLayoutClass) return this.$el.addClass(this.fieldLayoutClass);
4305
+ },
4306
+ applyBootstrapStyleClasses: function() {
4307
+ if (this.labelAlign === "left") this.inlineForm = true;
4308
+ if (this.well) this.$el.addClass('well');
4309
+ if (this.searchForm) this.$el.addClass('form-search');
4310
+ if (this.horizontalForm) this.$el.addClass('form-horizontal');
4311
+ if (this.inlineForm) return this.$el.addClass('form-inline');
4312
+ },
4313
+ resetHandler: function(e) {
4314
+ var me, my;
4315
+ me = my = $(e != null ? e.target : void 0);
4316
+ this.trigger("before:reset", this);
4317
+ this.reset();
4318
+ return this.trigger("after:reset", this);
4319
+ },
4320
+ submitHandler: function(e) {
4321
+ var me, my;
4322
+ me = my = $(e != null ? e.target : void 0);
4323
+ this.trigger("before:submit", this);
4324
+ if (this.loadMask === true) this.trigger("enable:loadmask", this);
4325
+ if (this.hasModel()) return this.submit();
4326
+ },
4327
+ afterComponents: function() {
4328
+ var _ref,
4329
+ _this = this;
4330
+ if ((_ref = Luca.core.Container.prototype.afterComponents) != null) {
4331
+ _ref.apply(this, arguments);
4332
+ }
4333
+ return this.eachField(function(field) {
4334
+ field.getForm = function() {
4335
+ return _this;
4336
+ };
4337
+ return field.getModel = function() {
4338
+ return _this.currentModel();
4339
+ };
4340
+ });
4341
+ },
4342
+ eachField: function(iterator) {
4343
+ return _(this.getFields()).map(iterator);
4344
+ },
4345
+ getField: function(name) {
4346
+ var passOne;
4347
+ passOne = _(this.getFields('name', name)).first();
4348
+ if (passOne != null) return passOne;
4349
+ return _(this.getFields('input_name', name)).first();
4350
+ },
4351
+ getFields: function(attr, value) {
4352
+ var fields;
4353
+ fields = this.selectByAttribute("isField", true, true);
4354
+ if ((attr != null) && (value != null)) {
4355
+ fields = _(fields).select(function(field) {
4356
+ var property;
4357
+ property = field[attr];
4358
+ if (_.isFunction(property)) property = property.call(field);
4359
+ return property === value;
4360
+ });
4361
+ }
4362
+ return fields;
4363
+ },
4364
+ loadModel: function(current_model) {
4365
+ var event, fields, form, _ref;
4366
+ this.current_model = current_model;
4367
+ form = this;
4368
+ fields = this.getFields();
4369
+ this.trigger("before:load", this, this.current_model);
4370
+ if (this.current_model) {
4371
+ if ((_ref = this.current_model.beforeFormLoad) != null) {
4372
+ _ref.apply(this.current_model, this);
4373
+ }
4374
+ event = "before:load:" + (this.current_model.isNew() ? "new" : "existing");
4375
+ this.trigger(event, this, this.current_model);
4376
+ }
4377
+ this.setValues(this.current_model);
4378
+ this.trigger("after:load", this, this.current_model);
4379
+ if (this.current_model) {
4380
+ return this.trigger("after:load:" + (this.current_model.isNew() ? "new" : "existing"), this, this.current_model);
4381
+ }
4382
+ },
4383
+ reset: function() {
4384
+ if (this.current_model != null) return this.loadModel(this.current_model);
4385
+ },
4386
+ clear: function() {
4387
+ var _this = this;
4388
+ this.current_model = this.defaultModel != null ? this.defaultModel() : void 0;
4389
+ return _(this.getFields()).each(function(field) {
4390
+ try {
4391
+ return field.setValue('');
4392
+ } catch (e) {
4393
+ return console.log("Error Clearing", _this, field);
4394
+ }
4395
+ });
4396
+ },
4397
+ setValues: function(source, options) {
4398
+ var fields,
4399
+ _this = this;
4400
+ if (options == null) options = {};
4401
+ source || (source = this.currentModel());
4402
+ fields = this.getFields();
4403
+ _(fields).each(function(field) {
4404
+ var field_name, value;
4405
+ field_name = field.input_name || field.name;
4406
+ if (value = source[field_name]) {
4407
+ if (_.isFunction(value)) value = value.apply(_this);
4408
+ }
4409
+ if (!value && Luca.isBackboneModel(source)) value = source.get(field_name);
4410
+ if (field.readOnly !== true) {
4411
+ return field != null ? field.setValue(value) : void 0;
4412
+ }
4413
+ });
4414
+ if ((options.silent != null) !== true) return this.syncFormWithModel();
4415
+ },
4416
+ getValues: function(options) {
4417
+ var values,
4418
+ _this = this;
4419
+ if (options == null) options = {};
4420
+ if (options.reject_blank == null) options.reject_blank = true;
4421
+ if (options.skip_buttons == null) options.skip_buttons = true;
4422
+ if (options.blanks === false) options.reject_blank = true;
4423
+ values = _(this.getFields()).inject(function(memo, field) {
4424
+ var allowBlankValues, key, skip, value, valueIsBlank;
4425
+ value = field.getValue();
4426
+ key = field.input_name || field.name;
4427
+ valueIsBlank = !!(_.str.isBlank(value) || _.isUndefined(value));
4428
+ allowBlankValues = !options.reject_blank && !field.send_blanks;
4429
+ if (options.debug) {
4430
+ console.log("" + key + " Options", options, "Value", value, "Value Is Blank?", valueIsBlank, "Allow Blanks?", allowBlankValues);
4431
+ }
4432
+ if (options.skip_buttons && field.ctype === "button_field") {
4433
+ skip = true;
4434
+ } else {
4435
+ if (valueIsBlank && allowBlankValues === false) skip = true;
4436
+ if (field.input_name === "id" && valueIsBlank === true) skip = true;
4437
+ }
4438
+ if (options.debug) console.log("Skip is true on " + key);
4439
+ if (skip !== true) memo[key] = value;
4440
+ return memo;
4441
+ }, options.defaults || {});
4442
+ return values;
4443
+ },
4444
+ submit_success_handler: function(model, response, xhr) {
4445
+ this.trigger("after:submit", this, model, response);
4446
+ if (this.loadMask === true) this.trigger("disable:loadmask", this);
4447
+ if (response && (response != null ? response.success : void 0) === true) {
4448
+ return this.trigger("after:submit:success", this, model, response);
4449
+ } else {
4450
+ return this.trigger("after:submit:error", this, model, response);
4451
+ }
4452
+ },
4453
+ submit_fatal_error_handler: function(model, response, xhr) {
4454
+ this.trigger("after:submit", this, model, response);
4455
+ return this.trigger("after:submit:fatal_error", this, model, response);
4456
+ },
4457
+ submit: function(save, saveOptions) {
4458
+ if (save == null) save = true;
4459
+ if (saveOptions == null) saveOptions = {};
4460
+ _.bindAll(this, "submit_success_handler", "submit_fatal_error_handler");
4461
+ saveOptions.success || (saveOptions.success = this.submit_success_handler);
4462
+ saveOptions.error || (saveOptions.error = this.submit_fatal_error_handler);
4463
+ this.syncFormWithModel();
4464
+ if (!save) return;
4465
+ return this.current_model.save(this.current_model.toJSON(), saveOptions);
4466
+ },
4467
+ hasModel: function() {
4468
+ return this.current_model != null;
4469
+ },
4470
+ currentModel: function(options) {
4471
+ if (options == null) options = {};
4472
+ if (options === true || (options != null ? options.refresh : void 0) === true) {
4473
+ this.syncFormWithModel();
4474
+ }
4475
+ return this.current_model;
4476
+ },
4477
+ syncFormWithModel: function() {
4478
+ var _ref;
4479
+ return (_ref = this.current_model) != null ? _ref.set(this.getValues()) : void 0;
4480
+ },
4481
+ setLegend: function(legend) {
4482
+ this.legend = legend;
4483
+ return $('fieldset legend', this.el).first().html(this.legend);
4484
+ },
4485
+ flash: function(message) {
4486
+ if (this.$('.toolbar-container.top').length > 0) {
4487
+ return this.$('.toolbar-container.top').after(message);
4488
+ } else {
4489
+ return this.$bodyEl().prepend(message);
4490
+ }
4491
+ },
4492
+ successFlashDelay: 1500,
4493
+ successMessage: function(message) {
4494
+ var _this = this;
4495
+ this.$('.alert.alert-success').remove();
4496
+ this.flash(Luca.template("components/form_alert", {
4497
+ className: "alert alert-success",
4498
+ message: message
4499
+ }));
4500
+ return _.delay(function() {
4501
+ return _this.$('.alert.alert-success').fadeOut();
4502
+ }, this.successFlashDelay || 0);
4503
+ },
4504
+ errorMessage: function(message) {
4505
+ this.$('.alert.alert-error').remove();
4506
+ return this.flash(Luca.template("components/form_alert", {
4507
+ className: "alert alert-error",
4508
+ message: message
4509
+ }));
4510
+ }
4511
+ });
4512
+
4513
+ }).call(this);
4514
+ (function() {
4515
+
4516
+ _.def('Luca.components.GridView').extend('Luca.components.Panel')["with"]({
4517
+ bodyTemplate: "components/grid_view",
4518
+ autoBindEventHandlers: true,
4519
+ events: {
4520
+ "dblclick table tbody tr": "double_click_handler",
4521
+ "click table tbody tr": "click_handler"
4522
+ },
4523
+ className: 'luca-ui-g-view',
4524
+ rowClass: "luca-ui-g-row",
4525
+ wrapperClass: "luca-ui-g-view-wrapper",
4526
+ additionalWrapperClasses: [],
4527
+ wrapperStyles: {},
4528
+ scrollable: true,
4529
+ emptyText: 'No Results To display.',
4530
+ tableStyle: 'striped',
4531
+ defaultHeight: 285,
4532
+ defaultWidth: 756,
4533
+ maxWidth: void 0,
4534
+ hooks: ["before:grid:render", "before:render:header", "before:render:row", "after:grid:render", "row:double:click", "row:click", "after:collection:load"],
4535
+ initialize: function(options) {
4536
+ var _this = this;
4537
+ this.options = options != null ? options : {};
4538
+ _.extend(this, this.options);
4539
+ _.extend(this, Luca.modules.Deferrable);
4540
+ if (this.loadMask == null) this.loadMask = Luca.enableBootstrap;
4541
+ if (this.loadMask === true) {
4542
+ this.loadMaskEl || (this.loadMaskEl = ".luca-ui-g-view-body");
4543
+ }
4544
+ Luca.components.Panel.prototype.initialize.apply(this, arguments);
4545
+ this.configure_collection(true);
4546
+ this.collection.bind("before:fetch", function() {
4547
+ if (_this.loadMask === true) return _this.trigger("enable:loadmask");
4548
+ });
4549
+ this.collection.bind("reset", function(collection) {
4550
+ _this.refresh();
4551
+ if (_this.loadMask === true) _this.trigger("disable:loadmask");
4552
+ return _this.trigger("after:collection:load", collection);
4553
+ });
4554
+ return this.collection.bind("change", function(model) {
4555
+ var cells, rowEl;
4556
+ if (_this.rendered !== true) return;
4557
+ try {
4558
+ rowEl = _this.getRowEl(model.id || model.get('id') || model.cid);
4559
+ cells = _this.render_row(model, _this.collection.indexOf(model), {
4560
+ cellsOnly: true
4561
+ });
4562
+ return $(rowEl).html(cells.join(" "));
4563
+ } catch (error) {
4564
+ return console.log("Error in change handler for GridView.collection", error, _this, model);
4565
+ }
4566
+ });
4567
+ },
4568
+ beforeRender: function() {
4569
+ var _ref;
4570
+ if ((_ref = Luca.components.Panel.prototype.beforeRender) != null) {
4571
+ _ref.apply(this, arguments);
4572
+ }
4573
+ this.trigger("before:grid:render", this);
4574
+ this.table = this.$('table.luca-ui-g-view');
4575
+ this.header = this.$("thead");
4576
+ this.body = this.$("tbody");
4577
+ this.footer = this.$("tfoot");
4578
+ this.wrapper = this.$("." + this.wrapperClass);
4579
+ this.applyCssClasses();
4580
+ if (this.scrollable) this.setDimensions();
4581
+ this.renderHeader();
4582
+ this.emptyMessage();
4583
+ return $(this.container).append(this.$el);
4584
+ },
4585
+ afterRender: function() {
4586
+ var _ref;
4587
+ if ((_ref = Luca.components.Panel.prototype.afterRender) != null) {
4588
+ _ref.apply(this, arguments);
4589
+ }
4590
+ this.rendered = true;
4591
+ this.refresh();
4592
+ return this.trigger("after:grid:render", this);
4593
+ },
4594
+ applyCssClasses: function() {
4595
+ var _ref,
4596
+ _this = this;
4597
+ if (this.scrollable) this.$el.addClass('scrollable-g-view');
4598
+ _(this.additionalWrapperClasses).each(function(containerClass) {
4599
+ var _ref;
4600
+ return (_ref = _this.wrapper) != null ? _ref.addClass(containerClass) : void 0;
4601
+ });
4602
+ if (Luca.enableBootstrap) this.table.addClass('table');
4603
+ return _((_ref = this.tableStyle) != null ? _ref.split(" ") : void 0).each(function(style) {
4604
+ return _this.table.addClass("table-" + style);
4605
+ });
4606
+ },
4607
+ setDimensions: function(offset) {
4608
+ var _this = this;
4609
+ this.height || (this.height = this.defaultHeight);
4610
+ this.$('.luca-ui-g-view-body').height(this.height);
4611
+ this.$('tbody.scrollable').height(this.height - 23);
4612
+ this.container_width = (function() {
4613
+ return $(_this.container).width();
4614
+ })();
4615
+ this.width || (this.width = this.container_width > 0 ? this.container_width : this.defaultWidth);
4616
+ this.width = _([this.width, this.maxWidth || this.width]).max();
4617
+ this.$('.luca-ui-g-view-body').width(this.width);
4618
+ this.$('.luca-ui-g-view-body table').width(this.width);
4619
+ return this.setDefaultColumnWidths();
4620
+ },
4621
+ resize: function(newWidth) {
4622
+ var difference, distribution,
4623
+ _this = this;
4624
+ difference = newWidth - this.width;
4625
+ this.width = newWidth;
4626
+ this.$('.luca-ui-g-view-body').width(this.width);
4627
+ this.$('.luca-ui-g-view-body table').width(this.width);
4628
+ if (this.columns.length > 0) {
4629
+ distribution = difference / this.columns.length;
4630
+ return _(this.columns).each(function(col, index) {
4631
+ var column;
4632
+ column = $(".column-" + index, _this.el);
4633
+ return column.width(col.width = col.width + distribution);
4634
+ });
4635
+ }
4636
+ },
4637
+ padLastColumn: function() {
4638
+ var configured_column_widths, unused_width;
4639
+ configured_column_widths = _(this.columns).inject(function(sum, column) {
4640
+ return sum = column.width + sum;
4641
+ }, 0);
4642
+ unused_width = this.width - configured_column_widths;
4643
+ if (unused_width > 0) return this.lastColumn().width += unused_width;
4644
+ },
4645
+ setDefaultColumnWidths: function() {
4646
+ var default_column_width;
4647
+ default_column_width = this.columns.length > 0 ? this.width / this.columns.length : 200;
4648
+ _(this.columns).each(function(column) {
4649
+ return parseInt(column.width || (column.width = default_column_width));
4650
+ });
4651
+ return this.padLastColumn();
4652
+ },
4653
+ lastColumn: function() {
4654
+ return this.columns[this.columns.length - 1];
4655
+ },
4656
+ emptyMessage: function(text) {
4657
+ if (text == null) text = "";
4658
+ text || (text = this.emptyText);
4659
+ this.body.html('');
4660
+ return this.body.append(Luca.templates["components/grid_view_empty_text"]({
4661
+ colspan: this.columns.length,
4662
+ text: text
4663
+ }));
4664
+ },
4665
+ refresh: function() {
4666
+ var _this = this;
4667
+ this.body.html('');
4668
+ this.collection.each(function(model, index) {
4669
+ return _this.render_row.apply(_this, [model, index]);
4670
+ });
4671
+ if (this.collection.models.length === 0) return this.emptyMessage();
4672
+ },
4673
+ ifLoaded: function(fn, scope) {
4674
+ scope || (scope = this);
4675
+ fn || (fn = function() {
4676
+ return true;
4677
+ });
4678
+ return this.collection.ifLoaded(fn, scope);
4679
+ },
4680
+ applyFilter: function(values, options) {
4681
+ if (options == null) {
4682
+ options = {
4683
+ auto: true,
4684
+ refresh: true
4685
+ };
4686
+ }
4687
+ return this.collection.applyFilter(values, options);
4688
+ },
4689
+ renderHeader: function() {
4690
+ var headers,
4691
+ _this = this;
4692
+ this.trigger("before:render:header");
4693
+ headers = _(this.columns).map(function(column, column_index) {
4694
+ var style;
4695
+ style = column.width ? "width:" + column.width + "px;" : "";
4696
+ return "<th style='" + style + "' class='column-" + column_index + "'>" + column.header + "</th>";
4697
+ });
4698
+ return this.header.append("<tr>" + headers + "</tr>");
4699
+ },
4700
+ getRowEl: function(id) {
4701
+ return this.$("[data-record-id=" + id + "]", 'table');
4702
+ },
4703
+ render_row: function(row, row_index, options) {
4704
+ var altClass, cells, content, model_id, rowClass, _ref,
4705
+ _this = this;
4706
+ if (options == null) options = {};
4707
+ rowClass = this.rowClass;
4708
+ model_id = (row != null ? row.get : void 0) && (row != null ? row.attributes : void 0) ? row.get('id') : '';
4709
+ this.trigger("before:render:row", row, row_index);
4710
+ cells = _(this.columns).map(function(column, col_index) {
4711
+ var display, style, value;
4712
+ value = _this.cell_renderer(row, column, col_index);
4713
+ style = column.width ? "width:" + column.width + "px;" : "";
4714
+ display = _.isUndefined(value) ? "" : value;
4715
+ return "<td style='" + style + "' class='column-" + col_index + "'>" + display + "</td>";
4716
+ });
4717
+ if (options.cellsOnly) return cells;
4718
+ altClass = '';
4719
+ if (this.alternateRowClasses) {
4720
+ altClass = row_index % 2 === 0 ? "even" : "odd";
4721
+ }
4722
+ content = "<tr data-record-id='" + model_id + "' data-row-index='" + row_index + "' class='" + rowClass + " " + altClass + "' id='row-" + row_index + "'>" + cells + "</tr>";
4723
+ if (options.contentOnly === true) return content;
4724
+ return (_ref = this.body) != null ? _ref.append(content) : void 0;
4725
+ },
4726
+ cell_renderer: function(row, column, columnIndex) {
4727
+ var source;
4728
+ if (_.isFunction(column.renderer)) {
4729
+ return column.renderer.apply(this, [row, column, columnIndex]);
4730
+ } else if (column.data.match(/\w+\.\w+/)) {
4731
+ source = row.attributes || row;
4732
+ return Luca.util.nestedValue(column.data, source);
4733
+ } else {
4734
+ return (typeof row.get === "function" ? row.get(column.data) : void 0) || row[column.data];
4735
+ }
4736
+ },
4737
+ double_click_handler: function(e) {
4738
+ var me, my, record, rowIndex;
4739
+ me = my = $(e.currentTarget);
4740
+ rowIndex = my.data('row-index');
4741
+ record = this.collection.at(rowIndex);
4742
+ return this.trigger("row:double:click", this, record, rowIndex);
4743
+ },
4744
+ click_handler: function(e) {
4745
+ var me, my, record, rowIndex;
4746
+ me = my = $(e.currentTarget);
4747
+ rowIndex = my.data('row-index');
4748
+ record = this.collection.at(rowIndex);
4749
+ this.trigger("row:click", this, record, rowIndex);
4750
+ $("." + this.rowClass, this.body).removeClass('selected-row');
4751
+ return me.addClass('selected-row');
4752
+ }
4753
+ });
4754
+
4755
+ }).call(this);
4756
+ (function() {
4757
+
4758
+ _.def("Luca.components.LoadMask")["extends"]("Luca.View")["with"]({
4759
+ className: "luca-ui-load-mask",
4760
+ bodyTemplate: "components/load_mask"
4761
+ });
4762
+
4763
+ }).call(this);
4764
+ (function() {
4765
+
4766
+ _.def("Luca.components.NavBar")["extends"]("Luca.View")["with"]({
4767
+ fixed: true,
4768
+ position: 'top',
4769
+ className: 'navbar',
4770
+ brand: "Luca.js",
4771
+ bodyTemplate: 'nav_bar',
4772
+ bodyClassName: 'luca-ui-navbar-body',
4773
+ beforeRender: function() {
4774
+ if (this.fixed) this.$el.addClass("navbar-fixed-" + this.position);
4775
+ if (this.brand != null) {
4776
+ this.content().append("<a class='brand' href='#'>" + this.brand + "</a>");
4777
+ }
4778
+ if (this.template) {
4779
+ return this.content().append(Luca.template(this.template, this));
4780
+ }
4781
+ },
4782
+ render: function() {
4783
+ return this;
4784
+ },
4785
+ content: function() {
4786
+ return this.$('.container').eq(0);
4787
+ }
4788
+ });
4789
+
4790
+ }).call(this);
4791
+ (function() {
4792
+
4793
+ _.def("Luca.PageController")["extends"]("Luca.components.Controller")["with"]({
4794
+ version: 2
4795
+ });
4796
+
4797
+ }).call(this);
4798
+ (function() {
4799
+ var paginationControl;
4800
+
4801
+ paginationControl = Luca.define("Luca.components.PaginationControl");
4802
+
4803
+ paginationControl["extends"]("Luca.View");
4804
+
4805
+ paginationControl.defaultsTo({
4806
+ template: "components/pagination",
4807
+ stateful: true,
4808
+ autoBindEventHandlers: true,
4809
+ events: {
4810
+ "click a[data-page-number]": "selectPage",
4811
+ "click a.next": "nextPage",
4812
+ "click a.prev": "previousPage"
4813
+ },
4814
+ afterInitialize: function() {
4815
+ return this.state.on("change", this.refresh, this);
4816
+ },
4817
+ limit: function() {
4818
+ var _ref;
4819
+ return parseInt(this.state.get('limit') || ((_ref = this.collection) != null ? _ref.length : void 0));
4820
+ },
4821
+ page: function() {
4822
+ return parseInt(this.state.get('page') || 1);
4823
+ },
4824
+ nextPage: function() {
4825
+ if (!this.nextEnabled()) return;
4826
+ return this.state.set('page', this.page() + 1);
4827
+ },
4828
+ previousPage: function() {
4829
+ if (!this.previousEnabled()) return;
4830
+ return this.state.set('page', this.page() - 1);
4831
+ },
4832
+ selectPage: function(e) {
4833
+ var me, my;
4834
+ me = my = this.$(e.target);
4835
+ if (!me.is('a.page')) me = my = my.closest('a.page');
4836
+ my.siblings().removeClass('is-selected');
4837
+ me.addClass('is-selected');
4838
+ return this.setPage(my.data('page-number'));
4839
+ },
4840
+ setPage: function(page, options) {
4841
+ if (page == null) page = 1;
4842
+ if (options == null) options = {};
4843
+ return this.state.set('page', page, options);
4844
+ },
4845
+ setLimit: function(limit, options) {
4846
+ if (limit == null) limit = 1;
4847
+ if (options == null) options = {};
4848
+ return this.state.set('limit', limit, options);
4849
+ },
4850
+ pageButtonContainer: function() {
4851
+ return this.$('.group');
4852
+ },
4853
+ previousEnabled: function() {
4854
+ return this.page() > 1;
4855
+ },
4856
+ nextEnabled: function() {
4857
+ return this.page() < this.totalPages();
4858
+ },
4859
+ previousButton: function() {
4860
+ return this.$('a.page.prev');
4861
+ },
4862
+ nextButton: function() {
4863
+ return this.$('a.page.next');
4864
+ },
4865
+ pageButtons: function() {
4866
+ return this.$('a[data-page-number]', this.pageButtonContainer());
4867
+ },
4868
+ refresh: function() {
4869
+ var button, page, _ref;
4870
+ this.pageButtonContainer().empty();
4871
+ for (page = 1, _ref = this.totalPages(); 1 <= _ref ? page <= _ref : page >= _ref; 1 <= _ref ? page++ : page--) {
4872
+ button = this.make("a", {
4873
+ "data-page-number": page,
4874
+ "class": "page"
4875
+ }, page);
4876
+ this.pageButtonContainer().append(button);
4877
+ }
4878
+ this.toggleNavigationButtons();
4879
+ return this.selectActivePageButton();
4880
+ },
4881
+ toggleNavigationButtons: function() {
4882
+ this.$('a.next, a.prev').addClass('disabled');
4883
+ if (this.nextEnabled()) this.nextButton().removeClass('disabled');
4884
+ if (this.previousEnabled()) {
4885
+ return this.previousButton().removeClass('disabled');
4886
+ }
4887
+ },
4888
+ selectActivePageButton: function() {
4889
+ return this.activePageButton().addClass('is-selected');
4890
+ },
4891
+ activePageButton: function() {
4892
+ return this.pageButtons().filter("[data-page-number='" + (this.page()) + "']");
4893
+ },
4894
+ totalPages: function() {
4895
+ return parseInt(Math.ceil(this.totalItems() / this.itemsPerPage()));
4896
+ },
4897
+ totalItems: function() {
4898
+ var _ref;
4899
+ return parseInt(((_ref = this.collection) != null ? _ref.length : void 0) || 0);
4900
+ },
4901
+ itemsPerPage: function(value, options) {
4902
+ if (options == null) options = {};
4903
+ if (value != null) this.set("limit", value, options);
4904
+ return parseInt(this.get("limit"));
4905
+ }
4906
+ });
4907
+
4908
+ }).call(this);
4909
+ (function() {
4910
+
4911
+ _.def('Luca.components.RecordManager')["extends"]('Luca.containers.CardView')["with"]({
4912
+ events: {
4913
+ "click .record-manager-grid .edit-link": "edit_handler",
4914
+ "click .record-manager-filter .filter-button": "filter_handler",
4915
+ "click .record-manager-filter .reset-button": "reset_filter_handler",
4916
+ "click .add-button": "add_handler",
4917
+ "click .refresh-button": "filter_handler",
4918
+ "click .back-to-search-button": "back_to_search_handler"
4919
+ },
4920
+ record_manager: true,
4921
+ initialize: function(options) {
4922
+ var _this = this;
4923
+ this.options = options != null ? options : {};
4924
+ Luca.containers.CardView.prototype.initialize.apply(this, arguments);
4925
+ if (!this.name) throw "Record Managers must specify a name";
4926
+ _.bindAll(this, "add_handler", "edit_handler", "filter_handler", "reset_filter_handler");
4927
+ if (this.filterConfig) _.extend(this.components[0][0], this.filterConfig);
4928
+ if (this.gridConfig) _.extend(this.components[0][1], this.gridConfig);
4929
+ if (this.editorConfig) _.extend(this.components[1][0], this.editorConfig);
4930
+ return this.bind("after:card:switch", function() {
4931
+ if (_this.activeCard === 0) _this.trigger("activation:search", _this);
4932
+ if (_this.activeCard === 1) {
4933
+ return _this.trigger("activation:editor", _this);
4934
+ }
4935
+ });
4936
+ },
4937
+ components: [
4938
+ {
4939
+ ctype: 'split_view',
4940
+ relayFirstActivation: true,
4941
+ components: [
4942
+ {
4943
+ ctype: 'form_view'
4944
+ }, {
4945
+ ctype: 'grid_view'
4946
+ }
4947
+ ]
4948
+ }, {
4949
+ ctype: 'form_view'
4950
+ }
4951
+ ],
4952
+ getSearch: function(activate, reset) {
4953
+ if (activate == null) activate = false;
4954
+ if (reset == null) reset = true;
4955
+ if (activate === true) this.activate(0);
4956
+ if (reset === true) this.getEditor().clear();
4957
+ return _.first(this.components);
4958
+ },
4959
+ getFilter: function() {
4960
+ return _.first(this.getSearch().components);
4961
+ },
4962
+ getGrid: function() {
4963
+ return _.last(this.getSearch().components);
4964
+ },
4965
+ getCollection: function() {
4966
+ return this.getGrid().collection;
4967
+ },
4968
+ getEditor: function(activate, reset) {
4969
+ var _this = this;
4970
+ if (activate == null) activate = false;
4971
+ if (reset == null) reset = false;
4972
+ if (activate === true) {
4973
+ this.activate(1, function(activator, previous, current) {
4974
+ return current.reset();
4975
+ });
4976
+ }
4977
+ return _.last(this.components);
4978
+ },
4979
+ beforeRender: function() {
4980
+ var _ref;
4981
+ this.$el.addClass("" + this.resource + "-manager");
4982
+ if ((_ref = Luca.containers.CardView.prototype.beforeRender) != null) {
4983
+ _ref.apply(this, arguments);
4984
+ }
4985
+ this.$el.addClass("" + this.resource + " record-manager");
4986
+ this.$el.data('resource', this.resource);
4987
+ $(this.getGrid().el).addClass("" + this.resource + " record-manager-grid");
4988
+ $(this.getFilter().el).addClass("" + this.resource + " record-manager-filter");
4989
+ return $(this.getEditor().el).addClass("" + this.resource + " record-manager-editor");
4990
+ },
4991
+ afterRender: function() {
4992
+ var collection, editor, filter, grid, manager, _ref,
4993
+ _this = this;
4994
+ if ((_ref = Luca.containers.CardView.prototype.afterRender) != null) {
4995
+ _ref.apply(this, arguments);
4996
+ }
4997
+ manager = this;
4998
+ grid = this.getGrid();
4999
+ filter = this.getFilter();
5000
+ editor = this.getEditor();
5001
+ collection = this.getCollection();
5002
+ grid.bind("row:double:click", function(grid, model, index) {
5003
+ manager.getEditor(true);
5004
+ return editor.loadModel(model);
5005
+ });
5006
+ editor.bind("before:submit", function() {
5007
+ $('.form-view-flash-container', _this.el).html('');
5008
+ return $('.form-view-body', _this.el).spin("large");
5009
+ });
5010
+ editor.bind("after:submit", function() {
5011
+ return $('.form-view-body', _this.el).spin(false);
5012
+ });
5013
+ editor.bind("after:submit:fatal_error", function() {
5014
+ $('.form-view-flash-container', _this.el).append("<li class='error'>There was an internal server error saving this record. Please contact developers@benchprep.com to report this error.</li>");
5015
+ return $('.form-view-body', _this.el).spin(false);
5016
+ });
5017
+ editor.bind("after:submit:error", function(form, model, response) {
5018
+ return _(response.errors).each(function(error) {
5019
+ return $('.form-view-flash-container', _this.el).append("<li class='error'>" + error + "</li>");
5020
+ });
5021
+ });
5022
+ editor.bind("after:submit:success", function(form, model, response) {
5023
+ $('.form-view-flash-container', _this.el).append("<li class='success'>Successfully Saved Record</li>");
5024
+ model.set(response.result);
5025
+ form.loadModel(model);
5026
+ grid.refresh();
5027
+ return _.delay(function() {
5028
+ $('.form-view-flash-container li.success', _this.el).fadeOut(1000);
5029
+ return $('.form-view-flash-container', _this.el).html('');
5030
+ }, 4000);
5031
+ });
5032
+ return filter.eachComponent(function(component) {
5033
+ try {
5034
+ return component.bind("on:change", _this.filter_handler);
5035
+ } catch (e) {
5036
+ return;
5037
+ }
5038
+ });
5039
+ },
5040
+ firstActivation: function() {
5041
+ this.getGrid().trigger("first:activation", this, this.getGrid());
5042
+ return this.getFilter().trigger("first:activation", this, this.getGrid());
5043
+ },
5044
+ reload: function() {
5045
+ var editor, filter, grid, manager;
5046
+ manager = this;
5047
+ grid = this.getGrid();
5048
+ filter = this.getFilter();
5049
+ editor = this.getEditor();
5050
+ filter.clear();
5051
+ return grid.applyFilter();
5052
+ },
5053
+ manageRecord: function(record_id) {
5054
+ var model,
5055
+ _this = this;
5056
+ model = this.getCollection().get(record_id);
5057
+ if (model) return this.loadModel(model);
5058
+ console.log("Could Not Find Model, building and fetching");
5059
+ model = this.buildModel();
5060
+ model.set({
5061
+ id: record_id
5062
+ }, {
5063
+ silent: true
5064
+ });
5065
+ return model.fetch({
5066
+ success: function(model, response) {
5067
+ return _this.loadModel(model);
5068
+ }
5069
+ });
5070
+ },
5071
+ loadModel: function(current_model) {
5072
+ this.current_model = current_model;
5073
+ this.getEditor(true).loadModel(this.current_model);
5074
+ return this.trigger("model:loaded", this.current_model);
5075
+ },
5076
+ currentModel: function() {
5077
+ return this.getEditor(false).currentModel();
5078
+ },
5079
+ buildModel: function() {
5080
+ var collection, editor, model;
5081
+ editor = this.getEditor(false);
5082
+ collection = this.getCollection();
5083
+ collection.add([{}], {
5084
+ silent: true,
5085
+ at: 0
5086
+ });
5087
+ return model = collection.at(0);
5088
+ },
5089
+ createModel: function() {
5090
+ return this.loadModel(this.buildModel());
5091
+ },
5092
+ reset_filter_handler: function(e) {
5093
+ this.getFilter().clear();
5094
+ return this.getGrid().applyFilter(this.getFilter().getValues());
5095
+ },
5096
+ filter_handler: function(e) {
5097
+ return this.getGrid().applyFilter(this.getFilter().getValues());
5098
+ },
5099
+ edit_handler: function(e) {
5100
+ var me, model, my, record_id;
5101
+ me = my = $(e.currentTarget);
5102
+ record_id = my.parents('tr').data('record-id');
5103
+ if (record_id) model = this.getGrid().collection.get(record_id);
5104
+ return model || (model = this.getGrid().collection.at(row_index));
5105
+ },
5106
+ add_handler: function(e) {
5107
+ var me, my, resource;
5108
+ me = my = $(e.currentTarget);
5109
+ return resource = my.parents('.record-manager').eq(0).data('resource');
5110
+ },
5111
+ destroy_handler: function(e) {},
5112
+ back_to_search_handler: function() {}
5113
+ });
5114
+
5115
+ }).call(this);
5116
+ (function() {
5117
+
5118
+ _.def("Luca.Router")["extends"]("Backbone.Router")["with"]({
5119
+ routes: {
5120
+ "": "default"
5121
+ },
5122
+ initialize: function(options) {
5123
+ var _this = this;
5124
+ this.options = options;
5125
+ _.extend(this, this.options);
5126
+ this.routeHandlers = _(this.routes).values();
5127
+ return _(this.routeHandlers).each(function(route_id) {
5128
+ return _this.bind("route:" + route_id, function() {
5129
+ return _this.trigger.apply(_this, ["change:navigation", route_id].concat(_(arguments).flatten()));
5130
+ });
5131
+ });
5132
+ },
5133
+ navigate: function(route, triggerRoute) {
5134
+ if (triggerRoute == null) triggerRoute = false;
5135
+ Backbone.Router.prototype.navigate.apply(this, arguments);
5136
+ return this.buildPathFrom(Backbone.history.getFragment());
5137
+ },
5138
+ buildPathFrom: function(matchedRoute) {
5139
+ var _this = this;
5140
+ return _(this.routes).each(function(route_id, route) {
5141
+ var args, regex;
5142
+ regex = _this._routeToRegExp(route);
5143
+ if (regex.test(matchedRoute)) {
5144
+ args = _this._extractParameters(regex, matchedRoute);
5145
+ return _this.trigger.apply(_this, ["change:navigation", route_id].concat(args));
5146
+ }
5147
+ });
5148
+ }
5149
+ });
5150
+
5151
+ }).call(this);
5152
+ (function() {
5153
+ var make;
5154
+
5155
+ _.def("Luca.components.TableView")["extends"]("Luca.components.CollectionView")["with"]({
5156
+ additionalClassNames: "table",
5157
+ tagName: "table",
5158
+ bodyTemplate: "table_view",
5159
+ bodyTagName: "tbody",
5160
+ bodyClassName: "table-body",
5161
+ itemTagName: "tr",
5162
+ stateful: true,
5163
+ observeChanges: true,
5164
+ columns: [],
5165
+ emptyText: "There are no results to display",
5166
+ itemRenderer: function(item, model) {
5167
+ return Luca.components.TableView.rowRenderer.call(this, item, model);
5168
+ },
5169
+ initialize: function(options) {
5170
+ var column,
5171
+ _this = this;
5172
+ this.options = options != null ? options : {};
5173
+ Luca.components.CollectionView.prototype.initialize.apply(this, arguments);
5174
+ this.columns = (function() {
5175
+ var _i, _len, _ref, _results;
5176
+ _ref = this.columns;
5177
+ _results = [];
5178
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
5179
+ column = _ref[_i];
5180
+ if (_.isString(column)) {
5181
+ column = {
5182
+ reader: column
5183
+ };
5184
+ }
5185
+ if (!(column.header != null)) {
5186
+ column.header = _.str.titleize(_.str.humanize(column.reader));
5187
+ }
5188
+ _results.push(column);
5189
+ }
5190
+ return _results;
5191
+ }).call(this);
5192
+ return this.defer(function() {
5193
+ return Luca.components.TableView.renderHeader.call(_this, _this.columns, _this.$('thead'));
5194
+ }).until("after:render");
5195
+ }
5196
+ });
5197
+
5198
+ make = Backbone.View.prototype.make;
5199
+
5200
+ Luca.components.TableView.renderHeader = function(columns, targetElement) {
5201
+ var column, content, index, _i, _len, _results;
5202
+ index = 0;
5203
+ content = (function() {
5204
+ var _i, _len, _results;
5205
+ _results = [];
5206
+ for (_i = 0, _len = columns.length; _i < _len; _i++) {
5207
+ column = columns[_i];
5208
+ _results.push("<th data-col-index='" + (index++) + "'>" + column.header + "</th>");
5209
+ }
5210
+ return _results;
5211
+ })();
5212
+ console.log("one");
5213
+ this.$(targetElement).append(make("tr", {}, content));
5214
+ console.log("two");
5215
+ index = 0;
5216
+ console.log("three");
5217
+ _results = [];
5218
+ for (_i = 0, _len = columns.length; _i < _len; _i++) {
5219
+ column = columns[_i];
5220
+ if (column.width != null) {
5221
+ _results.push(this.$("th[data-col-index='" + (index++) + "']", targetElement).css('width', column.width));
5222
+ }
5223
+ }
5224
+ return _results;
5225
+ };
5226
+
5227
+ Luca.components.TableView.rowRenderer = function(item, model, index) {
5228
+ var colIndex, columnConfig, _i, _len, _ref, _results;
5229
+ colIndex = 0;
5230
+ _ref = this.columns;
5231
+ _results = [];
5232
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
5233
+ columnConfig = _ref[_i];
5234
+ _results.push(Luca.components.TableView.renderColumn.call(this, columnConfig, item, model, colIndex++));
5235
+ }
5236
+ return _results;
5237
+ };
5238
+
5239
+ Luca.components.TableView.renderColumn = function(column, item, model, index) {
5240
+ var cellValue;
5241
+ cellValue = model.read(column.reader);
5242
+ if (_.isFunction(column.renderer)) {
5243
+ cellValue = column.renderer.call(this, cellValue, model, column);
5244
+ }
5245
+ return make("td", {
5246
+ "data-col-index": index
5247
+ }, cellValue);
5248
+ };
5249
+
5250
+ }).call(this);
5251
+ (function() {
5252
+
5253
+ _.def("Luca.components.ToolbarDialog")["extends"]("Luca.View")["with"]({
5254
+ className: "luca-ui-toolbar-dialog span well",
5255
+ styles: {
5256
+ "position": "absolute",
5257
+ "z-Index": "3000",
5258
+ "float": "left"
5259
+ },
5260
+ initialize: function(options) {
5261
+ this.options = options != null ? options : {};
5262
+ return this._super("initialize", this, arguments);
5263
+ },
5264
+ createWrapper: function() {
5265
+ return this.make("div", {
5266
+ "class": "component-picker span4 well",
5267
+ style: "position: absolute; z-index:12000"
5268
+ });
5269
+ },
5270
+ show: function() {
5271
+ return this.$el.parent().show();
5272
+ },
5273
+ hide: function() {
5274
+ return this.$el.parent().hide();
5275
+ },
5276
+ toggle: function() {
5277
+ return this.$el.parent().toggle();
5278
+ }
5279
+ });
5280
+
5281
+ }).call(this);
5282
+ (function() {
5283
+
5284
+
5285
+
5286
+ }).call(this);
5287
+ (function() {
5288
+
5289
+
5290
+
5291
+ }).call(this);
5292
+
5293
+
5294
+
2620
5295
  (function() {
2621
5296
 
2622
5297