luca 0.9.42 → 0.9.65

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/CHANGELOG +50 -9
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +2 -0
  4. data/README.md +5 -0
  5. data/assets/javascripts/dependencies/underscore-min.js +5 -31
  6. data/lib/generators/luca/application/application_generator.rb +71 -0
  7. data/lib/generators/luca/application/templates/controller.rb +6 -0
  8. data/lib/generators/luca/application/templates/index.html.erb +7 -0
  9. data/lib/generators/luca/application/templates/index.html.haml +6 -0
  10. data/lib/generators/luca/application/templates/javascripts/application.js +28 -0
  11. data/lib/generators/luca/application/templates/javascripts/application.js.coffee +20 -0
  12. data/lib/generators/luca/application/templates/javascripts/config.js +15 -0
  13. data/lib/generators/luca/application/templates/javascripts/config.js.coffee +9 -0
  14. data/lib/generators/luca/application/templates/javascripts/dependencies.js +5 -0
  15. data/lib/generators/luca/application/templates/javascripts/dependencies.js.coffee +5 -0
  16. data/lib/generators/luca/application/templates/javascripts/index.js +9 -0
  17. data/lib/generators/luca/application/templates/javascripts/index.js.coffee +9 -0
  18. data/lib/generators/luca/application/templates/javascripts/main.js +8 -0
  19. data/lib/generators/luca/application/templates/javascripts/main.js.coffee +3 -0
  20. data/lib/generators/luca/application/templates/javascripts/main.jst.ejs +1 -0
  21. data/lib/generators/luca/application/templates/javascripts/router.js +12 -0
  22. data/lib/generators/luca/application/templates/javascripts/router.js.coffee +7 -0
  23. data/lib/luca/rails/version.rb +1 -1
  24. data/spec/components/collection_view_spec.coffee +59 -0
  25. data/spec/components/multi_collection_view_spec.coffee +5 -0
  26. data/{src/templates/components/form_alert → spec/components/pagination_control_spec.coffee} +0 -0
  27. data/spec/components/table_view_spec.coffee +17 -0
  28. data/spec/core/container_spec.coffee +127 -5
  29. data/spec/core/model_spec.coffee +21 -3
  30. data/spec/define_spec.coffee +19 -0
  31. data/spec/mixin_spec.coffee +49 -0
  32. data/spec/modules/filterable_spec.coffee +25 -0
  33. data/spec/modules/paginatable_spec.coffee +0 -0
  34. data/spec/modules/state_model_spec.coffee +0 -0
  35. data/src/components/application.coffee +52 -38
  36. data/src/components/collection_view.coffee +118 -45
  37. data/src/components/fields/checkbox_field.coffee +2 -2
  38. data/src/components/fields/file_upload_field.coffee +0 -3
  39. data/src/components/fields/hidden_field.coffee +0 -3
  40. data/src/components/fields/label_field.coffee +1 -4
  41. data/src/components/fields/select_field.coffee +6 -6
  42. data/src/components/fields/text_area_field.coffee +1 -0
  43. data/src/components/fields/text_field.coffee +4 -0
  44. data/src/components/fields/type_ahead_field.coffee +5 -9
  45. data/src/components/form_view.coffee +28 -23
  46. data/src/components/multi_collection_view.coffee +121 -0
  47. data/src/components/pagination_control.coffee +106 -0
  48. data/src/components/table_view.coffee +22 -13
  49. data/src/containers/card_view.coffee +44 -11
  50. data/src/containers/panel_toolbar.coffee +88 -82
  51. data/src/containers/tab_view.coffee +3 -3
  52. data/src/core/collection.coffee +11 -4
  53. data/src/core/container.coffee +206 -122
  54. data/src/core/field.coffee +13 -10
  55. data/src/core/model.coffee +23 -27
  56. data/src/core/registry.coffee +42 -29
  57. data/src/core/view.coffee +63 -149
  58. data/src/define.coffee +91 -19
  59. data/src/framework.coffee +11 -9
  60. data/src/managers/collection_manager.coffee +24 -8
  61. data/src/modules/application_event_bindings.coffee +19 -0
  62. data/src/modules/collection_event_bindings.coffee +26 -0
  63. data/src/modules/deferrable.coffee +3 -1
  64. data/src/modules/dom_helpers.coffee +49 -0
  65. data/src/modules/enhanced_properties.coffee +23 -0
  66. data/src/modules/filterable.coffee +82 -0
  67. data/src/modules/grid_layout.coffee +13 -1
  68. data/src/modules/{load_mask.coffee → loadmaskable.coffee} +10 -4
  69. data/src/modules/modal_view.coffee +38 -0
  70. data/src/modules/paginatable.coffee +87 -0
  71. data/src/modules/state_model.coffee +16 -0
  72. data/src/modules/templating.coffee +8 -0
  73. data/src/plugins/events.coffee +30 -2
  74. data/src/templates/components/bootstrap_form_controls.jst.ejs +10 -0
  75. data/src/templates/components/collection_loader_view.jst.ejs +6 -0
  76. data/src/templates/components/form_alert.jst.ejs +4 -0
  77. data/src/templates/components/grid_view.jst.ejs +11 -0
  78. data/src/templates/components/grid_view_empty_text.jst.ejs +3 -0
  79. data/src/templates/components/load_mask.jst.ejs +5 -0
  80. data/src/templates/components/nav_bar.jst.ejs +4 -0
  81. data/src/templates/components/pagination.jst.ejs +10 -0
  82. data/src/templates/containers/basic.jst.ejs +1 -0
  83. data/src/templates/containers/tab_selector_container.jst.ejs +12 -0
  84. data/src/templates/containers/tab_view.jst.ejs +2 -0
  85. data/src/templates/containers/toolbar_wrapper.jst.ejs +1 -0
  86. data/src/templates/fields/button_field.jst.ejs +2 -0
  87. data/src/templates/fields/button_field_link.jst.ejs +6 -0
  88. data/src/templates/fields/checkbox_array.jst.ejs +4 -0
  89. data/src/templates/fields/checkbox_array_item.jst.ejs +3 -0
  90. data/src/templates/fields/checkbox_field.jst.ejs +10 -0
  91. data/src/templates/fields/file_upload_field.jst.ejs +10 -0
  92. data/src/templates/fields/hidden_field.jst.ejs +1 -0
  93. data/src/templates/fields/select_field.jst.ejs +11 -0
  94. data/src/templates/fields/text_area_field.jst.ejs +11 -0
  95. data/src/templates/fields/text_field.jst.ejs +16 -0
  96. data/src/templates/table_view.jst.ejs +4 -0
  97. data/src/tools/console.coffee +51 -21
  98. data/src/util.coffee +17 -4
  99. data/vendor/assets/javascripts/luca-ui-base.js +5304 -0
  100. data/vendor/assets/javascripts/luca-ui-bootstrap.js +9 -0
  101. data/vendor/assets/javascripts/luca-ui-development-tools.js +52 -24
  102. data/vendor/assets/javascripts/luca-ui-development-tools.min.js +1 -1
  103. data/vendor/assets/javascripts/luca-ui-full.js +1700 -595
  104. data/vendor/assets/javascripts/luca-ui-full.min.js +7 -6
  105. data/vendor/assets/javascripts/luca-ui-spec.js +6815 -0
  106. data/vendor/assets/javascripts/luca-ui-templates.js +92 -24
  107. data/vendor/assets/javascripts/luca-ui.js +1695 -564
  108. data/vendor/assets/javascripts/luca-ui.min.js +4 -4
  109. metadata +69 -28
  110. data/src/templates/components/bootstrap_form_controls.luca +0 -7
  111. data/src/templates/components/collection_loader_view.luca +0 -5
  112. data/src/templates/components/form_alert.luca +0 -3
  113. data/src/templates/components/grid_view.luca +0 -7
  114. data/src/templates/components/grid_view_empty_text.luca +0 -3
  115. data/src/templates/components/load_mask.luca +0 -3
  116. data/src/templates/components/nav_bar.luca +0 -2
  117. data/src/templates/containers/basic.luca +0 -1
  118. data/src/templates/containers/tab_selector_container.luca +0 -8
  119. data/src/templates/containers/tab_view.luca +0 -2
  120. data/src/templates/containers/toolbar_wrapper.luca +0 -1
  121. data/src/templates/fields/button_field.luca +0 -2
  122. data/src/templates/fields/button_field_link.luca +0 -5
  123. data/src/templates/fields/checkbox_array.luca +0 -4
  124. data/src/templates/fields/checkbox_array_item.luca +0 -4
  125. data/src/templates/fields/checkbox_field.luca +0 -9
  126. data/src/templates/fields/file_upload_field.luca +0 -8
  127. data/src/templates/fields/hidden_field.luca +0 -1
  128. data/src/templates/fields/select_field.luca +0 -8
  129. data/src/templates/fields/text_area_field.luca +0 -8
  130. data/src/templates/fields/text_field.luca +0 -17
  131. data/src/templates/sample/contents.luca +0 -1
  132. data/src/templates/sample/welcome.luca +0 -1
  133. data/src/templates/table_view.luca +0 -4
