Changeset 173:4959bd27b191
- Timestamp:
- 08/27/08 17:08:34 (19 months ago)
- Author:
- rgrp
- Branch:
- default
- convert_revision:
- svn:10edda23-d834-0410-9182-b00384516d49/trunk@185
- Message:
-
[js][m]: refactor factletsearch_controller and threadfactlets_controller to be views.
- Create new BaseControlsView? class for them to inherit from copying over delegator stuff from Nick's existing Controller class.
- All tests seem to be passing.
- Location:
- microfacts/public
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r161
|
r173
|
|
| 7 | 7 | this.controllers = []; |
| 8 | 8 | element.getElements('.thread-factlets').each(function (el) { |
| 9 | | this.addController(new ThreadFactletsController(el)); |
| | 9 | this.addController(new ThreadFactletsView(el)); |
| 10 | 10 | }, this); |
| 11 | 11 | // should be only one |
| 12 | 12 | element.getElements('#factlet-search').each(function (el) { |
| 13 | | this.addController(new FactletSearchController(el)); |
| | 13 | this.addController(new FactletSearchView(el)); |
| 14 | 14 | }, this); |
| 15 | 15 | |
-
|
r171
|
r173
|
|
| 1 | | var FactletSearchController = new Class({ |
| 2 | | Extends: Controller, |
| | 1 | var FactletSearchView = new Class({ |
| | 2 | // Extends: Controller, |
| | 3 | Extends: BaseControlsView, |
| | 4 | name: 'FactletSearchView', |
| 3 | 5 | |
| 4 | | initialize: function () { |
| 5 | | this.parent.apply(this, arguments); |
| 6 | | console.log('FactletSearchController: initialize'); |
| | 6 | setupView: function () { |
| 7 | 7 | this.searchResults = $$('.factlet-search-results')[0]; |
| 8 | 8 | // list of factlet ids currently being shown |
| … |
… |
|
| 11 | 11 | }, |
| 12 | 12 | |
| 13 | | onFactletSelect: function (factlet) { |
| 14 | | }, |
| 15 | | |
| | 13 | // in parent now |
| 16 | 14 | // will be removed/promoted once controller setup is refactored |
| 17 | | onThreadStart: function (factlet) { |
| 18 | | }, |
| | 15 | // onThreadStart: function (factlet) { |
| | 16 | // }, |
| 19 | 17 | |
| 20 | 18 | onDataChange: function (data) { |
| … |
… |
|
| 68 | 66 | var data = $('factlet-search-title').value; |
| 69 | 67 | var query = { "q": data }; |
| | 68 | console.log('Had onclick event'); |
| 70 | 69 | request.post(url, encodeURIComponent(JSON.encode(query))); |
| 71 | 70 | }, |
-
|
r171
|
r173
|
|
| 1 | | var ThreadFactletsController = new Class({ |
| 2 | | Extends: Controller, |
| | 1 | var ThreadFactletsView = new Class({ |
| | 2 | Extends: BaseControlsView, |
| 3 | 3 | |
| 4 | 4 | factletSummaryTemplate: [ |
| … |
… |
|
| 8 | 8 | ].join('\n'), |
| 9 | 9 | |
| 10 | | initialize: function (element) { |
| 11 | | this.parent.apply(this, arguments); |
| | 10 | setupView: function () { |
| 12 | 11 | this.factlets = []; |
| 13 | 12 | this.selectedFactletId = null; |
| … |
… |
|
| 33 | 32 | }, |
| 34 | 33 | |
| | 34 | // TODO: refactor to use BaseView class onThreadStart |
| 35 | 35 | onThreadStart: function (thread, threadFactlets) { |
| 36 | 36 | console.log("ThreadFactletsController saw threadStart event"); |
-
|
r169
|
r173
|
|
| 38 | 38 | }, this); |
| 39 | 39 | var factletsData = []; |
| | 40 | // what is this doing in here? |
| | 41 | // why test for existence of location? May have date but not location |
| 40 | 42 | this.factlets.each(function (factletObject) { |
| 41 | 43 | if (factletObject.data.location) { |
| … |
… |
|
| 43 | 45 | } |
| 44 | 46 | }); |
| 45 | | this.log("Factlet data:"); |
| 46 | | this.log(factletsData); |
| | 47 | // this.log("Factlet data:"); |
| | 48 | // this.log(factletsData); |
| 47 | 49 | this.drawFactlets(factletsData); |
| 48 | 50 | }, |
| … |
… |
|
| 66 | 68 | } |
| 67 | 69 | |
| | 70 | }); |
| | 71 | |
| | 72 | var BaseControlsView = new Class({ |
| | 73 | Extends: BaseView, |
| | 74 | name: 'BaseControlsView', |
| | 75 | |
| | 76 | controls: {}, |
| | 77 | |
| | 78 | initialize: function (element, controls) { |
| | 79 | this.parent.apply(this, arguments); |
| | 80 | this.setControls(controls); |
| | 81 | this.delegateControls(); |
| | 82 | }, |
| | 83 | |
| | 84 | setupView: function () { |
| | 85 | }, |
| | 86 | |
| | 87 | setControls: function (controls) { |
| | 88 | this.controls = $merge(this.controls, controls); |
| | 89 | }, |
| | 90 | |
| | 91 | delegateControls: function () { |
| | 92 | $each(this.controls, function (fn, desc) { |
| | 93 | var desc = desc.trim().split(" "), type = desc.pop(), selector = desc.join(" "); |
| | 94 | this.element.delegate(selector, type, fn, this); |
| | 95 | }, this); |
| | 96 | } |
| 68 | 97 | }); |
| 69 | 98 | |
-
|
r171
|
r173
|
|
| 51 | 51 | type: "js", |
| 52 | 52 | path: "lib/moovc.js?" + Math.random(), |
| 53 | | requires: ['mootools'], |
| | 53 | requires: ['mootools', 'delegator'], |
| 54 | 54 | varName: "LayerBase" |
| 55 | 55 | }); |
| … |
… |
|
| 137 | 137 | |
| 138 | 138 | loader.addModule({ |
| | 139 | name: "threadfactletsview", |
| | 140 | type: "js", |
| | 141 | path: "app/views/threadfactletsview.js?" + Math.random(), |
| | 142 | requires: ['view', 'controller', 'thread', 'ejs'], |
| | 143 | varName: "ThreadFactletsView" |
| | 144 | }); |
| | 145 | |
| | 146 | loader.addModule({ |
| | 147 | name: "factletsearchview", |
| | 148 | type: "js", |
| | 149 | path: "app/views/factletsearchview.js?" + Math.random(), |
| | 150 | requires: ['view', 'controller', 'factlet'], |
| | 151 | varName: "FactletSearchView" |
| | 152 | }); |
| | 153 | |
| | 154 | loader.addModule({ |
| 139 | 155 | name: "mapview", |
| 140 | 156 | type: "js", |
| … |
… |
|
| 165 | 181 | |
| 166 | 182 | loader.addModule({ |
| 167 | | name: "threadfactletscontroller", |
| 168 | | type: "js", |
| 169 | | path: "app/controllers/threadfactlets_controller.js?" + Math.random(), |
| 170 | | requires: ['controller', 'thread', 'ejs'], |
| 171 | | varName: "ThreadFactletsController" |
| 172 | | }); |
| 173 | | |
| 174 | | loader.addModule({ |
| 175 | | name: "factletsearchcontroller", |
| 176 | | type: "js", |
| 177 | | path: "app/controllers/factletsearch_controller.js?" + Math.random(), |
| 178 | | requires: ['controller', 'factlet'], |
| 179 | | varName: "FactletSearchController" |
| 180 | | }); |
| 181 | | |
| 182 | | |
| 183 | | loader.addModule({ |
| 184 | 183 | name: "factletcontroller", |
| 185 | 184 | type: "js", |
| … |
… |
|
| 197 | 196 | type: "js", |
| 198 | 197 | path: "app/microfacts.js?" + Math.random(), |
| 199 | | requires: ['domainobject', 'view', 'controller', 'microfactscontroller', 'factletcontroller', 'threadfactletscontroller', 'mapview', 'timelineview', 'geochronopagecontroller', 'threadpagecontroller'], |
| | 198 | requires: ['domainobject', 'view', 'controller', 'microfactscontroller', 'factletcontroller', 'threadfactletsview', 'mapview', 'timelineview', 'geochronopagecontroller', 'threadpagecontroller'], |
| 200 | 199 | varName: "Microfacts" |
| 201 | 200 | }); |
| … |
… |
|
| 205 | 204 | type: "js", |
| 206 | 205 | path: "app/controllers/threadpage_controller.js?" + Math.random(), |
| 207 | | requires: ['model', 'domainobject', 'view', 'controller', 'thread', 'factlet', 'threadfactletscontroller', 'factletsearchcontroller'], |
| | 206 | requires: ['model', 'domainobject', 'view', 'controller', 'thread', 'factlet', 'threadfactletsview', 'factletsearchview'], |
| 208 | 207 | varName: "ThreadPageController" |
| 209 | 208 | }); |
-
|
r171
|
r173
|
|
| 56 | 56 | <!-- views --> |
| 57 | 57 | <script type="text/javascript" src="spec/view_spec.js?123"></script> |
| 58 | | <script type="text/javascript" src="spec/threadfactletscontroller_spec.js?123"></script> |
| 59 | | <script type="text/javascript" src="spec/factletsearch_controller_spec.js?123"></script> |
| | 58 | <script type="text/javascript" src="spec/threadfactletsview_spec.js?123"></script> |
| | 59 | <script type="text/javascript" src="spec/factletsearchview_spec.js?123"></script> |
| 60 | 60 | |
| 61 | 61 | <script type="text/javascript" src="spec/mapview_spec.js?123"></script> |
-
|
r171
|
r173
|
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | | describe('FactletSearchController', { |
| | 27 | describe('FactletSearchView', { |
| 28 | 28 | |
| 29 | 29 | before_each: function () { |
| 30 | 30 | var elem = $('factlet-search'); |
| 31 | | ctrl = new FactletSearchController(elem); |
| | 31 | ctrl = new FactletSearchView(elem); |
| 32 | 32 | }, |
| 33 | 33 | |
-
|
r171
|
r173
|
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | | describe('ThreadFactletsController', { |
| | 38 | describe('ThreadFactletsView', { |
| 39 | 39 | |
| 40 | 40 | before_each: function () { |
| 41 | 41 | var elem = $$('.thread-factlets')[0]; |
| 42 | | ctrl = new ThreadFactletsController(elem); |
| | 42 | ctrl = new ThreadFactletsView(elem); |
| 43 | 43 | }, |
| 44 | 44 | |