Changeset 13663

Show
Ignore:
Timestamp:
11/27/07 16:51:21 (1 year ago)
Author:
adrenalin
Message:

Proceeding with the sortable widget.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.helper.datamanager2/locale/default.en.txt

    r5325 r13663  
    205205---STRINGEND 
    206206 
     207---STRING write the order, lower numbers are placed first 
     208Write the order, lower numbers are placed first 
     209---STRINGEND 
     210 
     211---STRING drag and drop to sort 
     212Drag and drop to sort 
     213---STRINGEND 
     214 
  • trunk/midcom/midcom.helper.datamanager2/locale/default.fi.txt

    r5325 r13663  
    9292---STRINGEND 
    9393 
     94---STRING rotate left 
     95KierrÀ vasemmalle 
     96---STRINGEND 
     97 
     98---STRING rotate right 
     99KierrÀ oikealle 
     100---STRINGEND 
     101 
    94102---STRING type blobs: file size 
    95103Tiedoston koko 
    96104---STRINGEND 
    97105 
     106---STRING type image: actions 
     107Kuvan toiminnot 
     108---STRINGEND 
     109 
    98110---STRING type image: available sizes 
    99111Saatavilla olevat koot 
     
    192204---STRINGEND 
    193205 
    194 ---STRING rotate left 
    195 KierrÀ vasemmalle 
    196 ---STRINGEND 
    197  
    198 ---STRING rotate right 
    199 KierrÀ oikealle 
    200 ---STRINGEND 
    201  
    202 ---STRING type image: actions 
    203 Kuvan toiminnot 
    204 ---STRINGEND 
    205  
     206---STRING write the order, lower numbers are placed first 
     207Kirjoita jÀrjestys, pienet numerot nÀytetÀÀn ensimmÀisenÀ 
     208---STRINGEND 
     209 
     210---STRING drag and drop to sort 
     211JÀrjestele hiirellÀ raahaamalla 
     212---STRINGEND 
     213 
  • trunk/midcom/midcom.helper.datamanager2/static/jquery.widget_sortable.js

    r13591 r13663  
    11jQuery.fn.create_sortable = function() 
    22{ 
     3    // Hide the inputs 
     4    $j(this).find('input[@type="text"]').css({display: 'none'}); 
     5     
    36    $j(this).each(function(i) 
    47    { 
    58        $j(this).sortable({ 
    6             containment: $j(this).attr('id') 
     9            containment: 'parent', 
     10            change: function(e, ui) 
     11            { 
     12                // Update all the text inputs to keep track on the changes 
     13                $j(this.parentNode).find('input[@type="text"]').each(function(i) 
     14                { 
     15                    $j(this).attr('value', i + 1); 
     16                }); 
     17            } 
    718        }); 
    819    }); 
    920} 
     21 
     22$j(document).ready(function() 
     23{ 
     24    $j('body p.sortable-help').css({display: 'none !important'}); 
     25    $j('body p.sortable-help-jquery').css({display: 'block !important'}); 
     26}); 
  • trunk/midcom/midcom.helper.datamanager2/widget/select.php

    r13568 r13663  
    4949 
    5050    /** 
    51      * The select element in use. This need spearate tracking due to the potential 
     51     * The select element in use. This need separate tracking due to the potential 
    5252     * group code. This makes tracking of empty return values much easier. It is 
    5353     * populated during add_elements_to_form(). 
     
    255255 
    256256    } 
    257  
    258257} 
    259  
    260258?> 
  • trunk/midcom/midcom.helper.datamanager2/widget/sortable.php

    r13582 r13663  
    3535     
    3636    /** 
     37     * Select automatically every object. This is for using the widget only to sort, not to select what 
     38     * has been sorted. 
     39     * 
     40     * @access public 
     41     * @var boolean 
     42     */ 
     43    var $select_all = false; 
     44     
     45    /** 
    3746     * The initialization event handler post-processes the maxlength setting. 
    3847     * 
     
    91100    function _create_select_element() 
    92101    { 
    93         $this->_elements['s_header'] =& HTML_QuickForm::createElement('static', 's_header', '', "<ul id=\"{$this->name}_sortable\" class=\"sortable\">\n"); 
    94          
    95102        $readonly = $this->_field['readonly']; 
    96103         
     
    117124        } 
    118125         
     126        // Show the help text 
     127        // jQuery help text, hide for now 
     128        $html  = "<p style=\"display: none;\" class=\"sortable-help-jquery\">\n"; 
     129        $html .= $this->_l10n->get('drag and drop to sort') . '.'; 
     130        $html .= "</p>\n"; 
     131         
     132        // Non-jQuery help, show on default, but hide with jQuery 
     133        $html  .= "<p class=\"sortable-help\">\n"; 
     134        $html .= $this->_l10n->get('write the order, lower numbers are placed first') . '.'; 
     135        $html .= "</p>\n"; 
     136        $html .= "<ul id=\"{$this->name}_sortable\" class=\"midcom_helper_datamanager2_widget_sortable\">\n"; 
     137         
     138        $this->_elements['s_header'] =& HTML_QuickForm::createElement('static', 's_header', '', $html); 
     139         
     140        $i = 1; 
     141         
     142        // Temporary array for the selection set 
     143        $temp = array(); 
     144         
     145        $all = $this->_type->list_all(); 
     146         
     147        foreach ($this->_type->selection as $key => $value) 
     148        { 
     149            if (isset($all[$value])) 
     150            { 
     151                $temp[$value] = $all[$value]; 
     152            } 
     153            else 
     154            { 
     155                $temp[$value] = $value; 
     156            } 
     157        } 
     158         
     159        foreach ($this->_type->list_all() as $key => $value) 
     160        { 
     161            if (array_key_exists($key, $temp)) 
     162            { 
     163                continue; 
     164            } 
     165             
     166            $temp[$key] = $value; 
     167        } 
     168         
     169        // Reset the form data 
    119170        $html = ''; 
    120         $i = 1; 
    121          
    122         foreach ($this->_type->list_all() as $key => $value) 
    123         { 
     171         
     172        foreach ($temp as $key => $value) 
     173        { 
     174            if (   array_key_exists($key, $this->_type->selection) 
     175                || $this->select_all) 
     176            { 
     177                $checked = ' checked="checked"'; 
     178            } 
     179            else 
     180            { 
     181                $checked = ''; 
     182            } 
     183             
    124184            $html .= "    <li>\n"; 
    125             $html .= "        <input type=\"{$input_type}\" name=\"{$this->name}{$name_suffix}\" value=\"{$key}\" />\n"; 
    126             $html .= "        <input type=\"text\" name=\"{$this->name}_order[{$key}]\" value=\"{$i}\" />\n"; 
    127             $html .= "        {$this->_translate($value)}\n"; 
     185             
     186            if ($this->select_all) 
     187            { 
     188                $html .= "            <input type=\"{$input_type}\" name=\"{$this->name}{$name_suffix}\" id=\"midcom_helper_datamanager2_widget_sortable_{$this->name}_{$i}\" value=\"{$key}\" checked=\"checked\" style=\"display: none !important;\" />\n"; 
     189            } 
     190            else 
     191            { 
     192                $html .= "        <label for=\"midcom_helper_datamanager2_widget_sortable_{$this->name}_{$i}\">\n"; 
     193                $html .= "            <input type=\"{$input_type}\" name=\"{$this->name}{$name_suffix}\" id=\"midcom_helper_datamanager2_widget_sortable_{$this->name}_{$i}\" value=\"{$key}\"{$checked} />\n"; 
     194            } 
     195             
     196            $html .= "            <input type=\"text\" name=\"{$this->name}_order[{$key}]\" value=\"{$i}\" />\n"; 
     197            $html .= "            {$this->_translate($value)}\n"; 
     198             
     199            if (!$this->select_all) 
     200            { 
     201                $html .= "         </label>\n"; 
     202            } 
    128203            $html .= "    </li>\n"; 
    129204            $i++; 
     
    153228    function sync_type_with_widget($results) 
    154229    { 
    155         echo "<pre>\n"; 
    156         echo "Make me work\n"; 
    157         print_r($_POST); 
    158         echo "</pre>\n"; 
    159         die(); 
     230        $temp = array(); 
     231         
     232        asort($results["{$this->name}_order"]); 
     233        $name = $this->name; 
     234         
     235        foreach ($results["{$this->name}_order"] as $key => $value) 
     236        { 
     237            if (   !isset($results[$this->name]) 
     238                || !in_array($key, $results[$this->name])) 
     239            { 
     240                continue; 
     241            } 
     242             
     243            $temp[] = $key; 
     244        } 
     245         
     246        $this->_type->selection = $temp; 
    160247    } 
    161248}