Changeset 481:431c98311af8
- Timestamp:
- 01/14/10 19:10:11 (8 months ago)
- Author:
- Nick Stenning <nick@…>
- Branch:
- default
- Message:
-
Half-fixed factlet edit view
- Location:
- microfacts
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r449
|
r481
|
|
| 165 | 165 | if factlet: |
| 166 | 166 | c.factlet = factlet |
| 167 | | html = render('factlet/edit_core.html') |
| 168 | | return html |
| | 167 | return render('factlet/edit_core.html') |
| 169 | 168 | |
| 170 | 169 | mode = EntityGet('/factlet/%s' % id).execute() |
| 171 | 170 | if mode.response_code == 200: |
| 172 | 171 | c.factlet = mode.entity |
| 173 | | edit_form_html = render('factlet/edit_core.html') |
| 174 | | return edit_form_html |
| | 172 | return render('factlet/edit_core.html') |
| 175 | 173 | else: |
| 176 | 174 | abort(mode.response_code) |
| … |
… |
|
| 179 | 177 | ispreview = request.params.has_key('preview') |
| 180 | 178 | iscommit = request.params.has_key('commit') |
| 181 | | if not (ispreview or iscommit): |
| 182 | | edit_form_html = self.edit_core(id) |
| 183 | | c.edit_form = genshi.HTML(edit_form_html) |
| | 179 | |
| | 180 | c.edit_core = self.edit_core(id) |
| | 181 | |
| | 182 | if not (iscommit or ispreview): |
| 184 | 183 | return render('factlet/edit.html') |
| 185 | | # so must be preview or commit ... |
| | 184 | |
| | 185 | |
| | 186 | # works in place |
| | 187 | self.unflatten_form_data(request.params) |
| 186 | 188 | entity_data = dict(request.params) |
| 187 | | # works in place |
| 188 | | self.unflatten_form_data(entity_data) |
| | 189 | |
| 189 | 190 | if ispreview: |
| 190 | | return self._preview(entity_data) |
| | 191 | self._preview(entity_data) |
| | 192 | return render('factlet/edit.html') |
| | 193 | |
| 191 | 194 | elif iscommit: |
| 192 | 195 | mode = EntityPut('/factlet/%s' % id, |
| … |
… |
|
| 207 | 210 | json_data = entity_data |
| 208 | 211 | c.factlet = self._parse_json_data(json_data) |
| 209 | | c.factlet_html = genshi.HTML(render('factlet/read_core.html')) |
| 210 | | c.factlet = self._parse_json_data(json_data) |
| 211 | | c.edit_form = genshi.HTML(render('factlet/edit_core.html')) |
| 212 | | return render('factlet/edit.html') |
| | 212 | c.factlet_html = render('factlet/read_core.html') |
| 213 | 213 | |
| 214 | 214 | def unflatten_form_data(self, formdict): |
| 215 | 215 | # convert back to json string format (not actual domain object) |
| 216 | | # name convention follows formencode |
| 217 | | x = formdict.get('location__x', None) |
| 218 | | y = formdict.get('location__y', None) |
| 219 | | try: x = float(x) |
| 220 | | except: x = None |
| 221 | | try: y = float(y) |
| 222 | | except: y = None |
| 223 | | if x or y: |
| 224 | | formdict['location'] = {'type': 'Point', 'coordinates': [x, y] } |
| | 216 | coords = formdict.getall('location[geometry][coordinates][]') |
| | 217 | |
| | 218 | try: |
| | 219 | coords[0] = float(coords[0]) if coords[0] else None |
| | 220 | coords[1] = float(coords[1]) if coords[1] else None |
| | 221 | f = geojson.Feature() |
| | 222 | f.geometry = geojson.Point(coordinates=coords) |
| | 223 | print f |
| | 224 | formdict['location'] = f |
| | 225 | except: |
| | 226 | pass |
| | 227 | |
| 225 | 228 | |
| 226 | 229 | def template(self, id): |
-
|
r475
|
r481
|
|
| 5 | 5 | this.parent(el); |
| 6 | 6 | |
| 7 | | // Disable as causes serious UI breakage when pane larger than page |
| 8 | | // new AutoScroller(this.element).scrollIntoView(); |
| | 7 | // If we're not a subcontroller, set up our own resources. |
| | 8 | if (!this.owner) { |
| | 9 | this.factlet = Factlet.find(this.element.getElement('.factlet').mfId()); |
| | 10 | this.factlet.attach(this.element); |
| | 11 | } |
| 9 | 12 | |
| 10 | 13 | this.modalMap = new Modal(this.element.getElement('.factlet-location-editor'), { |
| … |
… |
|
| 14 | 17 | onHide: this.modalMapDidHide.bind(this) |
| 15 | 18 | }); |
| | 19 | |
| | 20 | this.element.getElement('.geometry').grab(new Element('dd', { |
| | 21 | 'class': 'notes', |
| | 22 | 'html': '<a href="#" class="locationSelectActivate">Select location on map</a>.' |
| | 23 | })); |
| 16 | 24 | }, |
| 17 | 25 | |
| … |
… |
|
| 39 | 47 | factletSaved: function (factlet) { |
| 40 | 48 | factlet.removeEvent("resourceChange", this.saveCallback); |
| 41 | | this.owner.fireEvent('factletSelect', factlet); |
| 42 | | this.owner.fireEvent('factletListUpdated', factlet); |
| | 49 | if (this.owner) { |
| | 50 | this.owner.fireEvent('factletSelect', factlet); |
| | 51 | this.owner.fireEvent('factletListUpdated', factlet); |
| | 52 | } |
| 43 | 53 | }, |
| 44 | 54 | |
| … |
… |
|
| 61 | 71 | controls: { |
| 62 | 72 | 'form submit': function (e) { |
| 63 | | e.stop(); |
| 64 | | this.updateFactlet(e.target.form.toObject()); |
| | 73 | if (this.owner) { |
| | 74 | e.stop(); |
| | 75 | this.updateFactlet(e.target.form.toObject()); |
| | 76 | } |
| 65 | 77 | }, |
| 66 | 78 | 'a.locationSelectActivate click': function (e) { |
| … |
… |
|
| 91 | 103 | } |
| 92 | 104 | }); |
| | 105 | |
| | 106 | // Only set up a FactletEditController if there's no thread in the page, as |
| | 107 | // threads will set up their own subcontrollers. |
| | 108 | if (MF.environment != "test" && !$(document).getElement('.thread')) { |
| | 109 | window.addEvent('domready', function () { |
| | 110 | new FactletEditController($(document).getElement('.factlet-edit')); |
| | 111 | }); |
| | 112 | } |
-
|
r471
|
r481
|
|
| 64 | 64 | { name: "app/controllers/factlet_search_controller" }, |
| 65 | 65 | { name: "app/controllers/factlet_edit_controller", |
| 66 | | requires: ["lib/elementfill", "lib/autoscroller"] |
| | 66 | requires: ["lib/elementfill", |
| | 67 | "lib/autoscroller", |
| | 68 | "app/models/factlet", |
| | 69 | "app/controllers/map_controller"] |
| 67 | 70 | }, |
| 68 | 71 | { name: "app/controllers/factlet_create_controller" }, |
-
|
r414
|
r481
|
|
| 20 | 20 | </p> |
| 21 | 21 | |
| 22 | | ${c.edit_form} |
| | 22 | <div class="factlet-edit"> |
| | 23 | ${c.edit_core} |
| | 24 | ${factlet_location_editor()} |
| | 25 | </div> |
| 23 | 26 | |
| 24 | 27 | <py:if test="c.factlet_html"> |
| … |
… |
|
| 30 | 33 | </div> |
| 31 | 34 | </py:if> |
| | 35 | |
| | 36 | <script type="text/javascript"> |
| | 37 | MF.loader.load( ['app/controllers/factlet_edit_controller'] ); |
| | 38 | </script> |
| 32 | 39 | </body> |
| 33 | 40 | </html> |
-
|
r475
|
r481
|
|
| 54 | 54 | class_='coordinate', id="coord-y")} |
| 55 | 55 | </dd> |
| 56 | | <dd class="notes"> |
| 57 | | <a href="#" class="locationSelectActivate">Select location on map</a>. |
| 58 | | </dd> |
| 59 | 56 | </dl> |
| 60 | | |
| 61 | 57 | |
| 62 | 58 | </div> |
-
|
r451
|
r481
|
|
| 50 | 50 | <div class="factlet-edit"> |
| 51 | 51 | ${c.edit_core} |
| 52 | | |
| 53 | | <div class="factlet-location-editor modal" style="visibility:hidden;opacity:0"> |
| 54 | | <div class="modal-content"> |
| 55 | | <h3>Select a point.</h3> |
| 56 | | <div class="map"> |
| 57 | | <p class="buttons"> |
| 58 | | <a href="#" class="done"><img alt='' src='/images/icons/accept.png' />Done</a> |
| 59 | | <a href="#" class="cancel"><img alt='' src='/images/icons/cancel.png' />Cancel</a> |
| 60 | | </p> |
| 61 | | </div> |
| 62 | | </div> |
| 63 | | </div> |
| | 52 | ${factlet_location_editor()} |
| 64 | 53 | </div> |
| 65 | 54 | |
-
|
r475
|
r481
|
|
| 51 | 51 | <script type="text/javascript" src="http://openlayers.org/api/2.8/OpenLayers.js"></script> |
| 52 | 52 | </py:def> |
| | 53 | |
| | 54 | <div py:def="factlet_location_editor" class="factlet-location-editor modal" style="visibility:hidden;opacity:0" > |
| | 55 | <div class="modal-content"> |
| | 56 | <h3>Select a point.</h3> |
| | 57 | <div class="map"> |
| | 58 | <p class="buttons"> |
| | 59 | <a href="#" class="done"><img alt='' src='/images/icons/accept.png' />Done</a> |
| | 60 | <a href="#" class="cancel"><img alt='' src='/images/icons/cancel.png' />Cancel</a> |
| | 61 | </p> |
| | 62 | </div> |
| | 63 | </div> |
| | 64 | </div> |
| 53 | 65 | </html> |
| 54 | 66 | |