lanes 0.1.9.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (304) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Rakefile +1 -1
  4. data/client/lanes/Boot.cjsx +3 -3
  5. data/client/lanes/Config.coffee +38 -3
  6. data/client/lanes/access/Extension.coffee +1 -1
  7. data/client/lanes/access/LoginDialog.cjsx +57 -47
  8. data/client/lanes/access/Roles.coffee +2 -2
  9. data/client/lanes/access/User.coffee +4 -3
  10. data/client/lanes/access/screens/user-management/UserManagement.cjsx +12 -11
  11. data/client/lanes/components/calendar/Calendar.cjsx +16 -0
  12. data/client/lanes/components/calendar/index.js +3 -0
  13. data/client/lanes/components/calendar/styles.scss +3 -0
  14. data/client/lanes/components/grid/Body.cjsx +86 -0
  15. data/client/lanes/components/grid/CellStyles.coffee +20 -0
  16. data/client/lanes/components/grid/EditingMixin.cjsx +84 -24
  17. data/client/lanes/components/grid/Editor.cjsx +45 -0
  18. data/client/lanes/components/grid/Grid.cjsx +62 -104
  19. data/client/lanes/components/grid/Header.cjsx +35 -0
  20. data/client/lanes/components/grid/PopOverMixin.cjsx +19 -9
  21. data/client/lanes/components/grid/PopoverEditor.cjsx +7 -1
  22. data/client/lanes/components/grid/RowEditor.cjsx +1 -1
  23. data/client/lanes/components/grid/Selections.cjsx +39 -0
  24. data/client/lanes/components/grid/Toolbar.cjsx +24 -5
  25. data/client/lanes/components/grid/editors.scss +22 -50
  26. data/client/lanes/components/grid/index.js +0 -1
  27. data/client/lanes/components/grid/row-editor.scss +68 -0
  28. data/client/lanes/components/grid/styles.scss +79 -3
  29. data/client/lanes/components/modal/Modal.cjsx +64 -24
  30. data/client/lanes/components/modal/styles.scss +12 -0
  31. data/client/lanes/components/record-finder/Clause.cjsx +11 -4
  32. data/client/lanes/components/record-finder/Dialog.cjsx +23 -24
  33. data/client/lanes/components/record-finder/RecordFinder.cjsx +45 -14
  34. data/client/lanes/components/record-finder/styles.scss +9 -6
  35. data/client/lanes/components/select-field/SelectField.cjsx +108 -53
  36. data/client/lanes/components/select-field/styles.scss +19 -0
  37. data/client/lanes/components/shared/ControlLabel.cjsx +45 -0
  38. data/client/lanes/components/shared/DateTime.cjsx +48 -0
  39. data/client/lanes/components/shared/DisplayValue.cjsx +16 -0
  40. data/client/lanes/components/shared/FieldMixin.cjsx +54 -23
  41. data/client/lanes/components/shared/FieldSet.cjsx +12 -35
  42. data/client/lanes/components/shared/FieldWrapper.cjsx +13 -0
  43. data/client/lanes/components/shared/FormGroup.cjsx +37 -0
  44. data/client/lanes/components/shared/Icon.cjsx +20 -0
  45. data/client/lanes/components/shared/ImageSaver.cjsx +33 -0
  46. data/client/lanes/components/shared/Input.cjsx +19 -0
  47. data/client/lanes/components/shared/InputFieldMixin.cjsx +48 -0
  48. data/client/lanes/components/shared/JobProgress.cjsx +27 -0
  49. data/client/lanes/components/shared/NetworkActivityOverlay.cjsx +58 -0
  50. data/client/lanes/components/shared/NumberInput.cjsx +29 -0
  51. data/client/lanes/components/shared/ResizeSensor.cjsx +11 -0
  52. data/client/lanes/components/shared/ScreenWrapper.cjsx +13 -0
  53. data/client/lanes/components/shared/Throbber.cjsx +3 -0
  54. data/client/lanes/components/shared/ToggleField.cjsx +33 -0
  55. data/client/lanes/components/shared/Tooltip.cjsx +2 -2
  56. data/client/lanes/components/shared/fields.scss +75 -13
  57. data/client/lanes/components/shared/fieldset.scss +3 -5
  58. data/client/lanes/components/shared/image-saver.scss +38 -0
  59. data/client/lanes/components/shared/index.js +2 -0
  60. data/client/lanes/{styles/plugins → components/shared}/overlay.scss +17 -4
  61. data/client/lanes/components/shared/resize-sensor.scss +30 -0
  62. data/client/lanes/components/shared/styles.scss +13 -0
  63. data/client/lanes/components/shared/throbber.scss +53 -0
  64. data/client/lanes/components/toolbar/RemoteChangeSets.cjsx +21 -48
  65. data/client/lanes/components/toolbar/SaveButton.cjsx +24 -0
  66. data/client/lanes/components/toolbar/Toolbar.cjsx +24 -37
  67. data/client/lanes/components/toolbar/changes-notification.scss +10 -6
  68. data/client/lanes/components/toolbar/styles.scss +29 -9
  69. data/client/lanes/extension/Base.coffee +4 -5
  70. data/client/lanes/index.js +0 -1
  71. data/client/lanes/index.scss.erb +10 -1
  72. data/client/lanes/lib/HotReload.coffee +13 -15
  73. data/client/lanes/lib/MakeBaseClass.coffee +6 -1
  74. data/client/lanes/lib/development.coffee +2 -0
  75. data/client/lanes/lib/dom-polyfills.coffee +5 -0
  76. data/client/lanes/lib/dom.coffee +38 -9
  77. data/client/lanes/lib/format.coffee +11 -0
  78. data/client/lanes/lib/index.js.erb +2 -0
  79. data/client/lanes/lib/production.coffee +6 -0
  80. data/client/lanes/lib/utilFunctions.coffee +50 -15
  81. data/client/lanes/models/AssociationMap.coffee +122 -46
  82. data/client/lanes/models/AssociationProxy.coffee +147 -0
  83. data/client/lanes/models/Base.coffee +97 -85
  84. data/client/lanes/models/ChangeMonitor.coffee +7 -3
  85. data/client/lanes/models/ChangeSet.coffee +2 -2
  86. data/client/lanes/models/Collection.coffee +49 -6
  87. data/client/lanes/models/JobStatus.coffee +32 -0
  88. data/client/lanes/models/PubSub.coffee +7 -5
  89. data/client/lanes/models/Query.coffee +115 -34
  90. data/client/lanes/models/ServerCache.coffee +67 -52
  91. data/client/lanes/models/State.coffee +97 -0
  92. data/client/lanes/models/Sync.coffee +18 -13
  93. data/client/lanes/models/SystemSettings.coffee +0 -0
  94. data/client/lanes/models/index.js +1 -0
  95. data/client/lanes/models/mixins/FileSupport.coffee +60 -0
  96. data/client/lanes/models/mixins/HasCodeField.coffee +13 -6
  97. data/client/lanes/models/query/ArrayResult.coffee +188 -0
  98. data/client/lanes/models/query/CollectionResult.coffee +71 -0
  99. data/client/lanes/models/query/Result.coffee +9 -0
  100. data/client/lanes/react/Component.coffee +7 -3
  101. data/client/lanes/react/PubSub.coffee +7 -7
  102. data/client/lanes/react/Root.cjsx +1 -4
  103. data/client/lanes/react/Screen.coffee +1 -0
  104. data/client/lanes/react/TypeValidators.coffee +3 -3
  105. data/client/lanes/react/Viewport.coffee +41 -7
  106. data/client/lanes/react/index.js +0 -1
  107. data/client/lanes/react/mixins/Access.coffee +4 -1
  108. data/client/lanes/react/mixins/Data.coffee +40 -25
  109. data/client/lanes/react/mixins/FieldErrors.coffee +27 -0
  110. data/client/lanes/react/mixins/RelayEditingState.coffee +4 -0
  111. data/client/lanes/react/mixins/Screen.coffee +14 -0
  112. data/client/lanes/react/mixins/Viewport.coffee +9 -3
  113. data/client/lanes/screens/ChangeListener.coffee +3 -3
  114. data/client/lanes/screens/Commands.coffee +14 -7
  115. data/client/lanes/screens/CommonComponents.cjsx +20 -0
  116. data/client/lanes/screens/Definitions.coffee +64 -20
  117. data/client/lanes/screens/SystemSettings.cjsx +56 -0
  118. data/client/lanes/screens/UserPreferences.cjsx +38 -0
  119. data/client/lanes/screens/index.js +3 -0
  120. data/client/lanes/screens/styles.scss +2 -1
  121. data/client/lanes/styles/fonts.scss +1 -0
  122. data/client/lanes/styles/global.scss +2 -1
  123. data/client/lanes/styles/global/flexbox.scss +16 -0
  124. data/client/lanes/styles/global/styles.scss +1 -0
  125. data/client/lanes/styles/mixins/_dropdown.scss +21 -0
  126. data/client/lanes/styles/mixins/_flexbox.scss +394 -0
  127. data/client/lanes/styles/mixins/all.scss +2 -0
  128. data/client/lanes/styles/variables.scss +28 -0
  129. data/client/lanes/testing/BeforeEach.coffee +15 -14
  130. data/client/lanes/testing/Helpers.coffee +14 -5
  131. data/client/lanes/testing/TestObjects.coffee +10 -2
  132. data/client/lanes/testing/index.js +1 -0
  133. data/client/lanes/testing/jasmine-react.js +125 -0
  134. data/client/lanes/vendor/base.js +56049 -74987
  135. data/client/lanes/vendor/calendar.js +17301 -0
  136. data/client/lanes/vendor/calendar.scss +303 -0
  137. data/client/lanes/vendor/commons.js +14990 -15847
  138. data/client/lanes/vendor/development.js +4912 -1952
  139. data/client/lanes/vendor/grid.js +14246 -5551
  140. data/client/lanes/vendor/grid.scss +876 -335
  141. data/client/lanes/vendor/index.js +1 -0
  142. data/client/lanes/vendor/message-bus-ajax.js +44 -0
  143. data/client/lanes/vendor/message-bus.js +414 -0
  144. data/client/lanes/vendor/rw-widgets.eot +0 -0
  145. data/client/lanes/vendor/rw-widgets.svg +18 -0
  146. data/client/lanes/vendor/rw-widgets.ttf +0 -0
  147. data/client/lanes/vendor/rw-widgets.woff +0 -0
  148. data/client/lanes/vendor/toggle.js +345 -0
  149. data/client/lanes/vendor/toggle.scss +138 -0
  150. data/client/lanes/vendor/widgets.js +21245 -6839
  151. data/client/lanes/vendor/widgets.scss +83 -67
  152. data/client/lanes/workspace/Layout.cjsx +18 -8
  153. data/client/lanes/workspace/Modal.cjsx +47 -0
  154. data/client/lanes/workspace/Navbar.cjsx +16 -2
  155. data/client/lanes/workspace/ScreenView.cjsx +10 -3
  156. data/client/lanes/workspace/ScreensMenu.cjsx +23 -7
  157. data/client/lanes/workspace/Tabs.cjsx +55 -0
  158. data/client/lanes/workspace/UIState.coffee +7 -8
  159. data/client/lanes/workspace/index.js +2 -1
  160. data/client/lanes/workspace/mixin.coffee +11 -0
  161. data/client/lanes/workspace/mixins/UIState.coffee +8 -0
  162. data/client/lanes/workspace/mixins/index.js +3 -0
  163. data/client/lanes/workspace/styles.scss +2 -1
  164. data/client/lanes/workspace/styles/header.scss +23 -1
  165. data/client/lanes/workspace/styles/layout.scss +26 -24
  166. data/client/lanes/workspace/styles/screens.scss +0 -4
  167. data/client/lanes/workspace/styles/tabs.scss +3 -10
  168. data/config/routes.rb +10 -4
  169. data/config/screens.rb +25 -0
  170. data/db/migrate/01_create_system_settings.rb +10 -0
  171. data/docs/todo-example-part-1.md +18 -20
  172. data/lanes.gemspec +15 -6
  173. data/lib/lanes.rb +4 -2
  174. data/lib/lanes/access/config/routes.rb +5 -3
  175. data/lib/lanes/access/config/screens.rb +1 -0
  176. data/lib/lanes/access/db/migrate/20140615031600_create_lanes_users.rb +1 -1
  177. data/lib/lanes/access/user.rb +1 -1
  178. data/lib/lanes/api.rb +2 -1
  179. data/lib/lanes/api/controller.rb +32 -71
  180. data/lib/lanes/api/default_routes.rb +10 -8
  181. data/lib/lanes/api/formatted_reply.rb +53 -0
  182. data/lib/lanes/api/handlers/file.rb +26 -0
  183. data/lib/lanes/api/helper_methods.rb +29 -5
  184. data/lib/lanes/api/javascript_processor.rb +36 -17
  185. data/lib/lanes/api/pub_sub.rb +6 -9
  186. data/lib/lanes/api/request_wrapper.rb +1 -2
  187. data/lib/lanes/api/root.rb +11 -43
  188. data/lib/lanes/api/routing.rb +63 -0
  189. data/lib/lanes/api/sprockets_extension.rb +15 -7
  190. data/lib/lanes/api/updates.rb +1 -2
  191. data/lib/lanes/command.rb +0 -1
  192. data/lib/lanes/command/app.rb +6 -5
  193. data/lib/lanes/command/console.rb +1 -0
  194. data/lib/lanes/command/generate.rb +3 -0
  195. data/lib/lanes/command/generate_migration.rb +33 -0
  196. data/lib/lanes/command/generate_model.rb +4 -26
  197. data/lib/lanes/command/migration_support.rb +29 -0
  198. data/lib/lanes/command/update_model.rb +14 -5
  199. data/lib/lanes/concerns/all.rb +2 -0
  200. data/lib/lanes/concerns/api_path.rb +4 -2
  201. data/lib/lanes/concerns/association_extensions.rb +1 -1
  202. data/lib/lanes/concerns/attr_accessor_with_default.rb +3 -1
  203. data/lib/lanes/concerns/code_identifier.rb +1 -1
  204. data/lib/lanes/concerns/image_uploader.rb +42 -0
  205. data/lib/lanes/concerns/pub_sub.rb +0 -1
  206. data/lib/lanes/concerns/queries.rb +2 -2
  207. data/lib/lanes/concerns/set_attribute_data.rb +4 -13
  208. data/lib/lanes/concerns/sorting_expressions.rb +34 -0
  209. data/lib/lanes/configuration.rb +48 -9
  210. data/lib/lanes/extension.rb +16 -7
  211. data/lib/lanes/extension/definition.rb +8 -2
  212. data/lib/lanes/job.rb +78 -0
  213. data/lib/lanes/job/failure_logger.rb +33 -0
  214. data/lib/lanes/model.rb +4 -0
  215. data/lib/lanes/rake_tasks.rb +6 -0
  216. data/lib/lanes/redis.rb +13 -0
  217. data/lib/lanes/screen.rb +34 -18
  218. data/lib/lanes/system_settings.rb +66 -0
  219. data/lib/lanes/version.rb +1 -1
  220. data/lib/lanes/workspace/extension.rb +1 -1
  221. data/npm-build/base.js +10 -3
  222. data/npm-build/calendar.js +6 -0
  223. data/npm-build/development.js +4 -5
  224. data/npm-build/grid.js +3 -5
  225. data/npm-build/package.json +40 -29
  226. data/npm-build/react-toggle.js +5 -0
  227. data/npm-build/react-widgets.js +6 -0
  228. data/npm-build/update-dayz +14 -0
  229. data/npm-build/webpack.config.js +5 -2
  230. data/spec/command-reference-files/initial/Gemfile +1 -1
  231. data/spec/command-reference-files/initial/config/routes.rb +2 -0
  232. data/spec/command-reference-files/initial/lib/appy-app.rb +4 -0
  233. data/spec/command-reference-files/initial/lib/appy-app/extension.rb +2 -0
  234. data/spec/command-reference-files/initial/spec/server/{spec_helpers.rb → spec_helper.rb} +0 -0
  235. data/spec/command-reference-files/model/config/routes.rb +2 -0
  236. data/spec/command-reference-files/model/spec/server/test_test_spec.rb +1 -1
  237. data/spec/command-reference-files/screen/client/appy-app/screens/ready-set-go/ReadySetGo.cjsx +6 -4
  238. data/spec/command-reference-files/screen/client/appy-app/screens/ready-set-go/index.scss +4 -3
  239. data/spec/command-reference-files/screen/config/screens.rb +4 -2
  240. data/spec/command-reference-files/screen/spec/appy-app/screens/ready-set-go/ReadySetGoSpec.coffee +1 -1
  241. data/spec/fixtures/system_settings.yml +1 -0
  242. data/spec/lanes/components/grid/GridSpec.coffee +56 -31
  243. data/spec/lanes/components/grid/RowEditorSpec.coffee +96 -0
  244. data/spec/lanes/components/select-field/SelectFieldSpec.coffee +99 -0
  245. data/spec/lanes/components/shared/NetworkActivityOverlaySpec.coffee +34 -0
  246. data/spec/lanes/models/AssociationMapSpec.coffee +36 -2
  247. data/spec/lanes/models/AssociationProxySpec.coffee +77 -0
  248. data/spec/lanes/models/BaseSpec.coffee +37 -4
  249. data/spec/lanes/models/CollectionSpec.coffee +11 -17
  250. data/spec/lanes/models/PubSubSpec.coffee +1 -1
  251. data/spec/lanes/models/ServerCacheSpec.coffee +65 -0
  252. data/spec/server/api/coffeescript_processor_spec.rb +1 -1
  253. data/spec/server/concerns/pub_sub_spec.rb +9 -10
  254. data/spec/server/concerns/sorting_expressions_spec.rb +34 -0
  255. data/spec/server/configuration_spec.rb +3 -3
  256. data/spec/server/job_spec.rb +54 -0
  257. data/spec/server/spec_helper.rb +0 -5
  258. data/spec/server/system_settings_spec.rb +23 -0
  259. data/templates/client/screens/Screen.cjsx +6 -4
  260. data/templates/client/screens/styles.scss +4 -3
  261. data/templates/config/routes.rb +2 -0
  262. data/templates/config/screen.rb +4 -2
  263. data/templates/lib/namespace.rb +4 -0
  264. data/templates/lib/namespace/extension.rb +2 -0
  265. data/templates/spec/client/Screen.coffee +1 -1
  266. data/templates/spec/server/model_spec.rb +1 -1
  267. data/templates/spec/server/{spec_helpers.rb → spec_helper.rb} +0 -0
  268. data/views/lanes_root_view.erb +70 -0
  269. data/views/specs.erb +2 -2
  270. metadata +207 -68
  271. data/client/images/lanes/dataTables/Sorting icons.psd +0 -0
  272. data/client/images/lanes/dataTables/back_disabled.png +0 -0
  273. data/client/images/lanes/dataTables/back_enabled.png +0 -0
  274. data/client/images/lanes/dataTables/back_enabled_hover.png +0 -0
  275. data/client/images/lanes/dataTables/favicon.ico +0 -0
  276. data/client/images/lanes/dataTables/forward_disabled.png +0 -0
  277. data/client/images/lanes/dataTables/forward_enabled.png +0 -0
  278. data/client/images/lanes/dataTables/forward_enabled_hover.png +0 -0
  279. data/client/images/lanes/dataTables/loading-background.png +0 -0
  280. data/client/images/lanes/dataTables/sort_asc.png +0 -0
  281. data/client/images/lanes/dataTables/sort_asc_disabled.png +0 -0
  282. data/client/images/lanes/dataTables/sort_both.png +0 -0
  283. data/client/images/lanes/dataTables/sort_desc.png +0 -0
  284. data/client/images/lanes/dataTables/sort_desc_disabled.png +0 -0
  285. data/client/lanes/components/shared/Resize.cjsx +0 -152
  286. data/client/lanes/components/shared/TextArea.cjsx +0 -19
  287. data/client/lanes/components/shared/TextField.cjsx +0 -25
  288. data/client/lanes/models/Bootstrap.coffee +0 -5
  289. data/client/lanes/models/QueryResults.coffee +0 -93
  290. data/client/lanes/react/FormBindings.coffee +0 -103
  291. data/client/lanes/react/Router.cjsx +0 -18
  292. data/client/lanes/styles/dataTables.scss +0 -4
  293. data/client/lanes/styles/plugins/all.scss +0 -2
  294. data/client/lanes/styles/plugins/resize-sensor.scss +0 -24
  295. data/client/lanes/vendor/jquery-2.js +0 -9190
  296. data/client/lanes/vendor/jquery.tap.js +0 -401
  297. data/client/lanes/vendor/magicsuggest.js +0 -1565
  298. data/client/lanes/vendor/message-bus.coffee +0 -264
  299. data/client/lanes/workspace/ActiveScreenSwitcher.cjsx +0 -38
  300. data/client/lanes/workspace/styles/toolbar.scss +0 -4
  301. data/lib/lanes/api/eco.js +0 -516
  302. data/lib/lanes/api/sprockets_compressor.rb +0 -39
  303. data/spec/command-reference-files/model/lib/appy-app.rb +0 -11
  304. data/views/index.erb +0 -19
