sproutcore 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/History.txt +233 -0
  2. data/Manifest.txt +67 -34
  3. data/bin/sc-build +12 -1
  4. data/bin/sc-gen +1 -1
  5. data/bin/sproutcore +14 -0
  6. data/clients/sc_docs/controllers/docs.js +38 -8
  7. data/clients/sc_docs/english.lproj/body.css +80 -127
  8. data/clients/sc_docs/english.lproj/body.rhtml +43 -23
  9. data/clients/sc_docs/english.lproj/no_docs.rhtml +2 -1
  10. data/clients/sc_docs/english.lproj/tabs.rhtml +16 -0
  11. data/clients/sc_docs/main.js +14 -9
  12. data/clients/sc_docs/models/doc.js +1 -1
  13. data/clients/sc_docs/tests/controllers/docs.rhtml +1 -2
  14. data/clients/sc_docs/tests/models/doc.rhtml +1 -2
  15. data/clients/sc_docs/tests/views/doc_frame.rhtml +1 -2
  16. data/clients/sc_docs/tests/views/doc_label_view.rhtml +1 -2
  17. data/clients/sc_docs/views/doc_frame.js +1 -1
  18. data/clients/sc_test_runner/controllers/runner.js +31 -8
  19. data/clients/sc_test_runner/english.lproj/body.css +62 -122
  20. data/clients/sc_test_runner/english.lproj/body.rhtml +62 -26
  21. data/clients/sc_test_runner/main.js +1 -6
  22. data/clients/sc_test_runner/models/test.js +14 -1
  23. data/clients/sc_test_runner/views/runner_frame.js +4 -2
  24. data/clients/view_builder/builders/builder.js +339 -0
  25. data/clients/view_builder/builders/button.js +81 -0
  26. data/clients/view_builder/controllers/document.js +21 -0
  27. data/clients/view_builder/core.js +19 -0
  28. data/clients/view_builder/english.lproj/body.css +77 -0
  29. data/clients/view_builder/english.lproj/body.rhtml +41 -0
  30. data/clients/{sc_docs → view_builder}/english.lproj/controls.css +0 -0
  31. data/clients/view_builder/english.lproj/strings.js +14 -0
  32. data/clients/view_builder/main.js +38 -0
  33. data/clients/view_builder/tests/controllers/document.rhtml +20 -0
  34. data/clients/view_builder/tests/views/builder.rhtml +20 -0
  35. data/clients/view_builder/views/builder.js +23 -0
  36. data/frameworks/prototype/prototype.js +1 -1
  37. data/frameworks/sproutcore/Core.js +32 -7
  38. data/frameworks/sproutcore/README +1 -1
  39. data/frameworks/sproutcore/animation/animation.js +411 -0
  40. data/frameworks/sproutcore/controllers/array.js +17 -9
  41. data/frameworks/sproutcore/controllers/collection.js +9 -110
  42. data/frameworks/sproutcore/controllers/controller.js +1 -1
  43. data/frameworks/sproutcore/controllers/object.js +2 -1
  44. data/frameworks/sproutcore/drag/drag.js +267 -56
  45. data/frameworks/sproutcore/drag/drag_data_source.js +24 -16
  46. data/frameworks/sproutcore/drag/drag_source.js +53 -42
  47. data/frameworks/sproutcore/drag/drop_target.js +2 -2
  48. data/frameworks/sproutcore/english.lproj/buttons.css +337 -236
  49. data/frameworks/sproutcore/english.lproj/core.css +115 -0
  50. data/frameworks/sproutcore/english.lproj/icons.css +227 -0
  51. data/{clients/sc_docs → frameworks/sproutcore}/english.lproj/images/indicator.gif +0 -0
  52. data/frameworks/sproutcore/english.lproj/images/sc-theme-sprite.png +0 -0
  53. data/frameworks/sproutcore/english.lproj/images/sc-theme-ysprite.png +0 -0
  54. data/frameworks/sproutcore/english.lproj/images/shared-icons.png +0 -0
  55. data/frameworks/sproutcore/english.lproj/menu.css +1 -1
  56. data/frameworks/sproutcore/english.lproj/strings.js +1 -1
  57. data/frameworks/sproutcore/english.lproj/theme.css +405 -31
  58. data/frameworks/sproutcore/foundation/application.js +15 -11
  59. data/frameworks/sproutcore/foundation/benchmark.js +1 -1
  60. data/frameworks/sproutcore/foundation/binding.js +2 -2
  61. data/frameworks/sproutcore/foundation/date.js +1 -1
  62. data/frameworks/sproutcore/foundation/error.js +1 -1
  63. data/frameworks/sproutcore/foundation/input_manager.js +32 -21
  64. data/frameworks/sproutcore/foundation/mock.js +1 -1
  65. data/frameworks/sproutcore/foundation/node_descriptor.js +9 -6
  66. data/frameworks/sproutcore/foundation/object.js +249 -177
  67. data/frameworks/sproutcore/foundation/page.js +5 -2
  68. data/frameworks/sproutcore/foundation/path_module.js +11 -10
  69. data/frameworks/sproutcore/foundation/responder.js +5 -2
  70. data/frameworks/sproutcore/foundation/routes.js +17 -13
  71. data/frameworks/sproutcore/foundation/run_loop.js +249 -11
  72. data/frameworks/sproutcore/foundation/server.js +1 -1
  73. data/frameworks/sproutcore/foundation/set.js +3 -3
  74. data/frameworks/sproutcore/foundation/string.js +5 -3
  75. data/frameworks/sproutcore/foundation/timer.js +371 -0
  76. data/frameworks/sproutcore/foundation/undo_manager.js +1 -1
  77. data/frameworks/sproutcore/foundation/unittest.js +3 -3
  78. data/frameworks/sproutcore/foundation/utils.js +161 -2
  79. data/frameworks/sproutcore/globals/panels.js +1 -1
  80. data/frameworks/sproutcore/globals/popups.js +4 -3
  81. data/frameworks/sproutcore/globals/window.js +44 -4
  82. data/frameworks/sproutcore/lib/button_views.rb +328 -0
  83. data/frameworks/sproutcore/lib/collection_view.rb +80 -0
  84. data/frameworks/sproutcore/lib/core_views.rb +281 -0
  85. data/frameworks/sproutcore/lib/form_views.rb +253 -0
  86. data/frameworks/sproutcore/lib/index.rhtml +2 -0
  87. data/frameworks/sproutcore/lib/menu_views.rb +88 -0
  88. data/frameworks/sproutcore/{foundation → mixins}/array.js +60 -29
  89. data/frameworks/sproutcore/mixins/control.js +265 -0
  90. data/frameworks/sproutcore/mixins/delegate_support.js +66 -0
  91. data/frameworks/sproutcore/{foundation → mixins}/observable.js +176 -6
  92. data/frameworks/sproutcore/mixins/scrollable.js +245 -0
  93. data/frameworks/sproutcore/mixins/selection_support.js +148 -0
  94. data/frameworks/sproutcore/mixins/validatable.js +152 -0
  95. data/frameworks/sproutcore/models/collection.js +5 -5
  96. data/frameworks/sproutcore/models/record.js +1 -1
  97. data/frameworks/sproutcore/models/store.js +1 -1
  98. data/frameworks/sproutcore/panes/dialog.js +1 -1
  99. data/frameworks/sproutcore/panes/manager.js +1 -1
  100. data/frameworks/sproutcore/panes/menu.js +1 -1
  101. data/frameworks/sproutcore/panes/overlay.js +2 -2
  102. data/frameworks/sproutcore/panes/panel.js +1 -1
  103. data/frameworks/sproutcore/panes/picker.js +1 -1
  104. data/frameworks/sproutcore/tests/controllers/array.rhtml +44 -4
  105. data/frameworks/sproutcore/tests/foundation/timer/invalidate.rhtml +33 -0
  106. data/frameworks/sproutcore/tests/foundation/timer/invokeLater.rhtml +145 -0
  107. data/frameworks/sproutcore/tests/foundation/timer/isPaused.rhtml +70 -0
  108. data/frameworks/sproutcore/tests/foundation/timer/schedule.rhtml +145 -0
  109. data/frameworks/sproutcore/tests/views/{scroll.rhtml → checkbox.rhtml} +3 -3
  110. data/frameworks/sproutcore/tests/views/{collection.rhtml → collection/base.rhtml} +33 -32
  111. data/frameworks/sproutcore/tests/views/collection/incremental_rendering.rhtml +260 -0
  112. data/frameworks/sproutcore/tests/views/image_cell.rhtml +19 -0
  113. data/frameworks/sproutcore/tests/views/label_item.rhtml +2 -4
  114. data/frameworks/sproutcore/tests/views/list.rhtml +2 -3
  115. data/frameworks/sproutcore/tests/views/list_item.rhtml +20 -0
  116. data/frameworks/sproutcore/tests/views/slider.rhtml +20 -0
  117. data/frameworks/sproutcore/tests/views/text_cell.rhtml +19 -0
  118. data/frameworks/sproutcore/tests/views/view/clippingFrame.rhtml +395 -0
  119. data/frameworks/sproutcore/tests/views/view/frame.rhtml +353 -0
  120. data/frameworks/sproutcore/tests/views/view/innerFrame.rhtml +347 -0
  121. data/frameworks/sproutcore/tests/views/view/isVisibleInWindow.rhtml +148 -0
  122. data/frameworks/sproutcore/tests/views/view/scrollFrame.rhtml +468 -0
  123. data/frameworks/sproutcore/validators/credit_card.js +33 -13
  124. data/frameworks/sproutcore/validators/date.js +26 -6
  125. data/frameworks/sproutcore/validators/email.js +21 -3
  126. data/frameworks/sproutcore/validators/not_empty.js +11 -1
  127. data/frameworks/sproutcore/validators/number.js +18 -4
  128. data/frameworks/sproutcore/validators/password.js +12 -1
  129. data/frameworks/sproutcore/validators/validator.js +204 -194
  130. data/frameworks/sproutcore/views/{button.js → button/button.js} +96 -94
  131. data/frameworks/sproutcore/views/button/checkbox.js +29 -0
  132. data/frameworks/sproutcore/views/button/disclosure.js +42 -0
  133. data/frameworks/sproutcore/views/button/radio.js +29 -0
  134. data/frameworks/sproutcore/views/{collection.js → collection/collection.js} +1373 -1024
  135. data/frameworks/sproutcore/views/collection/grid.js +124 -46
  136. data/frameworks/sproutcore/views/collection/image_cell.js +17 -46
  137. data/frameworks/sproutcore/views/collection/list.js +45 -35
  138. data/frameworks/sproutcore/views/collection/source_list.js +386 -0
  139. data/frameworks/sproutcore/views/collection/table.js +118 -0
  140. data/frameworks/sproutcore/views/container.js +7 -2
  141. data/frameworks/sproutcore/views/error_explanation.js +23 -10
  142. data/frameworks/sproutcore/views/{checkbox_field.js → field/checkbox_field.js} +16 -6
  143. data/frameworks/sproutcore/views/field/field.js +219 -0
  144. data/frameworks/sproutcore/views/{radio_field.js → field/radio_field.js} +27 -12
  145. data/frameworks/sproutcore/views/{select_field.js → field/select_field.js} +116 -90
  146. data/frameworks/sproutcore/views/{text_field.js → field/text_field.js} +57 -8
  147. data/frameworks/sproutcore/views/{textarea_field.js → field/textarea_field.js} +13 -3
  148. data/frameworks/sproutcore/views/filter_button.js +2 -2
  149. data/frameworks/sproutcore/views/form.js +3 -3
  150. data/frameworks/sproutcore/views/image.js +128 -21
  151. data/frameworks/sproutcore/views/inline_text_editor.js +1 -1
  152. data/frameworks/sproutcore/views/label.js +149 -92
  153. data/frameworks/sproutcore/views/list_item.js +225 -0
  154. data/frameworks/sproutcore/views/menu_item.js +10 -4
  155. data/frameworks/sproutcore/views/pagination.js +11 -4
  156. data/frameworks/sproutcore/views/popup_button.js +25 -21
  157. data/frameworks/sproutcore/views/popup_menu.js +10 -4
  158. data/frameworks/sproutcore/views/progress.js +29 -16
  159. data/frameworks/sproutcore/views/radio_group.js +1 -1
  160. data/frameworks/sproutcore/views/scroll.js +60 -20
  161. data/frameworks/sproutcore/views/segmented.js +1 -1
  162. data/frameworks/sproutcore/views/slider.js +132 -0
  163. data/frameworks/sproutcore/views/source_list_group.js +130 -0
  164. data/frameworks/sproutcore/views/spinner.js +1 -1
  165. data/frameworks/sproutcore/views/split.js +292 -0
  166. data/frameworks/sproutcore/views/split_divider.js +109 -0
  167. data/frameworks/sproutcore/views/tab.js +1 -1
  168. data/frameworks/sproutcore/views/toolbar.js +1 -1
  169. data/frameworks/sproutcore/views/view.js +1272 -591
  170. data/generators/client/templates/english.lproj/body.css +1 -1
  171. data/generators/controller/controller_generator.rb +1 -1
  172. data/generators/controller/templates/test.rhtml +2 -1
  173. data/generators/model/templates/test.rhtml +1 -1
  174. data/generators/test/templates/test.rhtml +1 -1
  175. data/generators/view/templates/test.rhtml +1 -1
  176. data/jsdoc/templates/sproutcore/class.tmpl +241 -338
  177. data/jsdoc/templates/sproutcore/default.css +105 -155
  178. data/jsdoc/templates/sproutcore/index.tmpl +43 -8
  179. data/jsdoc/templates/sproutcore/publish.js +9 -4
  180. data/lib/sproutcore/build_tools/html_builder.rb +29 -13
  181. data/lib/sproutcore/build_tools/resource_builder.rb +1 -1
  182. data/lib/sproutcore/bundle.rb +86 -25
  183. data/lib/sproutcore/jsdoc.rb +2 -0
  184. data/lib/sproutcore/version.rb +1 -1
  185. data/lib/sproutcore/view_helpers.rb +36 -3
  186. data/tasks/deployment.rake +1 -1
  187. metadata +69 -36
  188. data/clients/sc_docs/english.lproj/icons/small/next.png +0 -0
  189. data/clients/sc_docs/english.lproj/icons/small/reset.png +0 -0
  190. data/clients/sc_docs/english.lproj/images/gradients.png +0 -0
  191. data/clients/sc_docs/english.lproj/images/toolbar.png +0 -0
  192. data/clients/sc_docs/english.lproj/warning.rhtml +0 -6
  193. data/clients/sc_test_runner/english.lproj/warning.rhtml +0 -6
  194. data/frameworks/sproutcore/english.lproj/buttons.png +0 -0
  195. data/frameworks/sproutcore/english.lproj/collections.css +0 -82
  196. data/frameworks/sproutcore/english.lproj/images/buttons-sprite.png +0 -0
  197. data/frameworks/sproutcore/views/collection/collection_item.js +0 -36
  198. data/frameworks/sproutcore/views/collection/text_cell.js +0 -128
  199. data/frameworks/sproutcore/views/field.js +0 -214
  200. data/frameworks/sproutcore/views/workspace.js +0 -170
  201. data/generators/client/templates/english.lproj/controls.css +0 -0
  202. data/generators/framework/templates/english.lproj/body.css +0 -0
  203. data/generators/framework/templates/english.lproj/body.rhtml +0 -3
  204. data/generators/framework/templates/english.lproj/controls.css +0 -0
  205. data/lib/sproutcore/view_helpers/button_views.rb +0 -302
  206. data/lib/sproutcore/view_helpers/core_views.rb +0 -292
  207. data/lib/sproutcore/view_helpers/form_views.rb +0 -258
  208. data/lib/sproutcore/view_helpers/menu_views.rb +0 -94
