Changeset 481:431c98311af8

Show
Ignore:
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:
7 modified

Legend:

Unmodified
Added
Removed
  • microfacts/controllers/factlet.py

    r449 r481  
    165165        if factlet: 
    166166            c.factlet = factlet 
    167             html = render('factlet/edit_core.html') 
    168             return html 
     167            return render('factlet/edit_core.html') 
    169168             
    170169        mode = EntityGet('/factlet/%s' % id).execute() 
    171170        if mode.response_code == 200: 
    172171            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') 
    175173        else: 
    176174            abort(mode.response_code) 
     
    179177        ispreview = request.params.has_key('preview') 
    180178        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): 
    184183            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) 
    186188        entity_data = dict(request.params) 
    187         # works in place 
    188         self.unflatten_form_data(entity_data) 
     189         
    189190        if ispreview: 
    190             return self._preview(entity_data) 
     191            self._preview(entity_data) 
     192            return render('factlet/edit.html') 
     193             
    191194        elif iscommit: 
    192195            mode = EntityPut('/factlet/%s' % id, 
     
    207210        json_data = entity_data 
    208211        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') 
    213213 
    214214    def unflatten_form_data(self, formdict): 
    215215        # 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         
    225228 
    226229    def template(self, id): 
  • microfacts/public/behaviour/app/controllers/factlet_edit_controller.js

    r475 r481  
    55        this.parent(el); 
    66         
    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        } 
    912 
    1013        this.modalMap = new Modal(this.element.getElement('.factlet-location-editor'), { 
     
    1417            onHide: this.modalMapDidHide.bind(this) 
    1518        }); 
     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        })); 
    1624    }, 
    1725         
     
    3947    factletSaved: function (factlet) { 
    4048        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        } 
    4353    }, 
    4454 
     
    6171    controls: { 
    6272        '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            } 
    6577        }, 
    6678        'a.locationSelectActivate click': function (e) { 
     
    91103    } 
    92104}); 
     105 
     106// Only set up a FactletEditController if there's no thread in the page, as 
     107// threads will set up their own subcontrollers. 
     108if (MF.environment != "test" && !$(document).getElement('.thread')) { 
     109    window.addEvent('domready', function () { 
     110        new FactletEditController($(document).getElement('.factlet-edit')); 
     111    }); 
     112} 
  • microfacts/public/behaviour/load.js

    r471 r481  
    6464        { name: "app/controllers/factlet_search_controller" }, 
    6565        { 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"] 
    6770        }, 
    6871        { name: "app/controllers/factlet_create_controller" }, 
  • microfacts/templates/factlet/edit.html

    r414 r481  
    2020    </p> 
    2121 
    22     ${c.edit_form} 
     22    <div class="factlet-edit"> 
     23      ${c.edit_core} 
     24      ${factlet_location_editor()} 
     25    </div> 
    2326 
    2427    <py:if test="c.factlet_html"> 
     
    3033      </div> 
    3134    </py:if> 
     35     
     36    <script type="text/javascript"> 
     37      MF.loader.load( ['app/controllers/factlet_edit_controller'] ); 
     38    </script> 
    3239  </body> 
    3340</html> 
  • microfacts/templates/factlet/edit_core.html

    r475 r481  
    5454                     class_='coordinate', id="coord-y")} 
    5555          </dd> 
    56           <dd class="notes"> 
    57             <a href="#" class="locationSelectActivate">Select location on map</a>. 
    58           </dd> 
    5956        </dl> 
    60  
    6157 
    6258      </div> 
  • microfacts/templates/thread/edit.html

    r451 r481  
    5050        <div class="factlet-edit"> 
    5151          ${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()} 
    6453        </div> 
    6554 
  • microfacts/templates/util.html

    r475 r481  
    5151    <script type="text/javascript" src="http://openlayers.org/api/2.8/OpenLayers.js"></script> 
    5252  </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> 
    5365</html> 
    5466