@@ -0,0 +1,147 @@
1
+ rememberEvents = (obj, ev, rest) ->
2
+ obj[ev] ||= []
3
+ obj[ev].push rest
4
+
5
+
6
+ relayEvents = (obj, model, meth) ->
7
+ for ev, args of obj or []
8
+ model[meth](ev, arg...) for arg in args
9
+
10
+ ProxyMethods = {
11
+
12
+ replaceProxy: (name, model) ->
13
+ @_association_cache[name] = model
14
+
15
+ replaceWithModel: (model, options, whenReadyMethod) ->
16
+ model = new @_proxied_model(model) unless Lanes.u.isModel(model)
17
+
18
+ @_proxied_parent?.replace(
19
+ @_proxied_options.parent, options.association_name, model
20
+ )
21
+ relayEvents(@_proxied_events, model, 'on')
22
+ relayEvents(@_proxied_once_events, model, 'once')
23
+
24
+ whenReadyMethod?()
25
+
26
+ if @_proxied_events?['proxyreplace']
27
+ for ev, args of @_proxied_events['proxyreplace'] or []
28
+ args[0].call(args[1], model)
29
+ delete @_proxied_events['proxyreplace']
30
+
31
+ model
32
+
33
+ _replaceAndCall: (options, fn) ->
34
+ model = new @_proxied_model()
35
+ @replaceWithModel(model, options, ->
36
+ fn.call(model, fn)
37
+ )
38
+
39
+
40
+ serialize: (options) ->
41
+ if @_association_cache
42
+ data = {}
43
+ for name, model of @_association_cache
44
+ data[name] = model.dataForSave(options)
45
+ data
46
+ else
47
+ return null
48
+ dataForSave: (options = {}) -> @serialize(options)
49
+ isPersistent: -> false
50
+ api_path: -> @_proxied_model::api_path()
51
+ getId: -> @_proxied_options.parent[@_proxied_config.association_pk]
52
+ isNew: -> _.isBlank(@getId())
53
+ invalidMessageFor: (name) ->
54
+ if @_proxied_model::_definition[name]?.required
55
+ "Cannot be empty"
56
+ else
57
+ ''
58
+
59
+ on: (ev, rest...) ->
60
+ rememberEvents( @_proxied_events ||= {}, ev, rest )
61
+
62
+ once: (ev, rest...) ->
63
+ rememberEvents( @_proxied_once_events ||= {}, ev, rest )
64
+
65
+ off: (ev, rest...) ->
66
+ delete @_proxied_events[ev]
67
+
68
+ }
69
+
70
+ Lanes.Models.AssocationProxy = {
71
+ NullGetter: ->
72
+ return null
73
+
74
+ fowardingFuncDefinition: (name, options) ->
75
+ -> args = arguments; @_replaceAndCall options, -> @[name](args...)
76
+
77
+ fieldDefinition: (name, definition, options) ->
78
+ enumerable: true
79
+ get: @NullGetter
80
+ set: (value) ->
81
+ @_replaceAndCall options, -> @[name] = value
82
+
83
+ derivedDefinition: (name, definition, options) ->
84
+ enumerable: true
85
+ get: @NullGetter
86
+ set: ->
87
+ throw new TypeError('"' + name + '" is a derived property, it can\'t be set directly.')
88
+
89
+
90
+ associationDefinition: (name, definition, options) ->
91
+ enumerable: true
92
+ set: ->
93
+ throw new TypeError('"' + name + '" is an association property, it can\'t be set directly.')
94
+
95
+ get: ->
96
+ @_association_cache ||= Object.create(null)
97
+ @_association_cache[name] ||= (
98
+ klass = @_proxied_model::associations.getClassFor(name)
99
+ Proxy = Lanes.Models.AssocationProxy.construct(klass,
100
+ association_name: name
101
+ )
102
+ new Proxy(@)
103
+ )
104
+
105
+
106
+ construct: (klass, config) ->
107
+ AssociationProxy = (parent, options) ->
108
+ @_proxied_parent = parent
109
+ @_proxied_options = options
110
+ @_proxied_config = config
111
+ undefined
112
+
113
+
114
+ _.extend(AssociationProxy.prototype, ProxyMethods)
115
+
116
+ AssociationProxy.Collection = klass.Collection
117
+
118
+ AssociationProxy::_proxied_model = klass
119
+
120
+ definedProps = {
121
+ isProxy: { value: true, enumerable: true, writable: false }
122
+ id: { get: -> @getId() }
123
+ }
124
+ if klass::associations?
125
+ definedProps.associations =
126
+ enumerable: true
127
+ get: -> klass::associations
128
+ for name, definition of klass::associations?.definitions
129
+ definedProps[name] = @associationDefinition(name, definition, config)
130
+
131
+ if klass::_definition?
132
+ for name, definition of klass::_definition when not definedProps[name]
133
+ definedProps[name] = @fieldDefinition(name, definition, config)
134
+
135
+ if klass::_derived?
136
+ for name, definition of klass::_derived when not definedProps[name]
137
+ definedProps[name] = @derivedDefinition(name, definition, config)
138
+
139
+ Object.defineProperties(AssociationProxy.prototype, definedProps)
140
+
141
+ for name, method of klass.prototype when _.isFunction(method) and not AssociationProxy::[name]
142
+ AssociationProxy::[name] = @fowardingFuncDefinition(name, config)
143
+
144
+ AssociationProxy
145
+
146
+
147
+ }
@@ -11,10 +11,15 @@ class BaseModel
11
11
  errors: 'object'