@@ -1,3 +1,4 @@
1
+ # Public: TableView renders collection data into an HTML table.
1
2
  _.def("Luca.components.TableView").extends("Luca.components.CollectionView").with
2
3
  additionalClassNames: "table"
3
4
  tagName: "table"
@@ -15,18 +16,21 @@ _.def("Luca.components.TableView").extends("Luca.components.CollectionView").wit
15
16
  itemRenderer: (item, model)->
16
17
  Luca.components.TableView.rowRenderer.call(@, item, model)
17
18
 
18
- emptyResults: ()->
19
- @$('tbody').append("<tr><td colspan=#{ @columns.length }>#{ @emptyText }</td></tr>")
20
-
21
19
  initialize: (@options={})->
22
20
  Luca.components.CollectionView::initialize.apply(@, arguments)
21
+
22
+ @columns = for column in @columns
23
+ if _.isString(column)
24
+ column = reader: column
25
+
26
+ if !column.header?
27
+ column.header = _.str.titleize(_.str.humanize(column.reader))
28
+
29
+ column
30
+
23
31
  @defer ()=>
24
32
  Luca.components.TableView.renderHeader.call(@, @columns, @$('thead') )
25
- # TEMP
26
- # This is a result of the @additionalClassNames inheritance bug
27
- @$el.removeClass('row-fluid')
28
- .until("before:render")
29
-
33
+ .until("after:render")
30
34
 