@@ -2,8 +2,8 @@
2
2
  // SC.GridView
3
3
  // ==========================================================================
4
4
 
5
- require('views/collection') ;
6
- require('views/collection/text_cell');
5
+ require('views/collection/collection') ;
6
+ require('views/label');
7
7
 
8
8
  /** @class
9
9
 
@@ -37,76 +37,150 @@ SC.GridView = SC.CollectionView.extend(
37
37
 
38
38
  You can override this as you wish.
39
39
  */
40
- exampleView: SC.TextCellView,
40
+ exampleView: SC.LabelView,
41
41
 
42
42
  insertionOrientation: SC.HORIZONTAL_ORIENTATION,
43
+
44
+ // computed function for keyboard handling.
45
+ itemsPerRow: function() {
46
+ var ret = this._computeItemsPerRow() ;
47
+ console.log('ret = %@'.fmt(ret)) ;
48
+ return ret ;
49
+ }.property(),
50
+
51
+ /**
52
+ Calculates the number of items per row.
53
+ */
54
+ _computeItemsPerRow: function() {
55
+ var f = this.get('innerFrame') ;
56
+ var columnWidth = this.get('columnWidth') || 0 ;
57
+ return (columnWidth <= 0) ? 1 : Math.floor(f.width / columnWidth) ;
58
+ },
59
+
60
+ /** @private
61
+ Find the contentRange to display in the passed frame. Note that we
62
+ ignore the width of the frame passed since we need to have a single
63
+ contiguous range.
64
+ */
65
+ contentRangeInFrame: function(frame) {
66
+ var rowHeight = this.get('rowHeight') || 48 ;
67
+ var itemsPerRow = this._computeItemsPerRow() ;
68
+
69
+ var min = Math.floor(SC.minY(frame) / rowHeight) * itemsPerRow ;
70
+ var max = Math.ceil(SC.maxY(frame) / rowHeight) * itemsPerRow ;
71
+ var ret = { start: min, length: max - min } ;
72
+ //console.log('contentRangeInFrame(%@) = %@'.fmt($H(frame).inspect(), $H(ret).inspect()));
73
+ //if (frame.height < 100) debugger ;
74
+ return ret ;
75
+ },
76
+
77
+ layoutItemView: function(itemView, contentIndex, firstLayout) {
78
+ if (!itemView) debugger ;
79
+ SC.Benchmark.start('SC.GridView.layoutItemViewsFor') ;
80
+
81
+ var rowHeight = this.get('rowHeight') || 0 ;
82
+ var parentView = itemView.get('parentView') ;
83
+ var frameWidth = this.get('innerFrame').width ;
84
+ var itemsPerRow = this._computeItemsPerRow() ;
85
+ var columnWidth = Math.floor(frameWidth/itemsPerRow);
86
+
87
+ var row = Math.floor(contentIndex / itemsPerRow) ;
88
+ var col = contentIndex - (itemsPerRow*row) ;
89
+ var f = {
90
+ x: col * columnWidth, y: row * rowHeight,
91
+ height: rowHeight, width: columnWidth
92
+ };
93
+
94
+ if (firstLayout || !SC.rectsEqual(itemView.get('frame'), f)) {
95
+ itemView.set('frame', f) ;
96
+ }
97
+ SC.Benchmark.end('SC.GridView.layoutItemViewsFor') ;
98
+ },
99
+
100
+ computeFrame: function() {
101
+ var content = this.get('content') ;
102
+ var rows = (content) ? content.get('length') : 0 ;
103
+ var rowHeight = this.get('rowHeight') || 20 ;
104
+
105
+ var parent = this.get('parentNode') ;
106
+ var f = (parent) ? parent.get('innerFrame') : { width: 100, height: 100 } ;
107
+
108
+ f.x = f.y = 0;
109
+ f.height = Math.max(f.height, rows * rowHeight) ;
110
+ // console.log('computeFrame(%@)'.fmt($H(f).inspect())) ;
111
+ return f ;
112
+ },
43
113
 