12
12
  changes: { type: 'collection', setOnce: true }
13
13
  lastServerMessage: { type: 'string' }
14
- parent: 'state'
15
- isDirty: { type: 'boolean', default: false }
14
+ isDirty: { type: 'boolean', default: false }
15
+ invalidAttributes: 'array'
16
+ updatingFromChangeset: { type: 'boolean', default: false }
16
17
 
17
18
  derived:
19
+ isSavable:
20
+ deps: ['invalidAttributes'], fn: ->
21
+ _.isEmpty @invalidAttributes #_calculateInvalidAttributes()
22
+
18
23
  errorMessage:
19
24
  deps:['errors'], fn: ->
20
25
  if !@errors then ''
@@ -22,47 +27,10 @@ class BaseModel
22
27
  else _.toSentence( _.map(@errors, (value, key) ->
23
28
  _.titleize(_.humanize(key)) + ' ' + value
24
29
  ))
25
- dataTypes:
26
- code:
27
- set: (newVal) ->
28
- if _.isString(newVal)
29
- val: newVal.toUpperCase(), type: 'code'
30
- else
31
- throw new TypeError('code must be a string')
32
- default: -> ''
33
- # Big decimal for attributes that need precision math
34
- bigdec:
35
- set: (newVal) ->
36
- val: new _.bigDecimal(newVal)
37
- type: 'bigdec'
38
- default: -> new _.bigDecimal(0)
39
-
40
- integer:
41
- set: (newVal) ->
42
- val: parseInt(newVal)
43
- type: 'integer'
44
- # Uses the "moment" lib to parse dates and coerce strings into the date type.
45
- date:
46
- get: (val) -> new Date(val)
47
- default: -> return new Date()
48
- set: (newVal) ->
49
- if _.isDate(newVal)
50
- newType = 'date'
51
- newVal = newVal.valueOf()
52
- else
53
- m = Lanes.Vendor.Moment(newVal)
54
- if m.isValid()
55
- newType = 'date'
56
- newVal = m.toDate()
57
- else
58
- newType = typeof newVal;
59
- return {
60
- val: newVal,
61
- type: newType
62
- }
63
-
64
30
  constructor: (attrs, options = {}) ->
