Changeset 12138
- Timestamp:
- 09/11/07 22:41:19 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.helper.datamanager2/widget/chooser.php
r12131 r12138 267 267 function _on_initialize() 268 268 { 269 debug_push_class(__CLASS__, __FUNCTION__);270 271 269 if (is_a('midcom_helper_datamanager2_type_select', $this->_type)) 272 270 { 271 debug_push_class(__CLASS__, __FUNCTION__); 273 272 debug_add("Warning, the field {$this->name} is not a select type or subclass thereoff, you cannot use the chooser widget with it.", 274 273 MIDCOM_LOG_WARN); … … 289 288 || empty($this->_callback_class)) 290 289 { 290 debug_push_class(__CLASS__, __FUNCTION__); 291 291 debug_add("Warning, the field {$this->name} does not have proper class definitions set.", 292 292 MIDCOM_LOG_WARN); … … 299 299 && !$this->_check_renderer()) 300 300 { 301 debug_push_class(__CLASS__, __FUNCTION__); 301 302 debug_add("Warning, the field {$this->name} renderer wasn't found or not set properly, thus widget can never show results.", 302 303 MIDCOM_LOG_WARN); … … 307 308 if (!$this->_check_class()) 308 309 { 310 debug_push_class(__CLASS__, __FUNCTION__); 309 311 debug_add("Warning, cannot load class {$this->class}.", 310 312 MIDCOM_LOG_WARN); … … 315 317 if (empty($this->class)) 316 318 { 319 debug_push_class(__CLASS__, __FUNCTION__); 317 320 debug_add("Warning, the field {$this->name} does not have class defined.", 318 321 MIDCOM_LOG_WARN); … … 323 326 if (empty($this->component)) 324 327 { 328 debug_push_class(__CLASS__, __FUNCTION__); 325 329 debug_add("Warning, the field {$this->name} does not have component the class {$this->class} belongs to defined.", 326 330 MIDCOM_LOG_WARN); … … 331 335 if (empty($this->searchfields)) 332 336 { 337 debug_push_class(__CLASS__, __FUNCTION__); 333 338 debug_add("Warning, the field {$this->name} does not have searchfields defined, it can never return results.", 334 339 MIDCOM_LOG_WARN); … … 358 363 359 364 $this->_init_widget_options(); 360 361 debug_pop(); 365 362 366 return true; 363 367 } … … 454 458 function _check_callback() 455 459 { 456 debug_push_class(__CLASS__, __FUNCTION__); 457 458 debug_add("Checking callback class {$this->_callback_class}"); 460 // debug_push_class(__CLASS__, __FUNCTION__); 461 // debug_add("Checking callback class {$this->_callback_class}"); 459 462 460 463 if (! class_exists($this->_callback_class)) … … 481 484 $this->_callback = new $this->_callback_class($this->_callback_args); 482 485 483 debug_pop();486 // debug_pop(); 484 487 return $this->_callback->initialize(); 485 488 } … … 487 490 function _check_clever_class() 488 491 { 489 debug_push_class(__CLASS__, __FUNCTION__);492 // debug_push_class(__CLASS__, __FUNCTION__); 490 493 491 494 $current_user = $_MIDCOM->auth->user->get_storage(); … … 606 609 if (array_key_exists($this->clever_class,$clever_classes)) 607 610 { 608 debug_add("clever class {$this->clever_class} found!");611 // debug_add("clever class {$this->clever_class} found!"); 609 612 610 613 $this->class = $clever_classes[$this->clever_class]['class']; … … 648 651 } 649 652 650 debug_pop();653 // debug_pop(); 651 654 return true; 652 655 } 653 656 else 654 657 { 655 debug_add("clever class {$this->clever_class} not found in predefined list. Trying to use reflector");658 // debug_add("clever class {$this->clever_class} not found in predefined list. Trying to use reflector"); 656 659 $_MIDCOM->componentloader->load_graceful('midgard.admin.asgard'); 657 660 … … 664 667 if ($pos !== false) 665 668 { 666 debug_add("found possible match: {$schema_type}");669 // debug_add("found possible match: {$schema_type}"); 667 670 $matched_types[] = $schema_type; 668 671 } 669 672 } 670 673 671 debug_print_r('$matched_types',$matched_types);674 // debug_print_r('$matched_types',$matched_types); 672 675 673 676 if (count($matched_types) == 1) … … 695 698 } 696 699 697 debug_print_r('Decided to go with',$matching_type);700 // debug_print_r('Decided to go with',$matching_type); 698 701 699 702 if (! $matching_type) 700 703 { 704 debug_push_class(__CLASS__, __FUNCTION__); 701 705 debug_add("no matches found for {$this->clever_class}!"); 702 706 debug_pop(); … … 711 715 $dummy_object = new $matching_type(); 712 716 $type_fields = array_keys(get_object_vars($dummy_object)); 713 debug_print_r('type_fields',$type_fields);717 // debug_print_r('type_fields',$type_fields); 714 718 715 719 unset($type_fields['metadata']); 716 720 foreach ($type_fields as $key) 717 721 { 718 debug_add("processing type field {$key}");722 // debug_add("processing type field {$key}"); 719 723 if ($mgd_reflector->is_link($key)) 720 724 { 721 debug_add("type field {$key} is link");725 // debug_add("type field {$key} is link"); 722 726 } 723 727 … … 734 738 { 735 739 $label_properties = $maa_reflector->get_label_property(); 736 debug_print_r('$label_properties',$label_properties);740 // debug_print_r('$label_properties',$label_properties); 737 741 if (is_array($label_properties)) 738 742 { … … 796 800 } 797 801 798 debug_add("using class: {$this->class}");802 /*debug_add("using class: {$this->class}"); 799 803 debug_add("using component: {$this->component}"); 800 804 debug_print_r('$this->searchfields',$this->searchfields); 801 805 debug_print_r('$this->result_headers',$this->result_headers); 802 806 803 debug_pop(); 807 debug_pop();*/ 804 808 return true; 805 809 } 806 810 807 debug_pop();811 //debug_pop(); 808 812 return false; 809 813 } … … 865 869 $this->_js_widget_options['result_headers'] = $headers; 866 870 867 debug_push_class(__CLASS__, __FUNCTION__);871 /*debug_push_class(__CLASS__, __FUNCTION__); 868 872 debug_add("js result_headers: {$headers}"); 869 debug_pop(); 873 debug_pop();*/ 870 874 871 875 $this->_generate_extra_params(); … … 901 905 function add_elements_to_form() 902 906 { 903 debug_push_class(__CLASS__, __FUNCTION__); 907 // debug_push_class(__CLASS__, __FUNCTION__); 908 904 909 // Get url to search handler 905 910 $nav = new midcom_helper_nav(); … … 956 961 $dialog_html = '<div class="chooser_widget_creation_dialog" id="' . $dialog_id . '">'; 957 962 $dialog_html .= '<div class="chooser_widget_creation_dialog_content_holder">'; 958 //$dialog_html .= '<img class="chooser_widget_creation_dialog_loading" src="' . MIDCOM_STATIC_URL . '/midcom.helper.datamanager2/ajax-loading.gif" alt="" />';959 //$dialog_html .= '<iframe width="450" height="500" class="chooser_widget_creation_dialog_content" src="">';960 //$dialog_html .= '</iframe>';961 963 $dialog_html .= $dialog_js; 962 964 $dialog_html .= '</div>'; … … 974 976 '', 975 977 $html 976 ); 977 } 978 979 $group =& $this->_form->addGroup($this->widget_elements, $this->_element_id, $this->_translate($this->_field['title']), '', array('class' => 'chooser_widget_group')); 980 $group->setAttributes( 981 array('class' => 'midcom_helper_datamanager2_widget_chooser') 982 ); 978 ); 979 } 983 980 984 981 $this->_jscript .= '<script type="text/javascript">'; … … 1005 1002 // Add existing and static selections 1006 1003 $existing_elements = $this->_type->selection; 1007 debug_print_r('existing_elements',$existing_elements);1008 1009 debug_print_r('static_options',$this->static_options);1004 // debug_print_r('existing_elements',$existing_elements); 1005 1006 // debug_print_r('static_options',$this->static_options); 1010 1007 1011 1008 $elements = array_merge($this->static_options,$existing_elements); 1012 debug_print_r('all elements to be added',$elements);1009 // debug_print_r('all elements to be added',$elements); 1013 1010 1014 1011 $ee_script = ''; … … 1017 1014 foreach ($elements as $key) 1018 1015 { 1019 debug_add("Passing key to renderer {$key}");1016 // debug_add("Passing key to renderer {$key}"); 1020 1017 $data = $this->_get_key_data($key); 1021 1018 if ($data) 1022 1019 { 1023 debug_add("Got data: {$data}");1020 // debug_add("Got data: {$data}"); 1024 1021 $item = $this->_renderer_callback->render_data($data); 1025 debug_add("Got item: {$item}");1022 // debug_add("Got item: {$item}"); 1026 1023 $ee_script .= "jQuery('#{$this->_element_id}_search_input').midcom_helper_datamanager2_widget_chooser_add_result_item({$data},'{$item}');\n"; 1027 1024 } … … 1032 1029 foreach ($elements as $key) 1033 1030 { 1034 debug_add("Processing key {$key}");1031 // debug_add("Processing key {$key}"); 1035 1032 $data = $this->_get_key_data($key); 1036 1033 if ($data) 1037 1034 { 1038 debug_add("Got data: {$data}");1035 // debug_add("Got data: {$data}"); 1039 1036 $ee_script .= "jQuery('#{$this->_element_id}_search_input').midcom_helper_datamanager2_widget_chooser_add_result_item({$data});\n"; 1040 1037 } … … 1046 1043 $this->_jscript .= '</script>'; 1047 1044 1048 $this->_form->addElement('static', "{$this->_element_id}_initscripts", '', $this->_jscript); 1045 //$this->_form->addElement('static', "{$this->_element_id}_initscripts", '', $this->_jscript); 1046 1047 $this->widget_elements[] =& HTML_QuickForm::createElement 1048 ( 1049 'static', 1050 "{$this->_element_id}_initscripts", 1051 '', 1052 $this->_jscript 1053 ); 1054 1055 $group =& $this->_form->addGroup($this->widget_elements, $this->name, $this->_translate($this->_field['title']), '', array('class' => 'midcom_helper_datamanager2_widget_chooser')); 1049 1056 } 1050 1057 1051 1058 function _resolve_object_name(&$object) 1052 1059 { 1053 debug_push_class(__CLASS__, __FUNCTION__);1054 debug_add("resolving object name from id {$object->id}");1060 // debug_push_class(__CLASS__, __FUNCTION__); 1061 // debug_add("resolving object name from id {$object->id}"); 1055 1062 1056 1063 $name = @$object->get_label(); … … 1079 1086 function _object_to_jsdata(&$object) 1080 1087 { 1081 debug_push_class(__CLASS__, __FUNCTION__); 1082 1083 debug_add("converting object with id {$object->id} to jsdata"); 1088 // debug_push_class(__CLASS__, __FUNCTION__); 1089 // debug_add("converting object with id {$object->id} to jsdata"); 1084 1090 1085 1091 $id = @$object->id; … … 1097 1103 $value = @$object->get_label(); 1098 1104 $value = rawurlencode($value); 1099 debug_add("adding header item: name=label value={$value}");1105 // debug_add("adding header item: name=label value={$value}"); 1100 1106 $jsdata .= "label: '{$value}'"; 1101 1107 } … … 1109 1115 $value = @$object->$item_name; 1110 1116 $value = rawurlencode($value); 1111 debug_add("adding header item: name={$item_name} value={$value}");1117 // debug_add("adding header item: name={$item_name} value={$value}"); 1112 1118 $jsdata .= "{$item_name}: '{$value}'"; 1113 1119 … … 1125 1131 return $jsdata; 1126 1132 1127 debug_pop();1133 // debug_pop(); 1128 1134 } 1129 1135 1130 1136 function _get_key_data($key, $in_render_mode=false) 1131 1137 { 1132 debug_push_class(__CLASS__, __FUNCTION__); 1133 1134 debug_add("get_key_data for key: {$key}"); 1138 // debug_push_class(__CLASS__, __FUNCTION__); 1139 // debug_add("get_key_data for key: {$key}"); 1135 1140 1136 1141 if ($this->_callback) 1137 1142 { 1138 debug_add("Using callback to fetch key data");1143 // debug_add("Using callback to fetch key data"); 1139 1144 1140 1145 if ($in_render_mode) 1141 1146 { 1142 debug_pop();1147 // debug_pop(); 1143 1148 return $_callback->resolve_object_name($key); 1144 1149 } … … 1151 1156 } 1152 1157 1153 debug_pop();1158 // debug_pop(); 1154 1159 1155 1160 if ($this->_renderer_callback) … … 1161 1166 } 1162 1167 1163 debug_add("Using clever class or predefined class");1168 // debug_add("Using clever class or predefined class"); 1164 1169 1165 1170 $_MIDCOM->auth->request_sudo(); … … 1183 1188 if (! $qb) 1184 1189 { 1185 debug_add("use midgard_query_builder");1190 // debug_add("use midgard_query_builder"); 1186 1191 $qb = new midgard_query_builder($this->class); 1187 1192 } … … 1194 1199 $results = $qb->execute(); 1195 1200 1196 debug_print_r("Got results:",$results);1201 // debug_print_r("Got results:",$results); 1197 1202 1198 1203 if (count($results) == 0) 1199 1204 { 1200 debug_add("Fetching data for key '{$key}' failed.");1205 // debug_add("Fetching data for key '{$key}' failed."); 1201 1206 return false; 1202 1207 } … … 1206 1211 $_MIDCOM->auth->drop_sudo(); 1207 1212 1208 debug_pop();1213 // debug_pop(); 1209 1214 1210 1215 if ($in_render_mode) … … 1242 1247 function get_default() 1243 1248 { 1244 debug_push_class(__CLASS__, __FUNCTION__); 1245 1249 // debug_push_class(__CLASS__, __FUNCTION__); 1246 1250 //debug_print_r('this->_type',$this->_type); 1247 1251 … … 1252 1256 } 1253 1257 1254 debug_print_r('defaults',$defaults); 1258 // debug_print_r('defaults',$defaults); 1259 // debug_pop(); 1255 1260 1256 debug_pop();1257 1261 return Array($this->name => $defaults); 1258 1262 } … … 1263 1267 function sync_type_with_widget($results) 1264 1268 { 1265 debug_push_class(__CLASS__, __FUNCTION__); 1266 1267 debug_print_r('results:',$results); 1269 // debug_push_class(__CLASS__, __FUNCTION__); 1270 // debug_print_r('results:',$results); 1268 1271 1269 1272 $this->_type->selection = array(); … … 1276 1279 foreach ($real_results as $key => $value) 1277 1280 { 1278 debug_add("checking key {$key} with value ".var_dump($value));1281 // debug_add("checking key {$key} with value ".var_dump($value)); 1279 1282 if ( $value != "0" 1280 1283 || $value != 0) 1281 1284 { 1282 debug_add("adding key {$key} to selection");1285 // debug_add("adding key {$key} to selection"); 1283 1286 $this->_type->selection[] = $key; 1284 1287 } 1285 1288 } 1286 1289 1287 debug_print_r('real_results', $real_results); 1288 debug_print_r('_type->selection', $this->_type->selection); 1289 1290 debug_pop(); 1290 // debug_print_r('real_results', $real_results); 1291 // debug_print_r('_type->selection', $this->_type->selection); 1292 // debug_pop(); 1291 1293 } 1292 1294 1293 1295 function render_content() 1294 1296 { 1295 debug_push_class(__CLASS__, __FUNCTION__);1297 // debug_push_class(__CLASS__, __FUNCTION__); 1296 1298 1297 1299 echo '<ul>'; … … 1302 1304 else 1303 1305 { 1304 debug_add("We have selections!");1306 // debug_add("We have selections!"); 1305 1307 1306 1308 foreach ($this->_type->selection as $key) … … 1312 1314 echo '</ul>'; 1313 1315 1314 debug_pop();1316 // debug_pop(); 1315 1317 } 1316 1318