114
+
44
115
  /** @private */
45
- layoutChildViewsFor: function(parentView, startingView) {
116
+ layoutItemViewsFor: function(parentView, startingView) {
117
+ SC.Benchmark.start('SC.GridView.layoutItemViewsFor') ;
118
+
46
119
  var rowHeight = this.get('rowHeight') ;
47
120
  var columnWidth = this.get('columnWidth') ;
48
121
  if ((rowHeight == null) || (columnWidth == null)) return false ;
49
122
 
50
123
  // set items per row.
51
124
  parentView = parentView || this ;
52
- var f = parentView.get('frame') ;
125
+ var f = parentView.get('innerFrame') ;
53
126
  f.x= f.y = 0 ;
54
127
  var itemsPerRow = Math.floor(f.width / (columnWidth || 1)) ;
55
128
  if (this.get('itemsPerRow') != itemsPerRow) this.set('itemsPerRow', itemsPerRow);
56
129
 
57
130
  // fix width to evenly match items per row
58
- columnWidth = Math.floor(f.width/itemsPerRow) ;
131
+ columnWidth = Math.floor((f.width-20)/itemsPerRow) ;
59
132
 
60
- // get the startingView and the starting X,Y
61
- if (!startingView) startingView = parentView.firstChild ;
62
- var x,y ;
63
- if (startingView && startingView.previousSibling) {
64
- var prevFrame = startingView.previousSibling.get('frame') ;
65
- x = SC.maxX(prevFrame); y = SC.minY(prevFrame) ;
66
- } else { x = f.x; y = f.y; }
133
+ // get the startingView and the starting row, col
134
+ var view = startingView || parentView.firstChild;
135
+ var content = this.get('content') || [] ;
136
+ var idx = (view) ? content.indexOf(view.get('content')) : 0;
137
+
67
138
 
68
- // Now setup the default frame
69
- var maxX = SC.maxX(f);
70
- var minX = f.x;
71
139
  f = { x: 0, y: 0, height: rowHeight, width: columnWidth } ;
72
- var view = startingView ;
140
+
73
141
  while(view) {
74
- // loop back to beginning of next line if needed.
75
- if (x >= maxX) {
76
- x = minX ;
77
- y += rowHeight ;
78
- }
79
-
80
- // save frame
81
- view.set('isPositioned', true) ;
82
- f.y = y ; f.x = x;
142
+
143
+ // calculate position.
144
+ var row = Math.floor(idx / itemsPerRow) ;
145
+ var col = idx - (row * itemsPerRow) ;
146
+ f.x = col * columnWidth; f.y = row * rowHeight ;
147
+
83
148
  if (!SC.rectsEqual(view.get('frame'), f)) view.set('frame', f) ;
84
- x += columnWidth;
149
+
150
+ // go to next one
85
151
  view = view.nextSibling ;
152
+ idx++ ;
86
153
  }
154
+
155
+ SC.Benchmark.end('SC.GridView.layoutItemViewsFor') ;
156
+
87
157
  return true;
88
158
  },
89
159
 
90
- // computedViewHeight: function(groupView) {
91
- // var content = this.get('content') ;
92
- // var rowHeight = this.get('rowHeight') ;
93
- // var parentNode = this.get('parentNode') ;
94
- // var minHeight = (parentNode) ? 20 : parentNode.get('frame').height ;
95
- // var height = 0 ;
96
- //
97
- // if (content && rowHeight) {
98
- // var rows = content.get('length') ;
99
- // height = rows * rowHeight ;
100
- // }
101
- // if (height < minHeight) height = minHeight ;
102
- // return height ;
103
- // },
160
+ computeFrame: function() {
161
+ var content = this.get('content') ;
162
+ var count = (content) ? content.get('length') : 0 ;
163
+ var rowHeight = this.get('rowHeight') || 0 ;
164
+ var columnWidth = this.get('columnWidth') || 0 ;
165
+
166
+ var parent = this.get('parentNode') ;
167
+ var f = (parent) ? parent.get('innerFrame') : { width: 0, height: 0 };
168
+ var itemsPerRow = (columnWidth <= 0) ? 1 : (f.width / columnWidth) ;
169
+ var rows = Math.ceil(count / itemsPerRow) ;
170
+
171
+ f.x = f.y = 0;
172
+ f.height = Math.max(f.height, rows * rowHeight) ;
173
+
174
+ return f ;
175
+ },
176
+
104
177
 
105
178
  insertionPointClass: SC.View.extend({
106
179
  emptyElement: '<div class="grid-insertion-point"><span class="anchor"></span></div>'
107
180
  }),
108
181
 
109
182
  showInsertionPointBefore: function(itemView) {
183
+
110
184
  if (!itemView) return ;
111
185
 
112
186
  if (!this._insertionPointView) {
@@ -120,6 +194,7 @@ SC.GridView = SC.CollectionView.extend(
120
194
  y: itemViewFrame.y + 6,
121
195
  width: 0
122
196
  };
197
+
123
198
  if (!SC.rectsEqual(insertionPoint.get('frame'), f)) {
124
199
  insertionPoint.set('frame', f) ;
125
200
  }
@@ -137,13 +212,16 @@ SC.GridView = SC.CollectionView.extend(
137
212
  // // We can do this much faster programatically using the rowHeight
138
213
  insertionIndexForLocation: function(loc) {
139
214
  var f = this.get('frame') ;
140
- loc = this.convertFrameFromView(loc, null) ;
215
+ var sf = this.get('scrollFrame') ;
141
216
 
142
- var itemsPerRow = this.get('itemsPerRow') || 1 ;
217
+ var itemsPerRow = this._computeItemsPerRow();
143
218
  var columnWidth = Math.floor(f.width / itemsPerRow) ;
144
- var row = Math.floor((loc.y - f.y) / this.get('rowHeight') + 0.5) ;
145
- var col = Math.floor((loc.x - f.x) / columnWidth + 0.5) ;
146
- return (row*itemsPerRow) + col ;
219
+ var row = Math.floor((loc.y - f.y - sf.y) / this.get('rowHeight')) ;
220
+ var col = Math.floor(((loc.x - f.x - sf.x) / columnWidth) + 0.5) ;
221
+
222
+ var ret= (row*itemsPerRow) + col ;
223
+ //console.log("insertionIndexForLocation = %@".fmt(ret)) ;
224
+ return ret ;
147
225
  }
148
226
 
149
227
  }) ;
@@ -1,8 +1,9 @@
1
1
  // ==========================================================================
2
- // SC.TextCellView
2
+ // SC.LabelView
3
3
  // ==========================================================================
4
4
 
5
- require('views/collection/collection_item') ;
5
+ require('mixins/control') ;
6
+ require('views/image') ;
6
7
 
7
8
  /** @class
8
9
 
@@ -14,15 +15,15 @@ require('views/collection/collection_item') ;
14
15
  @author AuthorName
15
16
  @version 0.1
16
17
  */
17
- SC.ImageCellView = SC.View.extend(SC.CollectionItem,
18
+ SC.ImageCellView = SC.View.extend(SC.Control,
18
19
  /** @scope SC.ImageCellView.prototype */ {
19
20
 
20
- emptyElement: '<div class="image-cell collection-item"><img src="%@" style="position:relative;" /></div>'.fmt(static_url('blank')),
21
+ emptyElement: '<div class="image-cell sc-collection-item"><img src="%@" style="position:relative;" /></div>'.fmt(static_url('blank')),
21
22
 
22
23
  /**
23
- The content object this image item view will display.
24
+ The image URL you wish to display.
24
25
  */
25
- content: null,
26
+ value: null,
26
27
 
27
28
  /**
28
29
  The owner view of this cell. The ImageCell relies on this
@@ -40,7 +41,7 @@ SC.ImageCellView = SC.View.extend(SC.CollectionItem,
40
41
  */
41
42
  formatter: null,
42
43
 
43
- displayProperty: null,
44
+ contentValueKey: null,
44
45
 
45
46
  /**
46
47
  This is the required margin you want to appear around the image. Expressed in px
@@ -58,6 +59,8 @@ SC.ImageCellView = SC.View.extend(SC.CollectionItem,
58
59
  // parent. Automatically triggered when load status changes and
59
60
  // also by owner whenever it is resized.
60
61
  sizeToFit: function() {
62
+
63
+ if (this.get('status') != 'loaded') return ;
61
64
 
62
65
  // find the best fit.
63
66
  var f= this.owner.get('frame') ;
@@ -90,65 +93,33 @@ SC.ImageCellView = SC.View.extend(SC.CollectionItem,
90
93
  }
91
94
  },
92
95
 
93
- // invoked whenever the content object changes.
94
- _contentObserver: function() {
95
- var content = this.get('content') ;
96
- if (this._content == content) return ;
97
- var f = this._boundValueDidChange() ;
98
-
99
- // stop observing the old display property, if there is one.
100
- if (this._content && this._displayProperty) {
101
- this._content.removeObserver(this._displayProperty, f) ;
102
- }
103
-
104
- // start observing the new display property, if there is one
105
- this._displayProperty = this._getDefault('displayProperty') ;
106
- this._content = content ;
107
- if (this._content && this._displayProperty) {
108
- this._content.addObserver(this._displayProperty, f) ;
109
- }
110
-
111
- // notify value did change
112
- this._valueDidChange() ;
113
- }.observes('content'),
114
-
115
96
  /**
116
97
  @private
117
98
 
118
99
  Invoked whenever the monitored value on the content object
119
100
  changes.
120
101
 
121
- The value processed is either the displayProperty, if set, or
102
+ The value processed is either the contentValueKey, if set, or
122
103
  it is the content object itself.
123
104
  */
124
105
  _valueDidChange: function() {
125
- var content = this.get('content') ;
126
- var value = (content && this._displayProperty) ? content.get(this._displayProperty) : content;
106
+ var value = this.get('value') ;
127
107
  var owner = this.get('owner') ;
128
108
 
129
109
  // prepare the value...
130
110
 
131
111
  // 1. apply the formatter
132
- var formatter = this._getDefault('formatter') ;
112
+ var formatter = this.getDelegateProperty(this.displayDelegate, 'formatter') ;
133
113
  if (formatter) {
134
114
  var formattedValue = ($type(formatter) == T_FUNCTION) ? formatter(value, this) : formatter.fieldValueForObject(value, this) ;
135
115
  if (formattedValue != null) value = formattedValue ;
136
116
  }
137
117
 
138
118
  // 2. If the returned value is not a string, convert it.
139
- if (($type(value) != T_NULL) && value.toString) value = value.toString() ;
119
+ if (value != null && value.toString) value = value.toString() ;
140
120
 
141
121
  // 3. Apply URL to image view.
142
- this.outlet('imageView').set('content', value) ;
143
- },
144
-
145
- _boundValueDidChange: function() {
146
- return this._boundValueDidChange = this._boundValueDidChange || this._valueDidChange.bind(this);
147
- },
148
-
149
- // Retrieves the default value from the owner or locally.
150
- _getDefault: function(keyName) {
151
- var ret = (this.owner) ? this.owner.get(keyName) : null ;
152
- return (ret != null) ? ret : this.get(keyName) ;
153
- }
122
+ this.outlet('imageView').set('value', value) ;
123
+ }.observes('value')
124
+
154
125
  }) ;
@@ -2,8 +2,8 @@
2
2
  // SC.ListView
3
3
  // ==========================================================================
4
4
 
5
- require('views/collection') ;
6
- require('views/collection/text_cell');
5
+ require('views/collection/collection') ;
6
+ require('views/label');
7
7
 
8
8
  /** @class
9
9
 
@@ -40,44 +40,54 @@ SC.ListView = SC.CollectionView.extend(
40
40
 
41
41
  You can override this as you wish.
42
42
  */
43
- exampleView: SC.TextCellView,
43
+ exampleView: SC.ListItemView,
44
44
 
45
45
  insertionOrientation: SC.VERTICAL_ORIENTATION,
46
46
 
47
+ contentRangeInFrame: function(frame) {
48
+ var rowHeight = this.get('rowHeight') || 0 ;
49
+ var min = Math.max(0,Math.floor(SC.minY(frame) / rowHeight)-1) ;
50
+ var max = Math.ceil(SC.maxY(frame) / rowHeight) ;
51
+ var ret = { start: min, length: max - min } ;
52
+ // console.log('contentRangeInFrame(%@) = %@'.fmt($H(frame).inspect(), $H(ret).inspect()));
53
+ //if (frame.height < 100) debugger ;
54
+ return ret ;
55
+ },
56
+
47
57
  /** @private */
48
- layoutChildViewsFor: function(parentView, startingView) {
49
- var rowHeight = this.get('rowHeight') ;
50
- if (rowHeight == null) return false ;
58
+ layoutItemView: function(itemView, contentIndex, firstLayout) {
59
+ if (!itemView) debugger ;
60
+ SC.Benchmark.start('SC.ListView.layoutItemViewsFor') ;
61
+
62
+ var rowHeight = this.get('rowHeight') || 0 ;
63
+ var parentView = itemView.get('parentView') ;
64
+ var f = {
65
+ x: 0,
66
+ y: contentIndex*rowHeight,
67
+ height: rowHeight,
68
+ width: (parentView || this).get('innerFrame').width
69
+ } ;
51
70
 
52
- if (!startingView) startingView = parentView.firstChild ;
53
- var y = (startingView && startingView.previousSibling) ? SC.maxY(startingView.previousSibling.get('frame')) : 0;
54
- var f = (parentView || this).get('frame') ;
55
- f = { x: 0, height: rowHeight } ;
56
- var view = startingView || parentView.firstChild;
57
- while(view) {
58
- view.set('isPositioned', true) ;
59
- f.y = y ;
60
- if (!SC.rectsEqual(view.get('frame'), f)) view.set('frame', f) ;
61
- y += rowHeight;
62
- view = view.nextSibling ;
71
+ if (firstLayout || !SC.rectsEqual(itemView.get('frame'), f)) {
72
+ itemView.set('frame', f) ;
73
+ itemView.setStyle({ zIndex: contentIndex.toString() }) ;
63
74
  }
64
- return true;
75
+ SC.Benchmark.end('SC.ListView.layoutItemViewsFor') ;
65
76
  },
66
77
 
67
- // computedViewHeight: function(groupView) {
68
- // var content = this.get('content') ;
69
- // var rowHeight = this.get('rowHeight') ;
70
- // var parentNode = this.get('parentNode') ;
71
- // var minHeight = (parentNode) ? 20 : parentNode.get('frame').height ;
72
- // var height = 0 ;
73
- //
74
- // if (content && rowHeight) {
75
- // var rows = content.get('length') ;
76
- // height = rows * rowHeight ;
77
- // }
78
- // if (height < minHeight) height = minHeight ;
79
- // return height ;
80
- // },
78
+ computeFrame: function() {
79
+ var content = this.get('content') ;
80
+ var rows = (content) ? content.get('length') : 0 ;
81
+ var rowHeight = this.get('rowHeight') || 20 ;
82
+
83
+ var parent = this.get('parentNode') ;
84
+ var f = (parent) ? parent.get('innerFrame') : { width: 100, height: 100 } ;
85
+
86
+ f.x = f.y = 0;
87
+ f.height = Math.max(f.height, rows * rowHeight) ;
88
+ // console.log('computeFrame(%@)'.fmt($H(f).inspect())) ;
89
+ return f ;
90
+ },
81
91
 
82
92
  insertionPointClass: SC.View.extend({
83
93
  emptyElement: '<div class="list-insertion-point"><span class="anchor"></span></div>'
@@ -106,9 +116,9 @@ SC.ListView = SC.CollectionView.extend(
106
116
 
107
117
  // We can do this much faster programatically using the rowHeight
108
118
  insertionIndexForLocation: function(loc) {
109
- var f = this.get('frame') ;
110
- loc = this.convertFrameFromView(loc, null) ;
111
- var ret = Math.floor((loc.y - f.y) / this.get('rowHeight') + 0.5) ;
119
+ var f = this.get('innerFrame') ;
120
+ var sf = this.get('scrollFrame') ;
121
+ var ret = Math.floor(((loc.y - f.y - sf.y) / this.get('rowHeight')) + 0.4) ;
112
122
  return ret ;
113
123
  }
114
124