65
31
  super
32
+ @on('change', @_calculateInvalidAttributes)
33
+ @_calculateInvalidAttributes()
66
34
  @changeMonitor = new Lanes.Models.ChangeMonitor(this)
67
35
  # The model was created with attributes and it did not originate from a XHR request
68
36
  if attrs and !options.xhr
@@ -80,10 +48,12 @@ class BaseModel
80
48
  # used by PubSub to record a remote change to the model
81
49
  addChangeSet: (change) ->
82
50
  change = new Lanes.Models.ChangeSet(change)
83
- this.set( change.value(), silent: true )
51
+ this.set('updatingFromChangeset', true, silent: true)
52
+ this.set( change.value() )
84
53
  for name, value of change.value()
85
- this.trigger("remote-update:#{name}", "changeset", this, change)
54
+ this.trigger("remote-update:#{name}", this, change)
86
55
  this.triggerChangeSet(this, change)
56
+ this.set('updatingFromChangeset', false, silent: true)
87
57
 
88
58
  triggerChangeSet: (triggered, change) ->
89
59
  this.changes ||= new Lanes.Models.ChangeSet.Collection( parent: this )
@@ -91,12 +61,15 @@ class BaseModel
91
61
  this.trigger('remote-update', triggered, change)
92
62
  @parent?.triggerChangeSet?(triggered, change)