31
35
  make = Backbone.View::make
32
36
 
@@ -34,20 +38,25 @@ Luca.components.TableView.renderHeader = (columns, targetElement)->
34
38
  index = 0
35
39
 
36
40
  content = for column in columns
37
- "<th data-col-index='#{ index }'>#{ column.header }</th>"
41
+ "<th data-col-index='#{ index++ }'>#{ column.header }</th>"
38
42
 
39
- $( targetElement ).append(make "tr",{}, content)
43
+ @$( targetElement ).append("<tr>#{ content.join('') }</tr>")
40
44
 
41
45
  index = 0
42
46
 
43
47
  for column in columns when column.width?
44
- @$("th[data-col-index='#{ index }']",targetElement).css('width', column.width)
48
+ @$("th[data-col-index='#{ index++ }']",targetElement).css('width', column.width)
45
49
 
46
50
 
47
51
  Luca.components.TableView.rowRenderer = (item, model, index)->
52
+ colIndex = 0
48
53
  for columnConfig in @columns
49
- Luca.components.TableView.renderColumn.call(@, columnConfig, item, model, index)
54
+ Luca.components.TableView.renderColumn.call(@, columnConfig, item, model, colIndex++)
50
55
 
51
56
  Luca.components.TableView.renderColumn = (column, item, model, index)->
52
57
  cellValue = model.read( column.reader )
