Changeset 14468
- Timestamp:
- 01/17/08 13:44:21 (11 months ago)
- Files:
-
- trunk/midcom/midcom.helper.datamanager2/exec/chooser_handler.php (modified) (1 diff)
- trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.js (modified) (10 diffs)
- trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.pack.js (deleted)
- trunk/midcom/midcom.helper.datamanager2/widget/chooser.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.helper.datamanager2/exec/chooser_handler.php
r14452 r14468 67 67 } 68 68 69 if (! empty($reflector_key))70 {71 $_MIDCOM->componentloader->load_graceful('midgard.admin.asgard'); 72 }69 // if (! empty($reflector_key)) 70 // { 71 // 72 // } 73 73 74 74 debug_pop(); trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.js
r14441 r14468 35 35 // }); 36 36 }, 37 midcom_helper_datamanager2_widget_chooser_add_result_item: function( item)38 { 39 return this.trigger("add_result_item",[ item]);37 midcom_helper_datamanager2_widget_chooser_add_result_item: function(data, item) 38 { 39 return this.trigger("add_result_item",[data, item]); 40 40 }, 41 41 midcom_helper_datamanager2_widget_chooser_remove_result_item: function(item_id) … … 79 79 insert_after = creation_dialog; 80 80 } 81 82 input_element.show(); 81 83 82 84 var results_holder = jQuery.midcom_helper_datamanager2_widget_chooser.ResultsHolder(options, input, insert_after, selectCurrent); … … 296 298 input_element.focus(); 297 299 results_holder.activate_item(data); 298 }).bind("add_result_item", function(event, item){299 results_holder.add_item( item);300 }).bind("add_result_item", function(event, data, item){ 301 results_holder.add_item(data, item); 300 302 }).bind("remove_result_item", function(event, item_id){ 301 303 results_holder.del_item(); … … 308 310 creation_dialog = jQuery('#' + options.widget_id + '_creation_dialog'); 309 311 create_button = jQuery('#' + options.widget_id + '_create_button'); 312 create_button.css('display', 'block'); 310 313 create_button.bind('click', function(){ 311 314 if (jQuery('#' + options.widget_id + '_creation_dialog').css('display') == 'block') … … 460 463 } 461 464 462 function add(data )465 function add(data, item) 463 466 { 464 467 // console.log('ResultsHolder add'); … … 468 471 469 472 var n=null; 470 jQuery.each( options.result_headers, function(i,n) {471 //console.log("data."+n.name+": "+data[n.name]);472 });473 473 474 474 var item_id = data[options.id_field]; 475 475 //console.log('options.id_field: '+options.id_field); 476 476 //console.log('item_id: '+item_id); 477 478 // var static_row = jQuery("#" + options.widget_id + "_existing_item_" + item_id + "_row"); 479 // if (typeof static_row[0] != 'undefined') 480 // { 481 // var static_input = jQuery("#" + options.widget_id + "_existing_item_" + item_id + "_input"); 482 // static_input.delete(); 483 // static_row.delete(); 484 // } 485 477 486 if (! can_add(item_id)) 478 487 { … … 483 492 //console.log("Can add!"); 484 493 485 if (! has_content)494 if (! has_content) 486 495 { 487 496 has_content = true; … … 550 559 } 551 560 552 if (options.renderer_callback) 561 if ( options.renderer_callback 562 && typeof item != 'undefined') 553 563 { 554 564 //console.log("use renderer"); 555 //TODO: Implement 556 // PONDER: How should we handle the renderer_callback rendering? 565 // PONDER: How should we really handle the renderer_callback rendering? 557 566 // We could use custom javascript function, or require the data 558 567 // object to contain a content field which is already formatted html... 559 var item_content = jQuery("<div>") 560 // .attr({ id: options.widget_id + '_result_item_'+data.id }) 561 // .html( midcom_helper_datamanager2_widget_chooser_format_item(data, options) ) 568 var item_content = jQuery("<div>").html(item) 569 .appendTo(li_elem); 570 var input_elem = jQuery("<input type=\"hidden\">") 571 .attr({ name: input_elem_name, value: 0, id: options.widget_id + '_result_item_'+item_id+'_input' }) 562 572 .appendTo(li_elem); 563 573 } … … 568 578 var input_elem = jQuery("<input type=\"hidden\">") 569 579 .attr({ name: input_elem_name, value: 0, id: options.widget_id + '_result_item_'+item_id+'_input' }) 570 .hide()571 580 .appendTo(li_elem); 572 581 } … … 734 743 dataToDom(); 735 744 }, 736 add_item: function( item)737 { 738 add( item);739 var item_id = item[options.id_field];745 add_item: function(data, item) 746 { 747 add(data, item); 748 var item_id = data[options.id_field]; 740 749 activate(item_id); 741 750 }, trunk/midcom/midcom.helper.datamanager2/widget/chooser.php
r14397 r14468 7 7 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License 8 8 */ 9 10 if (! class_exists('midcom_helper_reflector')) 11 { 12 $filename = MIDCOM_ROOT . "/midcom/helper/reflector.php"; 13 require_once($filename); 14 } 9 15 10 16 /** … … 283 289 */ 284 290 var $widget_elements = array(); 285 291 292 var $_static_items_html = ""; 293 var $_added_static_items = array(); 294 286 295 var $allow_multiple = true; 287 296 var $require_corresponding_option = true; … … 766 775 { 767 776 // debug_add("clever class {$this->clever_class} not found in predefined list. Trying to use reflector"); 768 $_MIDCOM->componentloader->load_graceful('midgard.admin.asgard');769 777 770 778 $matching_type = false; … … 817 825 } 818 826 819 $m aa_reflector =& new midgard_admin_asgard_reflector($matching_type);827 $midcom_reflector =& new midcom_helper_reflector($matching_type); 820 828 $mgd_reflector = new midgard_reflection_property($matching_type); 821 829 … … 846 854 if (empty($labels)) 847 855 { 848 $label_properties = $m aa_reflector->get_label_property();856 $label_properties = $midcom_reflector->get_label_property(); 849 857 // debug_print_r('$label_properties',$label_properties); 850 858 if (is_array($label_properties)) … … 874 882 if (empty($this->searchfields)) 875 883 { 876 $this->searchfields = $m aa_reflector->get_search_properties();884 $this->searchfields = $midcom_reflector->get_search_properties(); 877 885 if (empty($this->searchfields)) 878 886 { … … 885 893 } 886 894 887 $reflection_l10n =& $m aa_reflector->get_component_l10n();895 $reflection_l10n =& $midcom_reflector->get_component_l10n(); 888 896 if (empty($this->result_headers)) 889 897 { … … 1079 1087 'class' => 'shorttext chooser_widget_search_input', 1080 1088 'id' => "{$this->_element_id}_search_input", 1089 'style' => "display: none;", 1081 1090 ) 1082 1091 ); … … 1097 1106 $dialog_html .= '</div>'; 1098 1107 1099 $button_html = '<div class="chooser_widget_create_button" id="' . $this->_element_id . '_create_button" >';1108 $button_html = '<div class="chooser_widget_create_button" id="' . $this->_element_id . '_create_button" style="display: none;">'; 1100 1109 $button_html .= '</div>'; 1101 1110 … … 1143 1152 // debug_pop(); 1144 1153 1154 $this->_static_items_html = "<noscript>\n"; 1155 $this->_static_items_html .= "<table class=\"widget_chooser_static_items_table\">\n<thead><tr>\n"; 1156 1157 if ( !empty($this->reflector_key) 1158 && !$this->result_headers) 1159 { 1160 $title = $_MIDCOM->i18n->get_string('Label', 'midcom'); 1161 $this->_static_items_html .= " <th class=\"label\">{$title} </th>\n"; 1162 } 1163 else 1164 { 1165 foreach ($this->result_headers as $header_item) 1166 { 1167 $this->_static_items_html .= " <th class=\"{$header_item['name']}\">{$header_item['title']} </th>\n"; 1168 } 1169 } 1170 1171 $title = $_MIDCOM->i18n->get_string('Selected', 'midcom.helper.datamanager2'); 1172 $this->_static_items_html .= " <th class=\"selected\">{$title} </th>\n"; 1173 1174 $this->_static_items_html .= "</tr></thead>\n<tbody>\n"; 1175 1145 1176 $ee_script = ''; 1146 1177 if ($this->_renderer_callback) … … 1156 1187 // debug_add("Got item: {$item}"); 1157 1188 $ee_script .= "jQuery('#{$this->_element_id}_search_input').midcom_helper_datamanager2_widget_chooser_add_result_item({$data},'{$item}');\n"; 1189 1190 $this->_add_existing_item_as_static($key); 1158 1191 } 1159 1192 } … … 1164 1197 { 1165 1198 // debug_add("Processing key {$key}"); 1199 $this->_add_existing_item_as_static($key); 1166 1200 $data = $this->_get_key_data($key); 1167 1201 if ($data) … … 1169 1203 // debug_add("Got data: {$data}"); 1170 1204 $ee_script .= "jQuery('#{$this->_element_id}_search_input').midcom_helper_datamanager2_widget_chooser_add_result_item({$data});\n"; 1171 } 1172 } 1173 } 1205 1206 $this->_add_existing_item_as_static($key); 1207 } 1208 } 1209 } 1210 1174 1211 $this->_jscript .= $ee_script; 1175 1212 1176 1213 $this->_jscript .= '});'; 1177 1214 $this->_jscript .= '</script>'; 1215 1216 $this->_static_items_html .= "</tbody>\n"; 1217 $this->_static_items_html .= "</table>\n"; 1218 $this->_static_items_html .= "</noscript>\n"; 1178 1219 1179 1220 //$this->_form->addElement('static', "{$this->_element_id}_initscripts", '', $this->_jscript); … … 1186 1227 $this->_jscript 1187 1228 ); 1229 1230 $this->widget_elements[] =& HTML_QuickForm::createElement 1231 ( 1232 'static', 1233 "{$this->_element_id}_noscript", 1234 '', 1235 $this->_static_items_html 1236 ); 1188 1237 1189 1238 $group =& $this->_form->addGroup($this->widget_elements, $this->name, $this->_translate($this->_field['title']), '', array('class' => 'midcom_helper_datamanager2_widget_chooser')); 1239 } 1240 1241 function _add_existing_item_as_static($key) 1242 { 1243 $object =& $this->_get_key_data($key, false, true); 1244 $id_field = $this->id_field; 1245 $item_id = @$object->$id_field; 1246 1247 if ( empty($item_id) 1248 || isset($this->_added_static_items[$item_id])) 1249 { 1250 return; 1251 } 1252 1253 $this->_static_items_html .= "<tr id=\"{$this->_element_id}_existing_item_{$item_id}_row\" class=\"chooser_widget_existing_item_static_row\">\n"; 1254 1255 if ( !empty($this->reflector_key) 1256 && !$this->result_headers) 1257 { 1258 $value = @$object->get_label(); 1259 $value = rawurlencode($value); 1260 //debug_add("adding header item: name=label value={$value}"); 1261 $title = $_MIDCOM->i18n->get_string('label', 'midcom'); 1262 $this->_static_items_html .= "<td class=\"label\">{$value} </td>\n"; 1263 } 1264 else 1265 { 1266 foreach ($this->result_headers as $header_item) 1267 { 1268 $item_name = $header_item['name']; 1269 $value = @$object->$item_name; 1270 $value = rawurlencode(utf8_decode($value)); 1271 // debug_add("adding header item: name={$item_name} value={$value}"); 1272 // 1273 $this->_static_items_html .= "<td class=\"{$item_name}\">{$value} </td>"; 1274 } 1275 } 1276 1277 $this->_static_items_html .= "<td>\n"; 1278 $this->_static_items_html .= "<input type=\"checkbox\" name=\"{$this->_element_id}_selections[{$item_id}]\" id=\"{$this->_element_id}_existing_item_{$item_id}_value\" class=\"chooser_widget_existing_item_static_input\" checked=\"checked\"/>\n"; 1279 $this->_static_items_html .= "</td>\n"; 1280 1281 $this->_static_items_html .= "</tr>\n"; 1282 1283 $this->_added_static_items[$item_id] = true; 1190 1284 } 1191 1285 … … 1284 1378 } 1285 1379 1286 function _get_key_data($key, $in_render_mode=false )1380 function _get_key_data($key, $in_render_mode=false, $return_object=false) 1287 1381 { 1288 1382 // debug_push_class(__CLASS__, __FUNCTION__); … … 1359 1453 1360 1454 $_MIDCOM->auth->drop_sudo(); 1361 1455 1362 1456 // debug_pop(); 1457 1458 if ($return_object) 1459 { 1460 return $object; 1461 } 1363 1462 1364 1463 if ($in_render_mode)