93
63
 
64
+ modelTypeIdentifier: ->
65
+ _.dasherize(_.last(@FILE?.path || ''))
66
+
94
67
  api_path: ->
95
- path = if this.FILE then _.last(this.FILE.path) else ''
96
- _.pluralize(_.dasherize(path))
68
+ id = @FILE?.extension.identifier || ''
69
+ id + '/' + _.pluralize(@modelTypeIdentifier())
97
70
 
98
71
  urlRoot: ->
99
- Lanes.config.api_path + '/' + _.result(this, 'api_path')
72
+ Lanes.config.api_path + _.result(this, 'api_path')
100
73
 
101
74
  # Default URL for the model's representation on the server
102
75
  url: ->
@@ -108,16 +81,37 @@ class BaseModel
108
81
 
109
82
 
110
83
  # Ensures the assocations given in "names" are loaded
111
- withAssociations: (names..., options = {}) ->
112
- if _.isString(options)
113
- names.push(options); options = {}
84
+ withAssociations: (names, options = {}) ->
114
85
  needed = this.associations?.nonLoaded(this, names)
115
- if _.isEmpty( needed )
86
+ if _.isEmpty( needed ) and not options.force
116
87
  return _.Promise.resolve(this)
117
88
  else
118
89
  options['include'] = needed