53
- make("td", {}, cellValue)
58
+
59
+ if _.isFunction( column.renderer )
60
+ cellValue = column.renderer.call @, cellValue, model, column
61
+
62
+ make("td", {"data-col-index":index}, cellValue)
@@ -1,5 +1,28 @@
1
- _.def("Luca.containers.CardView").extends("Luca.core.Container").with
2
- componentType: 'card_view'
1
+ component = Luca.define "Luca.containers.CardView"
2
+ component.extends "Luca.core.Container"
3
+ #
4
+ # The CardView is a type of Container which has many sub-views
5
+ # which are only going to be visible one at a time. A CardView
6
+ # allows you to @activate() its cards, navigate through them using
7
+ # @next(), @previous(), @cycle()
8
+ #
9
+ # Example:
10
+ # cardView = new Luca.containers.CardView
11
+ # cards:[
12
+ # getter: "getCardOne"
13
+ # type: "my_component"
14
+ # name: "one"
15
+ # ,
16
+ # getter: "getCardTwo"
17
+ # type: "my_component"
18
+ # name: "two"
19
+ # ]
20
+ #
21
+ # cardView.activeComponent().name # => "one"
22
+ # cardView.activate('two')
23
+ # cardView.activeComponent().name # => "two"
24
+ #
25
+ component.defaults
3
26
 
4
27
  className: 'luca-ui-card-view-wrapper'
5
28
 
@@ -18,15 +41,12 @@ _.def("Luca.containers.CardView").extends("Luca.core.Container").with
18
41
  initialize: (@options)->
19
42
  Luca.core.Container::initialize.apply @,arguments
20
43
  @setupHooks(@hooks)
44
+ @components ||= @pages ||= @cards
21
45
 
22
46
  prepareComponents: ()->
23
47
  Luca.core.Container::prepareComponents?.apply(@, arguments)
24
-
25
- _( @components ).each (component,index)=>
26
- if index is @activeCard
27
- $( component.container ).show()
28
- else
29
- $( component.container ).hide()
48
+ @componentElements().hide()
49
+ @activeComponentElement().show()
30
50
 
31
51
  activeComponentElement: ()->
32
52
  @componentElements().eq( @activeCard )
@@ -39,12 +59,25 @@ _.def("Luca.containers.CardView").extends("Luca.core.Container").with
39
59
 
40
60
  containerEl
41
61
 
62
+ atFirst: ()->
63
+ @activeCard is 0
64
+
65
+ atLast: ()->
66
+ @activeCard is @components.length - 1
67
+
68
+ next: ()->
69
+ return if @atLast()
70
+ @activate( @activeCard + 1)
71
+
72
+ previous: ()->
73
+ return if @atFirst()
74
+ @activate( @activeCard - 1)
75
+
42
76
  cycle: ()->
43
- nextIndex = if @activeCard < @components.length - 1 then @activeCard + 1 else 0
77
+ nextIndex = if @atLast() then 0 else @activeCard + 1
44
78
  @activate( nextIndex )
45
79
 
46
- find: (name)->
47
- @findComponentByName(name,true)
80
+ find: (name)-> Luca(name)
48
81
 
49
82
  firstActivation: ()->
50
83
  @activeComponent().trigger "first:activation", @, @activeComponent()
@@ -1,26 +1,95 @@
1
+ panelToolbar = Luca.register "Luca.components.PanelToolbar"
2
+ # The Panel Toolbar is a collection of buttons and / or dropdowns
3
+ # which are automatically created by BasicPanel classes, or can be
4
+ # added to any other view component.
5
+ panelToolbar.extends "Luca.View"
6
+
7
+
8
+ panelToolbar.defines
9
+ # @buttons is an array of button config objects
10
+ # button config accepts the following paramters:
11
+ #
12
+ # label what should the button say
13
+ # eventId what event should the button trigger
14
+ # dropdown an array of arrays: [eventId, label]
15
+ # group an array of button configs
16
+ # wrapper a css class, in addition to btn-group
17
+ # icon which icon do you want to use on this button?
18
+ # white true or false: is it a white colored text?
19
+ # color options are primary, info, success, warning, danger, inverse
20
+ buttons:[]
21
+
22
+ className: "luca-ui-toolbar btn-toolbar"
23
+
24
+ well: true
25
+
26
+ orientation: 'top'
27
+
28
+ autoBindEventHandlers: true
29
+
30
+ events:
31
+ "click a.btn, click .dropdown-menu li" : "clickHandler"
32
+
33
+ initialize: (@options={})->
34
+ @_super("initialize", @, arguments)
35
+
36
+ # if the toolbar consists of a single button group
37
+ # don't make the developer specify buttons = {buttons:[group:true, buttons:[...]]}
38
+ if @group is true and @buttons?.length >= 0
39
+ @buttons = [
40
+ group: true
41
+ buttons: @buttons
42
+ ]
43
+
44
+ # The Toolbar behaves by triggering events on the components which they
45
+ # belong to. Combined with Luca.View::setupHooks it is a clean way
46
+ # to organize actions
47
+ clickHandler: (e)->
48
+ me = my = $( e.target )
49
+ me = my = $( e.target ).parent() if me.is('i')
50
+
51
+ if @selectable is true
52
+ my.siblings().removeClass("is-selected")
53
+ me.addClass('is-selected')
54
+
55
+ return unless eventId = my.data('eventid')
56
+
57
+ hook = Luca.util.hook( eventId )
58
+
59
+ source = @parent || @
60
+ if _.isFunction( source[hook] )
61
+ source[ hook ].call(@, me, e)
62
+ else
63
+ source.trigger(eventId, me, e)
64
+
65
+ beforeRender:()->
66
+ @_super("beforeRender", @, arguments)
67
+
68
+ if @well is true
69
+ @$el.addClass 'well'
70
+
71
+ @$el.addClass 'btn-selectable' if @selectable is true
72
+ @$el.addClass "toolbar-#{ @orientation }"
73
+ @$el.addClass "pull-right" if @align is "right"
74
+ @$el.addClass "pull-left" if @align is "left"
75
+
76
+ render: ()->
77
+ @$el.empty()
78
+ @$el.append( element ) for element in prepareButtons(@buttons)
79
+ @
1
80
 
