Changeset 16679

Show
Ignore:
Timestamp:
06/23/08 17:30:52 (5 months ago)
Author:
adrenalin
Message:

Tabledata widget in beta stage. Fixed widgets downloads and images to
fit the current JavaScript? sorting model.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/MidCOM_2_8/midcom.helper.datamanager2/static/datamanager2.tablesorter.js

    r16651 r16679  
    11jQuery.fn.create_sortable = function(options) 
    22{ 
    3     console.log(options); 
    4      
    53    jQuery(this).addClass('jquery-enabled'); 
    64    jQuery(this).find('th.index').text(''); 
     
    1311    }); 
    1412     
     13    jQuery(this).find('tfoot td.new_row') 
     14        .unbind('click') 
     15        .click(function() 
     16        { 
     17            var new_row = jQuery(this).parent().clone(true); 
     18            jQuery(new_row).find('img.add-row').remove(); 
     19             
     20            // Insert the rows 
     21            jQuery(new_row) 
     22                .appendTo(jQuery(this).parents('table.jquery-enabled').find('tbody')); 
     23             
     24            jQuery(new_row).find('input').each(function(i) 
     25            { 
     26                var name = jQuery(this).attr('name'); 
     27                var size = jQuery(this).parents('table.jquery-enabled').find('tbody tr').size() - 1; 
     28                 
     29                if (name) 
     30                { 
     31                    name = name.replace(/index/, size); 
     32                    jQuery(this).attr('name', name); 
     33                } 
     34                 
     35                var id = jQuery(this).attr('id'); 
     36                 
     37                if (id) 
     38                { 
     39                    id = id.replace(/index/, size); 
     40                    jQuery(this).attr('id', id); 
     41                } 
     42                 
     43                var value = jQuery(this).attr('value'); 
     44                 
     45                if (value) 
     46                { 
     47                    value = value.replace(/__new_row__index/, '__new_row__' + size); 
     48                    jQuery(this).attr('value', value); 
     49                } 
     50            }); 
     51             
     52            jQuery(new_row).find('td.new_row') 
     53                .unbind('click') 
     54                .removeClass('new_row'); 
     55             
     56            jQuery(this).parents('table.jquery-enabled').create_sortable(options); 
     57            jQuery(this).rearrange_scores(); 
     58             
     59            // Check the amount of rows presented 
     60            var row_count = jQuery(this).parents('table.jquery-enabled').find('tbody tr').size(); 
     61             
     62            if (   options.max_count != 0 
     63                && row_count >= options.max_count) 
     64            { 
     65                jQuery(this) 
     66                    .fadeTo(500, 0.5) 
     67                    .unbind('click'); 
     68                return false; 
     69            } 
     70        }); 
     71     
    1572    // Less than two, no point in initializing the sortable 
    16     if (jQuery(this).find('td.midcom_helper_datamanager2_helper_sortable').size() < 2) 
    17     { 
    18         jQuery('td.midcom_helper_datamanager2_helper_sortable').css({display: 'none'}); 
     73    if (   !options.sortable 
     74        || jQuery(this).find('tbody td.midcom_helper_datamanager2_helper_sortable').size() < 2) 
     75    { 
     76        jQuery('tbody td.midcom_helper_datamanager2_helper_sortable').css({display: 'none'}); 
    1977        jQuery(this).find('th.index').css({display: 'none'}); 
    2078        return; 
    2179    } 
     80     
     81    jQuery('tbody td.midcom_helper_datamanager2_helper_sortable').css({display: 'table-cell'}); 
     82    jQuery(this).find('th.index').css({display: 'table-cell'}); 
    2283     
    2384    // IE6 compliant hovering 
     
    3596     
    3697     
    37     jQuery(this).find('td.midcom_helper_datamanager2_helper_sortable').each(function(i) 
     98    jQuery(this).find('tbody td.midcom_helper_datamanager2_helper_sortable').each(function(i) 
    3899    { 
    39100        if (jQuery(this).find('img.down').size() == 0) 
     
    70131    }); 
    71132     
    72     jQuery(this).find('tr').find('td:first').each(function(i) 
    73     { 
     133    jQuery(this).find('tbody tr').find('td:first').each(function(i) 
     134    { 
     135        if (   jQuery(this).find('img.delete').size() > 0 
     136            || options.allow_delete == false) 
     137        { 
     138            return; 
     139        } 
     140         
    74141        jQuery('<img />') 
    75142            .addClass('delete') 
     
    105172            .prependTo(jQuery(this)); 
    106173    }); 
    107          
     174     
     175    // Check the amount of rows presented 
     176    var row_count = jQuery(this).find('tbody tr').size(); 
     177     
     178    if (   options.max_count != 0 
     179        && row_count >= options.max_count) 
     180    { 
     181        jQuery(this) 
     182            .find('tfoot td.new_row').fadeTo(500, 0.5) 
     183            .unbind('click'); 
     184    } 
    108185    jQuery(this).rearrange_scores(); 
    109186} 
     
    122199        case 'up': 
    123200            jQuery(parent).insertBefore(jQuery(parent).prev('tr')); 
    124             jQuery(this).parents('table').rearrange_scores(); 
     201            jQuery(this).parents('table.jquery-enabled').rearrange_scores(); 
    125202            break; 
    126203        case 'down': 
    127204            jQuery(parent).insertAfter(jQuery(parent).next('tr')); 
    128             jQuery(this).parents('table').rearrange_scores(); 
     205            jQuery(this).parents('table.jquery-enabled').rearrange_scores(); 
    129206            break; 
    130207    } 
     
    133210jQuery.fn.rearrange_scores = function() 
    134211{ 
    135     var size = jQuery(this).find('td.midcom_helper_datamanager2_helper_sortable').size(); 
    136      
    137     jQuery(this).find('td.midcom_helper_datamanager2_helper_sortable').each(function(i) 
     212    var size = jQuery(this).find('tbody td.midcom_helper_datamanager2_helper_sortable').size(); 
     213     
     214    jQuery(this).find('tbody td.midcom_helper_datamanager2_helper_sortable').each(function(i) 
    138215    { 
    139216        var last_index = size - 1; 
  • branches/MidCOM_2_8/midcom.helper.datamanager2/static/legacy.css

    r16651 r16679  
    345345} 
    346346 
     347form.datamanager2 table.jquery-enabled tfoot td.new_row 
     348{ 
     349  display: table-cell; 
     350} 
     351 
    347352form.datamanager2 table.jquery-enabled tr.deleted td input 
    348353{ 
  • branches/MidCOM_2_8/midcom.helper.datamanager2/type/blobs.php

    r16651 r16679  
    353353        $temp = array(); 
    354354         
    355         $data = Array(); 
     355        // Data that will be stored 
     356        $data = array(); 
     357         
    356358        foreach ($this->attachments as $identifier => $attachment) 
    357359        { 
  • branches/MidCOM_2_8/midcom.helper.datamanager2/type/tabledata.php

    r16651 r16679  
    9292     
    9393    /** 
     94     * Should adding new columns be allowed? 
     95     * 
     96     * @access public 
     97     * @var boolean 
     98     */ 
     99    var $allow_new_columns = false; 
     100     
     101    /** 
    94102     * Parameter domain that will be used to store the data 
    95103     *  
     
    131139    function _on_initialize() 
    132140    { 
    133         // Add the JavaScript file to aid in sorting, if requested for 
     141        // Add the JavaScript file to aid in sorting and other features 
     142        $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL . '/midcom.helper.datamanager2/datamanager2.tablesorter.js'); 
     143         
     144        if (!$this->row_limit) 
     145        { 
     146            $this->row_limit = 0; 
     147        } 
     148         
    134149        if ($this->sortable_rows) 
    135150        { 
    136             $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL . '/midcom.helper.datamanager2/datamanager2.tablesorter.js'); 
    137         } 
    138          
    139         if (!$this->row_limit) 
    140         { 
    141             $this->row_limit = 0; 
     151            $sortable = 'true'; 
     152        } 
     153        else 
     154        { 
     155            $sortable = 'false'; 
    142156        } 
    143157         
     
    148162                jQuery('#midcom_helper_datamanager2_{$this->name}_widget_tabledata') 
    149163                    .create_sortable({ 
    150                         max_count: {$this->row_limit} 
     164                        max_count: {$this->row_limit}, 
     165                        sortable: {$sortable}, 
     166                        allow_delete: true 
    151167                    }); 
    152168            }); 
     
    242258             
    243259            if (   $order 
    244                 && ($array = unserialize($order))) 
     260                && ($array = unserialize($order)) 
     261                && is_array($array)) 
    245262            { 
    246263                // Reinitialize the returned array 
     
    468485                } 
    469486                 
    470                 if (preg_match('/^__new_row__/', $row)) 
    471                 { 
    472                     $index = count($this->_storage_data); 
    473                      
    474                     while (array_key_exists($index, $this->_storage_data)) 
     487                // Skip the new row placeholder index 
     488                if ($row === '__new_row__index') 
     489                { 
     490                    unset($this->_storage_data[$row]); 
     491                    continue; 
     492                }                 
     493                 
     494                // This is a new row 
     495                if (preg_match('/^__new_row__([0-9]+)$/', $row, $regs)) 
     496                { 
     497                    $index = 1; 
     498                     
     499                    while (isset($this->_storage_data["{$index}"])) 
    475500                    { 
    476501                        $index++; 
     
    483508                    } 
    484509                     
     510                    // Remove the existing row and replace it with new 
     511                    unset($this->_storage_data[$row]); 
     512                     
     513                    $this->_storage_data["{$index}"] = $array; 
     514                     
     515                    if (in_array($row, $this->_row_order)) 
     516                    { 
     517                        $key = array_search($row, $this->_row_order); 
     518                        $this->_row_order[$key] = "{$index}"; 
     519                    } 
     520                     
    485521                    // Store to new indexes 
    486                     $new_indexes[(string) $index] = $row; 
    487                     $row = $index; 
    488                 } 
    489                  
     522                    $new_indexes["{$index}"] = $regs[1]; 
     523                    $row = "{$index}"; 
     524                } 
     525                 
     526                // Check that each field gets populated 
     527                $hits = false; 
     528                 
     529                // Store each value in a parameter 
    490530                foreach ($array as $column => $value) 
    491531                { 
     532                    if ($value) 
     533                    { 
     534                        $hits = true; 
     535                    } 
     536                     
    492537                    $this->storage->object->set_parameter($this->parameter_domain, "{$this->name}{$this->storage_mode_parameter_limiter}{$row}{$this->storage_mode_parameter_limiter}{$column}", $value); 
     538                } 
     539                 
     540                if (!$hits) 
     541                { 
     542                    $key = array_search($row, $this->_row_order); 
     543                    unset($this->_row_order[$key]); 
     544                    unset($this->_storage_data[$row]); 
    493545                } 
    494546            } 
     
    530582            { 
    531583                $key = array_search($old, $this->_row_order); 
    532                 $this->_row_order[$key] = "{$new}"; 
    533             } 
     584                 
     585                if (   $key !== false 
     586                    && $this->get_row($new)) 
     587                { 
     588                    $this->_row_order[$key] = "{$new}"; 
     589                } 
     590            } 
     591             
     592            $new_row = array_search('__new_row__index', $this->_row_order); 
     593             
     594            if ($new_row) 
     595            { 
     596                unset($this->_row_order[$new_row]); 
     597            } 
     598             
     599            ksort($this->_row_order); 
     600             
    534601            $this->storage->object->set_parameter('midcom.helper.datamanager2.type.tabledata.order', $this->name, serialize($this->_row_order)); 
    535602        } 
     
    623690        $output .= "</table>\n"; 
    624691         
    625         echo $output; 
    626692        return $output; 
    627693    } 
  • branches/MidCOM_2_8/midcom.helper.datamanager2/widget/downloads.php

    r16651 r16679  
    117117            $this->max_count = $this->_type->max_count; 
    118118        } 
    119  
     119         
     120        // Create sortable 
     121        if ($this->_type->sortable) 
     122        { 
     123            // Configuration options 
     124            $_MIDCOM->add_jscript(" 
     125                jQuery(document).ready(function() 
     126                { 
     127                    jQuery('#{$this->_namespace}{$this->name}') 
     128                        .create_sortable({ 
     129                            max_count: 0, 
     130                            sortable: true, 
     131                            allow_delete: false 
     132                        }); 
     133                }); 
     134            "); 
     135        } 
     136         
    120137        return true; 
    121138    } 
     
    246263        if ($this->_type->sortable) 
    247264        { 
    248             $sortable = "<td class=\"midcom_helper_datamanager2_helper_sortable\"><input type=\"text\" class=\"downloads_sortable\" name=\"midcom_helper_datamanager2_sortable[{$this->name}][{$identifier}]\" value=\"" . $info['object']->guid . "\" /></td>\n"; 
     265            $sortable  = "            <td class=\"midcom_helper_datamanager2_helper_sortable\">\n"; 
     266            $sortable .= "               <input type=\"text\" class=\"downloads_sortable\" name=\"midcom_helper_datamanager2_sortable[{$this->name}][{$identifier}]\" value=\"{$this->_sort_index}\" />\n"; 
     267            $sortable .="             </td>\n"; 
     268             
    249269            $this->_sort_index++; 
    250270        } 
  • branches/MidCOM_2_8/midcom.helper.datamanager2/widget/images.php

    r16628 r16679  
    122122        } 
    123123 
     124        // Create sortable 
     125        if ($this->_type->sortable) 
     126        { 
     127            // Configuration options 
     128            $_MIDCOM->add_jscript(" 
     129                jQuery(document).ready(function() 
     130                { 
     131                    jQuery('#{$this->_namespace}{$this->name}') 
     132                        .create_sortable({ 
     133                            max_count: 0, 
     134                            sortable: true, 
     135                            allow_delete: false 
     136                        }); 
     137                }); 
     138            "); 
     139        } 
     140         
    124141        $_MIDCOM->add_jscript($this->_get_filename_validation_script()); 
    125142 
     
    394411        if ($this->_type->sortable) 
    395412        { 
    396             $sortable = "            <td class=\"midcom_helper_datamanager2_helper_sortable\"><input type=\"text\" class=\"image_sortable\" name=\"midcom_helper_datamanager2_sortable[{$this->name}][{$identifier}]\" value=\"" . $info['object']->guid . "\" /></td>\n"; 
     413            $sortable = "            <td class=\"midcom_helper_datamanager2_helper_sortable\"><input type=\"text\" class=\"image_sortable\" name=\"midcom_helper_datamanager2_sortable[{$this->name}][{$identifier}]\" value=\"{$this->_sort_index}\" /></td>\n"; 
    397414            $this->_sort_index++; 
    398415        } 
  • branches/MidCOM_2_8/midcom.helper.datamanager2/widget/tabledata.php

    r16651 r16679  
    8282            $html .= "    <tfoot>\n"; 
    8383            $html .= "        <tr>\n"; 
    84             $html .= "            <th class=\"add_new_row\"><img src=\"" . MIDCOM_STATIC_URL . "/stock-icons/16x16/list-add.png\" alt=\"" . $this->_l10n->get('add new row') . "\" /></th>\n"; 
     84            $html .= "            <td class=\"new_row midcom_helper_datamanager2_helper_sortable\">\n"; 
     85            $html .= "                <img src=\"" . MIDCOM_STATIC_URL . "/stock-icons/16x16/list-add.png\" alt=\"" . $this->_l10n->get('add new row') . "\" class=\"add-row\" />\n"; 
     86            $html .= "                <input type=\"text\" class=\"downloads_sortable\" name=\"midcom_helper_datamanager2_sortable[{$this->name}][]\" value=\"__new_row__index\" />\n"; 
     87            $html .= "            </td>\n"; 
    8588            $html .= $this->_add_columns('__new_row__index'); 
    8689            $html .= "        </tr>\n"; 
     
    114117            if ($this->_type->sortable_rows) 
    115118            { 
    116                 $html .= "<td class=\"midcom_helper_datamanager2_helper_sortable\"><input type=\"text\" class=\"downloads_sortable\" name=\"midcom_helper_datamanager2_sortable[{$this->name}][]\" value=\"{$key}\" /></td>\n"; 
     119                $html .= "            <td class=\"midcom_helper_datamanager2_helper_sortable\">\n"; 
     120                $html .= "                <input type=\"text\" class=\"downloads_sortable\" name=\"midcom_helper_datamanager2_sortable[{$this->name}][]\" value=\"{$key}\" />\n"; 
     121                $html .= "            </td>\n"; 
    117122            } 
    118123             
     
    195200                || count($rows) < $this->_type->row_limit)) 
    196201        { 
    197             $rows[] = '__new_row__'; 
     202            $rows[] = '__new_row__0'; 
    198203        } 
    199204         
     
    212217        } 
    213218         
    214         if ($this->_type->sortable_rows 
     219        // Deleted rows 
     220        if (   isset($_REQUEST['___midcom_helper_datamanager2_type_tabledata']) 
     221            && isset($_REQUEST['___midcom_helper_datamanager2_type_tabledata'][$this->name]) 
     222            && is_array($_REQUEST['___midcom_helper_datamanager2_type_tabledata'][$this->name])) 
     223        { 
     224            foreach ($_REQUEST['___midcom_helper_datamanager2_type_tabledata'][$this->name] as $row => $columns) 
     225            { 
     226                foreach ($columns as $column => $value) 
     227                { 
     228                    $this->_type->_storage_data[$row][$column] = ''; 
     229                } 
     230            } 
     231        } 
     232         
     233        if (   $this->_type->sortable_rows 
    215234            && isset($_REQUEST['midcom_helper_datamanager2_sortable']) 
    216235            && isset($_REQUEST['midcom_helper_datamanager2_sortable'][$this->name])) 
    217236        { 
    218             $this->_type->_row_order = $_REQUEST['midcom_helper_datamanager2_sortable'][$this->name]; 
     237            foreach ($_REQUEST['midcom_helper_datamanager2_sortable'][$this->name] as $row_name) 
     238            { 
     239                $this->_type->_row_order[] = $row_name; 
     240            } 
    219241        } 
    220242    }