Changeset 16679
- Timestamp:
- 06/23/08 17:30:52 (5 months ago)
- Files:
-
- branches/MidCOM_2_8/midcom.helper.datamanager2/static/datamanager2.tablesorter.js (modified) (7 diffs)
- branches/MidCOM_2_8/midcom.helper.datamanager2/static/legacy.css (modified) (1 diff)
- branches/MidCOM_2_8/midcom.helper.datamanager2/type/blobs.php (modified) (1 diff)
- branches/MidCOM_2_8/midcom.helper.datamanager2/type/tabledata.php (modified) (8 diffs)
- branches/MidCOM_2_8/midcom.helper.datamanager2/widget/downloads.php (modified) (2 diffs)
- branches/MidCOM_2_8/midcom.helper.datamanager2/widget/images.php (modified) (2 diffs)
- branches/MidCOM_2_8/midcom.helper.datamanager2/widget/tabledata.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/MidCOM_2_8/midcom.helper.datamanager2/static/datamanager2.tablesorter.js
r16651 r16679 1 1 jQuery.fn.create_sortable = function(options) 2 2 { 3 console.log(options);4 5 3 jQuery(this).addClass('jquery-enabled'); 6 4 jQuery(this).find('th.index').text(''); … … 13 11 }); 14 12 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 15 72 // 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'}); 19 77 jQuery(this).find('th.index').css({display: 'none'}); 20 78 return; 21 79 } 80 81 jQuery('tbody td.midcom_helper_datamanager2_helper_sortable').css({display: 'table-cell'}); 82 jQuery(this).find('th.index').css({display: 'table-cell'}); 22 83 23 84 // IE6 compliant hovering … … 35 96 36 97 37 jQuery(this).find('t d.midcom_helper_datamanager2_helper_sortable').each(function(i)98 jQuery(this).find('tbody td.midcom_helper_datamanager2_helper_sortable').each(function(i) 38 99 { 39 100 if (jQuery(this).find('img.down').size() == 0) … … 70 131 }); 71 132 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 74 141 jQuery('<img />') 75 142 .addClass('delete') … … 105 172 .prependTo(jQuery(this)); 106 173 }); 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 } 108 185 jQuery(this).rearrange_scores(); 109 186 } … … 122 199 case 'up': 123 200 jQuery(parent).insertBefore(jQuery(parent).prev('tr')); 124 jQuery(this).parents('table ').rearrange_scores();201 jQuery(this).parents('table.jquery-enabled').rearrange_scores(); 125 202 break; 126 203 case 'down': 127 204 jQuery(parent).insertAfter(jQuery(parent).next('tr')); 128 jQuery(this).parents('table ').rearrange_scores();205 jQuery(this).parents('table.jquery-enabled').rearrange_scores(); 129 206 break; 130 207 } … … 133 210 jQuery.fn.rearrange_scores = function() 134 211 { 135 var size = jQuery(this).find('t d.midcom_helper_datamanager2_helper_sortable').size();136 137 jQuery(this).find('t d.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) 138 215 { 139 216 var last_index = size - 1; branches/MidCOM_2_8/midcom.helper.datamanager2/static/legacy.css
r16651 r16679 345 345 } 346 346 347 form.datamanager2 table.jquery-enabled tfoot td.new_row 348 { 349 display: table-cell; 350 } 351 347 352 form.datamanager2 table.jquery-enabled tr.deleted td input 348 353 { branches/MidCOM_2_8/midcom.helper.datamanager2/type/blobs.php
r16651 r16679 353 353 $temp = array(); 354 354 355 $data = Array(); 355 // Data that will be stored 356 $data = array(); 357 356 358 foreach ($this->attachments as $identifier => $attachment) 357 359 { branches/MidCOM_2_8/midcom.helper.datamanager2/type/tabledata.php
r16651 r16679 92 92 93 93 /** 94 * Should adding new columns be allowed? 95 * 96 * @access public 97 * @var boolean 98 */ 99 var $allow_new_columns = false; 100 101 /** 94 102 * Parameter domain that will be used to store the data 95 103 * … … 131 139 function _on_initialize() 132 140 { 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 134 149 if ($this->sortable_rows) 135 150 { 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'; 142 156 } 143 157 … … 148 162 jQuery('#midcom_helper_datamanager2_{$this->name}_widget_tabledata') 149 163 .create_sortable({ 150 max_count: {$this->row_limit} 164 max_count: {$this->row_limit}, 165 sortable: {$sortable}, 166 allow_delete: true 151 167 }); 152 168 }); … … 242 258 243 259 if ( $order 244 && ($array = unserialize($order))) 260 && ($array = unserialize($order)) 261 && is_array($array)) 245 262 { 246 263 // Reinitialize the returned array … … 468 485 } 469 486 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}"])) 475 500 { 476 501 $index++; … … 483 508 } 484 509 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 485 521 // 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 490 530 foreach ($array as $column => $value) 491 531 { 532 if ($value) 533 { 534 $hits = true; 535 } 536 492 537 $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]); 493 545 } 494 546 } … … 530 582 { 531 583 $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 534 601 $this->storage->object->set_parameter('midcom.helper.datamanager2.type.tabledata.order', $this->name, serialize($this->_row_order)); 535 602 } … … 623 690 $output .= "</table>\n"; 624 691 625 echo $output;626 692 return $output; 627 693 } branches/MidCOM_2_8/midcom.helper.datamanager2/widget/downloads.php
r16651 r16679 117 117 $this->max_count = $this->_type->max_count; 118 118 } 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 120 137 return true; 121 138 } … … 246 263 if ($this->_type->sortable) 247 264 { 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 249 269 $this->_sort_index++; 250 270 } branches/MidCOM_2_8/midcom.helper.datamanager2/widget/images.php
r16628 r16679 122 122 } 123 123 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 124 141 $_MIDCOM->add_jscript($this->_get_filename_validation_script()); 125 142 … … 394 411 if ($this->_type->sortable) 395 412 { 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"; 397 414 $this->_sort_index++; 398 415 } branches/MidCOM_2_8/midcom.helper.datamanager2/widget/tabledata.php
r16651 r16679 82 82 $html .= " <tfoot>\n"; 83 83 $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"; 85 88 $html .= $this->_add_columns('__new_row__index'); 86 89 $html .= " </tr>\n"; … … 114 117 if ($this->_type->sortable_rows) 115 118 { 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"; 117 122 } 118 123 … … 195 200 || count($rows) < $this->_type->row_limit)) 196 201 { 197 $rows[] = '__new_row__ ';202 $rows[] = '__new_row__0'; 198 203 } 199 204 … … 212 217 } 213 218 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 215 234 && isset($_REQUEST['midcom_helper_datamanager2_sortable']) 216 235 && isset($_REQUEST['midcom_helper_datamanager2_sortable'][$this->name])) 217 236 { 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 } 219 241 } 220 242 }