119
90
  this.fetch(options)
120
91
 
92
+ clear: ->
93
+ this.associations?.clear(@)
94
+ super
95
+
96
+ # duplicate the model. Copies only attributes, not bound events
97
+ clone: ->
98
+ new @constructor( @clonedAttributes() )
99
+
100
+ clonedAttributes: ->
101
+ attributes = @serialize()
102
+ _.extend(attributes, @getAttributes(session: true) )
103
+
104
+ attributeType: (name) ->
105
+ @_definition[name].type
106
+
107
+ serialize: (options = {}) ->
108
+ options.depth ||= 1
109
+ return if options.depth > 5
110
+ depth = options.depth + 1
111
+ options = _.extend({}, options, {depth})
112
+ _.extend(super,
113
+ this.associations?.serialize(this, options)
114
+ )
121
115
 
122
116
  # Calls Ampersand State's set method, then sets any associations that are present as well
123
117
  set: (key, value, options) ->
@@ -129,7 +123,7 @@ class BaseModel
129
123
  attrs = {}
130
124
  attrs[key] = value
131
125
  super
132
- this.associations.set(this, attrs) if this.associations
126
+ this.associations.set(this, attrs, options) if this.associations
133
127
  this
134
128
 
135
129
  # Loads records from the server that match query, returns a collection
