Changeset 16519
- Timestamp:
- 06/01/08 17:17:10 (3 months ago)
- Files:
-
- trunk/midcom/midcom.helper.datamanager2/documentation/CHANGES (modified) (1 diff)
- trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.css (modified) (1 diff)
- trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.js (modified) (7 diffs)
- trunk/midcom/midcom.helper.datamanager2/type/mnrelation.php (modified) (7 diffs)
- trunk/midcom/midcom.helper.datamanager2/type/select.php (modified) (2 diffs)
- trunk/midcom/midcom.helper.datamanager2/widget/chooser.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.helper.datamanager2/documentation/CHANGES
r16485 r16519 8 8 which might even break existing functionality. 9 9 - All items marked with "+" represent completely new features. 10 11 2008-06-01 adrenalin 12 + Chooser widget can store order information now 13 - Documented Chooser widget JavaScript files 10 14 11 15 2008-05-28 adrenalin trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.css
r16518 r16519 187 187 ul.chooser_widget_results.ui-sortable .chooser_widget_results_item_dragger 188 188 { 189 background : url('../../stock-icons/16x16/topic-score.png') center center no-repeat; 189 190 width: 20px; 190 191 height: 22px; 191 192 margin-left: -20px; 192 193 float: left; 193 cursor: move;194 cursor: n-resize; 194 195 } 195 196 trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.js
r16518 r16519 671 671 { 672 672 var jq_elem = jQuery(target(event)).addClass(CLASSES.HOVER); 673 jQuery(target(event)).find('div.chooser_widget_results_item_dragger').fadeIn('slow'); 673 674 }) 674 675 .mouseout( function(event) 675 676 { 676 677 jQuery(target(event)).removeClass(CLASSES.HOVER); 678 jQuery(target(event)).find('div.chooser_widget_results_item_dragger').fadeOut('fast'); 677 679 }); 678 680 … … 709 711 .prependTo(li_elem); 710 712 711 jQuery('<input type="hidden" />') 712 .attr('name', 'sortable[' + options.widget_id + '][]') 713 .attr('value', item_id); 713 if (options.sortable) 714 { 715 jQuery('<input type="hidden" />') 716 .attr('name', options.widget_id + '[sortable][]') 717 .attr('value', item_id) 718 .appendTo(li_elem); 719 } 714 720 715 721 li_elem.appendTo(list); … … 1020 1026 .attr({id: options.widget_id + '_result_item_dragger_' + item.id}) 1021 1027 .addClass('chooser_widget_results_item_dragger') 1028 .fadeOut(0) 1022 1029 .appendTo(item_parts); 1023 1030 … … 1028 1035 .appendTo(item_parts); 1029 1036 1030 jQuery.each( options.result_headers, function(i,n)1037 jQuery.each(options.result_headers, function(i,n) 1031 1038 { 1032 1039 var value = null; … … 1041 1048 1042 1049 item_content = jQuery('<div>') 1043 .addClass('chooser_widget_item_part')1044 .attr(1045 {1046 title: midcom_helper_datamanager2_widget_chooser_format_value('html2text', value)1047 })1048 .css(1049 {1050 width: block_width + '%'1051 })1052 .html( value )1053 .appendTo(item_parts);1050 .addClass('chooser_widget_item_part') 1051 .attr( 1052 { 1053 title: midcom_helper_datamanager2_widget_chooser_format_value('html2text', value) 1054 }) 1055 .css( 1056 { 1057 width: block_width + '%' 1058 }) 1059 .html( value ) 1060 .appendTo(item_parts); 1054 1061 }); 1055 1062 … … 1100 1107 } 1101 1108 1102 1109 /** 1110 * Create the sortable list 1111 */ 1103 1112 jQuery.fn.create_sortable = function() 1104 1113 { 1105 // Create the sortable list, if there are more than one item in the list1114 // If there is less than two items in the list, sortable shouldn't be created 1106 1115 if (jQuery(this).find('li').size() <= 1) 1107 1116 { … … 1114 1123 } 1115 1124 1116 jQuery(this).sortable('destroy'); 1125 if (jQuery(this).attr('sortable')) 1126 { 1127 jQuery(this).sortable('destroy'); 1128 } 1129 1117 1130 jQuery(this).sortable( 1118 1131 { trunk/midcom/midcom.helper.datamanager2/type/mnrelation.php
r14806 r16519 81 81 * are available at the site of import. This flag is not set by default. Note, that 82 82 * this does not affect import, which is only available with keys, not values. 83 * - <i>boolean sortable:</i> Switch for determining if the order selected by the widget 84 * should be stored to the metadata object 85 * - <i>string sortable_sort_order:</i> Direction that metadata.score should go. If this 86 * is set to `ASC`, lower scores will be displayed first. If this is set to `DESC`, higher 87 * scores will be displayed first. `DESC` is default, since then new member objects will 88 * be left at the end of the line rather than appearing first. This field is not case 89 * sensitive and string can be extended e.g. to `ascend`. 83 90 * 84 91 * (These list is complete, including all allowed options from the base type. Base type … … 162 169 */ 163 170 var $_membership_objects = null; 171 172 /** 173 * Should the sorting feature be enabled. This will affect the way chooser widget will act 174 * and how the results will be presented. If the sorting feature is enabled, 175 * 176 * @access public 177 * @var boolean 178 */ 179 var $sortable = false; 180 181 /** 182 * Sort order. Which direction should metadata.score force the results. This should be either 183 * `ASC` or `DESC` 184 * 185 * @access public 186 * @var string 187 */ 188 var $sortable_sort_order = 'DESC'; 189 190 /** 191 * Sorted order, which is returned by the widget. 192 * 193 * @access public 194 * @var Array 195 */ 196 var $sorted_order = array(); 164 197 165 198 /** … … 240 273 $qb = $_MIDCOM->dbfactory->new_query_builder($this->mapping_class_name); 241 274 $qb->add_constraint($this->master_fieldname, '=', $this->_get_master_foreign_key()); 275 276 if ( $this->sortable 277 && preg_match('/^(ASC|DESC)/i', $this->sortable_sort_order, $regs)) 278 { 279 $order = strtoupper($regs[1]); 280 $qb->add_order('metadata.score', $order); 281 } 282 242 283 if ($this->member_limit_like) 243 284 { … … 313 354 $existing_members[$key] = $index; 314 355 } 315 356 357 // Cache the total quantity of items and get the order if the field is supposed to store the member order 358 if ( $this->sortable 359 && isset($this->sorted_order)) 360 { 361 $count = count($this->sorted_order); 362 363 if (preg_match('/ASC/i', $this->sortable_sort_order)) 364 { 365 $direction = 'asc'; 366 } 367 else 368 { 369 $direction = 'desc'; 370 } 371 } 372 373 $i = 0; 374 316 375 $new_membership_objects = Array(); 317 376 foreach ($this->selection as $key) … … 330 389 if (array_key_exists($key, $existing_members)) 331 390 { 391 // Update the existing member 392 if ($this->sortable) 393 { 394 $index = $existing_members[$key]; 395 396 if ($direction === 'asc') 397 { 398 $this->_membership_objects[$index]->metadata->score = $i; 399 } 400 else 401 { 402 $this->_membership_objects[$index]->metadata->score = $count - $i; 403 } 404 405 if (!$this->_membership_objects[$index]->update()) 406 { 407 debug_add("Failed to update the member record for key {$key}. Couldn't store the order information", MIDCOM_LOG_ERROR); 408 debug_add('Last Midgard error was ' . mgd_errstr(), MIDCOM_LOG_ERROR); 409 debug_print_r('Tried to update this object', $this->_membership_objects[$index]); 410 } 411 412 $i++; 413 } 414 332 415 $index = $existing_members[$key]; 333 416 $new_membership_objects[] = $this->_membership_objects[$index]; … … 340 423 $member->{$this->master_fieldname} = $this->_get_master_foreign_key(); 341 424 $member->{$this->member_fieldname} = $key; 342 if (! $member->create()) 425 426 // Set the score if requested 427 if ($this->sortable) 428 { 429 if ($direction === 'asc') 430 { 431 $member->metadata->score = $i; 432 } 433 else 434 { 435 $member->metadata->score = $count - $i; 436 } 437 438 $i++; 439 } 440 441 if (!$member->create()) 343 442 { 344 443 debug_add("Failed to create a new member record for key {$key}, skipping it. " . … … 356 455 foreach ($this->_membership_objects as $member) 357 456 { 358 if (! $member->delete())457 if (!$member->delete()) 359 458 { 360 459 debug_add("Failed to delete a no longer needed member record #{$member->id}, ignoring silently. " . trunk/midcom/midcom.helper.datamanager2/type/select.php
r15380 r16519 40 40 * - <i>string multiple_storagemode:</i> Controls how multiple options are stored in 41 41 * a single field. See below "multiselect storagemodes". Defaults to "serialized". 42 * - <i>boolean sortable:</i> Switch for determining if the order selected by the widget 43 * should be stored to the metadata object 42 44 * 43 45 * Keys should be alphanumeric only. … … 206 208 207 209 /** 210 * Should the sorting feature be enabled. This will affect the way chooser widget will act 211 * and how the results will be presented. If the sorting feature is enabled, 212 * 213 * @access public 214 * @var boolean 215 */ 216 var $sortable = false; 217 218 /** 208 219 * Initialize the class, if necessary, create a callback instance, otherwise 209 220 * validate that an option array is present. trunk/midcom/midcom.helper.datamanager2/widget/chooser.php
r16518 r16519 308 308 * @var boolean True if the sorting should be enabled 309 309 */ 310 var $sortable = false;310 var $sortable = null; 311 311 312 312 /** … … 325 325 debug_pop(); 326 326 return false; 327 } 328 329 // Determine the sortability from the type configuration 330 if ( is_null($this->sortable) 331 && isset($this->_type->sortable)) 332 { 333 $this->sortable = $this->_type->sortable; 327 334 } 328 335 … … 1536 1543 return; 1537 1544 } 1545 1538 1546 $real_results =& $results["{$this->_element_id}_selections"]; 1539 1547 if (is_array($real_results)) … … 1553 1561 { 1554 1562 $this->_type->selection[] = $real_results; 1563 } 1564 1565 if ( $this->sortable 1566 && isset($results[$this->_element_id]) 1567 && isset($results[$this->_element_id]['sortable'])) 1568 { 1569 $this->_type->sorted_order = array(); 1570 1571 foreach ($results[$this->_element_id]['sortable'] as $i => $id) 1572 { 1573 $this->_type->sorted_order[$id] = $i; 1574 } 1555 1575 } 1556 1576