2
- # button config accepts the following paramters:
3
- #
4
- # label what should the button say
5
- # eventId what event should the button trigger
6
- # dropdown an array of arrays: [eventId, label]
7
- # group an array of button configs
8
- # wrapper a css class, in addition to btn-group
9
- # icon which icon do you want to use on this button?
10
- # white true or false: is it a white colored text?
11
- # color options are primary, info, success, warning, danger, inverse
12
81
 
13
82
  make = Backbone.View::make
14
83
 
15
84
  buildButton = (config, wrap=true)->
16
- if config.ctype?
85
+ if config.ctype? or config.type?
17
86
  config.className ||= ""
18
87
  config.className += 'toolbar-component'
19
88
 
20
89
  object = Luca(config).render()
90
+
21
91
  if Luca.isBackboneView(object)
22
- console.log "Adding toolbar component", object
23
- return object.el
92
+ return object.$el
24
93
 
25
94
  if config.spacer
26
95
  return make "div", class: "spacer #{ config.spacer }"
@@ -29,8 +98,9 @@ buildButton = (config, wrap=true)->
29
98
  return make "div", {class: "toolbar-text"}, config.text
30
99
 
31
100
  wrapper = 'btn-group'
32
- wrapper += " #{ config.wrapper }" if config.wrapper?
33
- wrapper += " align-#{ config.align }" if config.align?
101
+ wrapper += "#{ config.wrapper }" if config.wrapper?
102
+ wrapper += "pull-#{ config.align } align-#{ config.align }" if config.align?
103
+ wrapper += 'btn-selectable' if config.selectable is true
34
104
 
35
105
  # if we're passed a group, then we need to just
36
106
  # wrap the contents of the buttons property in that group
@@ -57,6 +127,7 @@ buildButton = (config, wrap=true)->
57
127
  title: config.title || config.description
58
128
 
59
129
  buttonAttributes["class"] += " btn-#{ config.color }" if config.color?
130
+ buttonAttributes["class"] += " is-selected" if config.selected?
60
131
 
61
132
  if config.dropdown
62
133
  label = "#{ label } <span class='caret'></span>"
@@ -82,70 +153,5 @@ buildButton = (config, wrap=true)->
82
153
  # for buttons which are already part f a group
83
154
  buttonEl
84
155
 