@@ -146,7 +140,8 @@ class BaseModel
146
140
  setFromServer: (data, options) ->
147
141
  data = if _.isArray(data) then data[0] else data
148
142
  BaseModel.__super__.set.call(this, data )
149
- this.associations.setFromServer(this, data) if this.associations
143
+ @unset('errors')
144
+ this.associations.setFromServer(this, data, options) if this.associations
150
145
  this.isDirty = false
151
146
 
152
147
  # save the model's data to the server
@@ -163,20 +158,16 @@ class BaseModel
163
158
 
164
159
  this.sync(method, this, options)
165
160
 
166
-
167
161
  # Fetch the model from the server. If the server's representation of the
168
162
  # model differs from its current attributes, they will be overridden,
169
163
  # triggering a `"change"` event.
170
164
  fetch: (original_options = {}) ->
171
- options = _.clone(original_options)
172
-
165
+ options = _.extend({}, original_options, {limit:1, ignoreUnsaved:true})
173
166
  if this.cacheDuration && _.isEmpty(original_options)
174
167
  Lanes.Models.ServerCache.fetchRecord(this, options)
175
168
  else
176
- _.extend(options, {limit:1, ignoreUnsaved:true})
177
169
  this.sync('read', this, options)
178
170
 
179
-
180
171
  @fetch: (options = {}) ->
181
172
  record = new this()
182
173
  record.fetch(options)
@@ -194,7 +185,9 @@ class BaseModel
194
185
  unsavedAttributes: ->
195
186
  attrs = {}
196
187
  _.extend(attrs, _.pick( this.getAttributes(props:true, true),
197
- @changeMonitor.changedAttributes() ) )
188
+ @changeMonitor?.changedAttributes() || {} ) )
189
+ unless _.isEmpty(attrs) or @isNew()
190
+ attrs[@idAttribute] = this.getId()
198
191
  attrs
199
192
 
200
193
  # returns data to save to server. If options.saveAll is true,
