To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Changeset 2144

Show
Ignore:
Timestamp:
09/07/10 17:08:36 (17 months ago)
Author:
tboutell
Message:

Fixed #428 (you can no longer reorder in an area while it has an unsaved new slot) and greatly sped up the move arrows. They now work on the client side without waiting for the site to refresh the area.

Refactored the JavaScript? associated with the up and down arrows.

Fixed a previously unnoticed bug: a-new-slot wasn't getting cleared when a slot was saved.

TODO: strip down the response from the server to a yea or a nay.
TODO: actually do something about a nay (like refreshing the area).

Location:
plugins/apostrophePlugin/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/trunk/lib/action/BaseaSlotActions.class.php

    r2139 r2144  
    161161        // a newly saved slot with an edit view 
    162162        "variant" => $variant, 
     163        // Having the actual slot makes it possible to check if it's new and 
     164        // shut off a-new-slot 
     165        "slot" => $this->slot, 
    163166        "validationData" => $this->validationData)); 
    164167  } 
  • plugins/apostrophePlugin/trunk/modules/a/templates/_ajaxUpdateSlot.php

    r1964 r2144  
    99  $validationData = isset($validationData) ? $sf_data->getRaw('validationData') : null; 
    1010  $variant = isset($variant) ? $sf_data->getRaw('variant') : null; 
     11  $slot = isset($slot) ? $sf_data->getRaw('slot') : null; 
    1112?> 
    1213<?php // 1.3 and up don't do this automatically (no common filter) ?> 
     
    1819<?php use_helper('a') ?> 
    1920<?php a_slot_body($name, $type, $permid, $options, $validationData, $editorOpen, true) ?> 
     21<?php if (!$slot->isNew()): ?> 
     22  <?php a_js_call('apostrophe.slotNotNew(?, ?, ?)', $pageid, $name, $permid) ?> 
     23<?php endif ?> 
     24<?php a_js_call('apostrophe.areaUpdateMoveButtons(?, ?, ?)', url_for('a/moveSlot'), $pageid, $name) ?> 
    2025<?php a_include_js_calls() ?> 
    2126<?php if (isset($variant)): ?> 
  • plugins/apostrophePlugin/trunk/modules/a/templates/_area.php

    r2090 r2144  
    8686        <!-- START SLOT --> 
    8787        <div class="a-slot <?php echo $slot->getEffectiveVariant($slotOptions) ?> <?php echo $slot->type ?><?php echo ($slot->isNew())? ' a-new-slot':'' ?> clearfix" id="a-slot-<?php echo "$pageid-$name-$permid" ?>"> 
     88          <?php // Make the slot aware of its permid for simpler JS later ?> 
     89          <?php a_js_call('$(?).data(?, ?)', "#a-slot-$pageid-$name-$permid", 'a-permid', $permid) ?> 
    8890                <?php // Slot Controls ?> 
    8991    <?php if ($editable): ?> 
    9092                <ul class="a-ui a-controls a-slot-controls clearfix">            
    9193      <?php if ($infinite): ?> 
    92           <?php if ($i > 0): ?> 
    93                                                 <li> 
    94             <?php echo jq_link_to_remote('<span class="icon"></span>'.__('Move', null, 'apostrophe'), array( 
    95                 "url" => "a/moveSlot?" .http_build_query(array( 
    96                                                                         "id" => $page->id, 
    97                                                                         "name" => $name, 
    98                                                                         "up" => 1, 
    99                                                                         "permid" => $permid)), 
    100                                                                         "update" => "a-slots-$pageid-$name", 
    101                                                                         'complete' => 'aUI()'),  
    102                                                                         array( 
    103                                                                                 'class' => 'a-btn icon a-arrow-up no-label',  
    104                                                                                 'title' => __('Move Up', null, 'apostrophe'),  
    105                                                 )) ?> 
    106                                                 </li> 
    107           <?php endif ?> 
    108           <?php if (($i + 1) < count($slots)): ?> 
    109                                                 <li> 
    110             <?php echo jq_link_to_remote('<span class="icon"></span>'.__('Move', null, 'apostrophe'), array( 
    111                 "url" => "a/moveSlot?" .http_build_query(array( 
    112                                                                         "id" => $page->id, 
    113                                                                         "name" => $name, 
    114                                                                         "permid" => $permid)), 
    115                                                                         "update" => "a-slots-$pageid-$name", 
    116                                                                         'complete' => 'aUI()'),  
    117                                                                         array( 
    118                                                                                 'class' => 'a-btn icon a-arrow-down no-label',  
    119                                                                                 'title' => __('Move Down', null, 'apostrophe'),  
    120                                                 )) ?> 
    121             </li> 
    122         <?php endif ?> 
     94                                <li class="a-move"> 
     95                                  <a href="#" class="a-btn icon a-arrow-up no-label" title="<?php echo a_('Move Up') ?>"><span class="icon"></span><?php echo a_('Move Up') ?></a> 
     96                                </li> 
     97                                <li class="a-move"> 
     98                                  <a href="#" class="a-btn icon a-arrow-down no-label" title="<?php echo a_('Move Down') ?>"><span class="icon"></span><?php echo a_('Move Down') ?></a> 
     99                                </li> 
    123100      <?php endif ?> 
    124101 
     
    201178        }); 
    202179</script> 
     180<?php a_js_call('apostrophe.areaUpdateMoveButtons(?, ?, ?)', url_for('a/moveSlot'), $pageid, $name) ?> 
    203181<?php endif ?> 
  • plugins/apostrophePlugin/trunk/web/js/a.js

    r2142 r2144  
    2626  } 
    2727 
     28        // Swap two DOM elements without cloning them 
     29        // http://blog.pengoworks.com/index.cfm/2008/9/24/A-quick-and-dirty-swap-method-for-jQuery 
     30        this.swapNodes = function(a, b) { 
     31    var t = a.parentNode.insertBefore(document.createTextNode(''), a);  
     32    b.parentNode.insertBefore(a, b);  
     33    t.parentNode.insertBefore(b, t);  
     34    t.parentNode.removeChild(t); 
     35        }        
     36         
    2837        this.jsTree = function(options) 
    2938        { 
     
    8897          }); 
    8998        } 
     99 
    90100 
    91101        this.slideshow = function(options) 
     
    463473                aUI(editBtn.parents('.a-slot').attr('id')); // Refresh the UI scoped to this Slot 
    464474        } 
     475         
     476        this.areaUpdateMoveButtons = function(updateAction, id, name) 
     477        { 
     478                var area = $('#a-area-' + id + '-' + name); 
     479                // Be precise - take care not to hoover up controls related to slots in nested areas, if there are any 
     480                var slots = area.children('.a-slots').children('.a-slot'); 
     481                var newSlots = area.children('.a-slots').children('.a-new-slot'); 
     482                if (newSlots.length) 
     483                { 
     484                        // TODO: this is not sensitive enough to nested areas 
     485                         
     486                        // You have to save a new slot before you can do any reordering. 
     487                        // TODO: with a little more finesse we could support saving it with 
     488                        // a rank, but think about how messy that might get 
     489                  slots.find('.a-arrow-up,.a-arrow-down').hide(); 
     490                        return; 
     491                } 
     492                // I actually want a visible loop variable here 
     493                for (n = 0; (n < slots.length); n++) 
     494                { 
     495                        var slot = slots[n]; 
     496                        // We use a nested function here because  
     497                        // a loop variable does *not* get captured 
     498                        // in the closure at its current value otherwise 
     499                        setButtons(slot, n, slots); 
     500                        function setButtons(slot, n, slots) 
     501                        { 
     502                                if (n > 0) 
     503                                { 
     504                                        // TODO: this is not sensitive enough to nested areas 
     505                                        $(slot).find('.a-arrow-up').show().unbind('click').click(function() { 
     506                                                // It would be nice to confirm success here in some way 
     507                                                $.get(updateAction, { id: id, name: name, permid: $(slot).data('a-permid'), up: 1 }); 
     508                                                apostrophe.swapNodes(slot, slots[n - 1]); 
     509                                                apostrophe.areaUpdateMoveButtons(updateAction, id, name); 
     510                                                return false; 
     511                                        }); 
     512                                } 
     513                                else 
     514                                { 
     515                                  $(slot).find('.a-arrow-up').hide(); 
     516                                } 
     517                                if (n < (slots.length - 1)) 
     518                                { 
     519                                        $(slot).find('.a-arrow-down').show().unbind('click').click(function() { 
     520                                                // It would be nice to confirm success here in some way 
     521                                                $.get(updateAction, { id: id, name: name, permid: $(slot).data('a-permid'), up: 0 }); 
     522                                                apostrophe.swapNodes(slot, slots[n + 1]); 
     523                                                apostrophe.areaUpdateMoveButtons(updateAction, id, name); 
     524                                                return false; 
     525                                        }); 
     526                                } 
     527                                else 
     528                                { 
     529                                        $(slot).find('.a-arrow-down').hide(); 
     530                                } 
     531                        } 
     532                } 
     533        } 
     534         
     535        this.slotNotNew = function(pageid, name, permid) 
     536        { 
     537                $("#a-slot-" + pageid + "-" + name + "-" + permid).removeClass('a-new-slot'); 
     538        } 
    465539}  
    466540