85
- prepareButtons = (buttons, wrap=true)->
86
- _( buttons ).map (button)->
87
- buildButton(button, wrap)
88
-
89
-
90
- #### Panel Toolbar Component
91
- #
92
- # The Panel Toolbar is a collection of buttons and / or dropdowns
93
- # which are automatically created by BasicPanel classes, or can be
94
- # added to any other view component.
95
- _.def("Luca.containers.PanelToolbar").extends("Luca.View").with
96
-
97
- className: "luca-ui-toolbar btn-toolbar"
98
-
99
- # @buttons is an array of button config objects
100
-
101
-
102
- buttons:[]
103
-
104
- well: true
105
-
106
- orientation: 'top'
107
-
108
- autoBindEventHandlers: true
109
-
110
- events:
111
- "click a.btn, click .dropdown-menu li" : "clickHandler"
112
-
113
- #autoBindEventHandlers: true
114
-
115
- # The Toolbar behaves by triggering events on the components which they
116
- # belong to. Combined with Luca.View::setupHooks it is a clean way
117
- # to organize actions
118
- clickHandler: (e)->
119
- me = my = $( e.target )
120
-
121
- if me.is('i')
122
- me = my = $( e.target ).parent()
123
-
124
- eventId = my.data('eventid')
125
-
126
- return unless eventId?
127
-
128
- hook = Luca.util.hook( eventId )
129
-
130
- source = @parent || @
131
- if _.isFunction( source[hook] )
132
- source[ hook ].call(@, me, e)
133
- else
134
- source.trigger(eventId, me, e)
135
-
136
- beforeRender:()->
137
- @_super("beforeRender", @, arguments)
138
-
139
- if @well is true
140
- @$el.addClass 'well'
141
-
142
- @$el.addClass "toolbar-#{ @orientation }"
143
-
144
- @applyStyles( @styles ) if @styles?
145
-
146
- render: ()->
147
- @$el.empty()
148
-
149
- elements = prepareButtons(@buttons)
150
- _( elements ).each (element)=>
151
- @$el.append( element )
156
+ prepareButtons = (buttons=[], wrap=true)->
157
+ buildButton(button, wrap) for button in buttons
@@ -42,17 +42,17 @@ _.def('Luca.containers.TabView').extends('Luca.containers.CardView').with
42
42
 
43
43
  afterRender: ()->
44
44
  Luca.containers.CardView::afterRender?.apply @, arguments
45
- @registerEvent("click ##{ @cid }-tabs-selector li a", "select")
45
+ tabContainerId = @tabContainer().attr("id")
46
+ @registerEvent("click ##{ tabContainerId } li a", "select")
46
47
 
47
48
  if Luca.enableBootstrap and (@tab_position is "left" or @tab_position is "right")
48
49
  @tabContainerWrapper().addClass("span2")
49
50
  @tabContentWrapper().addClass("span9")
50
51
 
51
-
52
52
  createTabSelectors: ()->
53
53
  tabView = @
54
54
  @each (component,index)->
55
- icon = "<i class='icon-#{ component.tabIcon }" if component.tabIcon
55
+ icon = "<i class='icon-#{ component.tabIcon }'></i>" if component.tabIcon
56
56
  link = "<a href='#'>#{ icon || ''} #{ component.title }</a>"
57
57
  selector = tabView.make("li",{class:"tab-selector","data-target":index}, link)
58
58
  tabView.tabContainer().append(selector)
@@ -1,8 +1,14 @@
1
- source = 'Backbone.Collection'
2
- source = 'Backbone.QueryCollection' if Backbone.QueryCollection?
1
+ collection = Luca.define 'Luca.Collection'
3
2
 
4
- _.def("Luca.Collection").extends( source ).with
5
- include: ['Luca.Events']
3
+ if Backbone.QueryCollection?
4
+ collection.extends 'Backbone.QueryCollection'
5
+ else
6
+ collection.extends 'Backbone.Collection'
7
+
8
+ collection.includes 'Luca.Events'
9
+
10
+ collection.defines
11
+ model: Luca.Model
6
12
  # cachedMethods refers to a list of methods on the collection
7
13
  # whose value gets cached once it is ran. the collection then
8
14
  # binds to change, add, remove, and reset events and then expires
@@ -325,6 +331,7 @@ _.def("Luca.Collection").extends( source ).with
325
331
  collection.bind "change:#{dependency}", ()->
326
332
  collection.clearMethodCache(method: method)
327
333
 
334
+
328
335
  # make sure the querying interface from backbone.query is present
329
336
  # in the case backbone-query isn't loaded. without it, it will
330
337
  # just return the models