@@ -205,11 +198,13 @@ class BaseModel
205
198
  data = this.getAttributes(props:true, true)
206
199
  else
207
200
  data = this.unsavedAttributes()
208
- if this.associations && (!_.isEmpty(data) || !this.isNew())
201
+ if this.associations && (!_.isEmpty(data) || !this.isNew()) && !options.excludeAssociations
209
202
  data.id = this.getId() unless this.isNew()
210
203
  _.extend(data, this.associations.dataForSave(this, options))
211
204
  data
212
205
 
206
+ unCacheDerived: (name) ->
207
+ delete this._cache[name]
213
208
 
214
209
  # True if the model has "name" as either a prop or session attribute
215
210
  hasAttribute: (name) ->
@@ -219,6 +214,36 @@ class BaseModel
219
214
  sync: (options...) ->
220
215
  Lanes.Models.Sync.state(options...)
221
216
 
217
+ # Check if an attribute named "name" can be set to "value"
218
+ # Returns an empty string if value, and an appropriate error message if not
219
+ invalidMessageFor: (name) ->
220
+ return '' unless @unmaskedInvalidFields and _.include(@requiredAttributes, name) and
221
+ _.include(@unmaskedInvalidFields, name)
222
+
223
+ if @isBlank(name)
224
+ "Cannot be empty"
225
+ else
226
+ ''
227
+
228
+ maskInvalidFields: ->
229
+ delete @unmaskedInvalidFields
230
+
231
+ unmaskInvalidField: (attr) ->
232
+ if attr is 'all'
233
+ @unmaskedInvalidFields = 'all'
234
+ @trigger("invalid-fields", this, @unmaskedInvalidFields)
235
+ else if @unmaskedInvalidFields isnt 'all'
236
+ @unmaskedInvalidFields ||= []
237
+ if _.include(@requiredAttributes, attr) and !_.include(@unmaskedInvalidFields, attr)
238
+ @unmaskedInvalidFields.push(attr)
239
+ @trigger("invalid-field:#{attr}", this)
240
+
241
+ _calculateInvalidAttributes: ->
242
+ invalid = []
243
+ for name in @requiredAttributes
244
+ invalid.push(name) if @isBlank(name)
245
+ @invalidAttributes = invalid
246
+
222
247
  # When the model is extended it auto-creates the created_at and updated_at
223
248
  # and sets up the AssociationMap
224
249
  @extended: (klass) ->
@@ -234,6 +259,13 @@ class BaseModel
234
259
 
235
260
  @afterExtended: (klass) ->
236
261
  return if klass::abstractClass
262
+ attrs = []
263
+ for name, definition of klass::_definition when definition.required
264
+ attrs.push(name)
265
+ for name, definition of (klass::associations?.definitions || {}) when definition.required
266
+ attrs.push(name)
267
+ klass::requiredAttributes = attrs
268
+
237
269
  unless klass.Collection
238
270
  @createDefaultCollectionFor(klass)
239
271
 
@@ -255,20 +287,6 @@ class BaseModel
255
287
  @include Lanes.lib.results
256
288
 
257
289
 
258
- class State
259
- constructor: -> super
260
- isState: true
261
-
262
- # ## listenToAndRun
263
- # Shortcut for registering a listener for a model
264
- # and also triggering it right away.
265
- listenToAndRun: (object, events, handler) ->
266
- bound = _.bind(handler, this)
267
- this.listenTo(object, events, bound)
268
- bound()
269
-
270
- Lanes.Models.State = Lanes.lib.MakeBaseClass( Lanes.Vendor.Ampersand.State, State )
271
-
272
290
  # ------------------------------------------------------------------ #
273
291
  # The BasicModel is just a very thin layer over State #
274
292
  # ------------------------------------------------------------------ #
@@ -278,24 +296,18 @@ class BasicModel
278
296
  isPersistent: ->
279
297
  false
280
298
 
281
- # Check if an attribute named "name" can be set to "value"
282
- # Returns an empty string if value, and an appropriate error message if not
283
- checkValid: (name, value) ->
284
- return '' unless def = this._definition[name]
285
- if def.required && _.isEmpty(value)
286
- "Cannot be empty"
287
- else
288
- ''
299
+ isBlank: (name) ->
300
+ return _.isEmpty(this.serialize()) if _.isUndefined(name)
301
+ value = this.get(name)
302
+ _.isBlank(value) || (value.isProxy && value.isNew())
303
+
289
304
 
290
305
  # sets the model from a user interaction
291
306
  # subviews may override this to provide a custom implementation
292
307
  setFromView: (key, value) ->
293
308
  this.set(key, value)
294
309
 
295
- # True if the model has "name" as eitehr a prop or session attribute
296
- hasAttribute: (name) ->
297
- !! (this._definition[name] || this._derived[name])
298
310
 
299
- Lanes.Models.BasicModel = State.extend( BasicModel )
311
+ Lanes.Models.BasicModel = Lanes.Models.State.extend( BasicModel )
300
312
 
301
313
  Lanes.Models.Base = BasicModel.extend( BaseModel )