Changeset 17864

Show
Ignore:
Timestamp:
10/02/08 14:15:36 (2 months ago)
Author:
adrenalin
Message:

Forward-porting r17862.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.helper.datamanager2/exec/chooser_handler.php

    r17304 r17864  
    5050); 
    5151$extra_params = unserialize(base64_decode($_REQUEST['extra_params'])); 
     52 
    5253debug_print_r('extra params', $extra_params); 
     54 
    5355foreach ($map as $map_key) 
    5456{ 
     
    127129    // debug_add("Using class: {$class}"); 
    128130     
    129     $_MIDCOM->componentloader->load_graceful($component); 
    130  
     131    // Load component if required 
     132    if (!class_exists($class)) 
     133    { 
     134        $_MIDCOM->componentloader->load_graceful($component); 
     135    } 
    131136    // Could not get required class defined, abort 
    132137    if (!class_exists($class)) 
     
    206211        } 
    207212    } 
     213     
    208214    $results = $qb->execute(); 
    209215    if ($results === false) 
     
    288294        { 
    289295            $item_name = $header_item['name']; 
    290             $value = @$object->$item_name; 
    291  
     296             
     297            if (preg_match('/^metadata\.(.+)$/', $item_name, $regs)) 
     298            { 
     299                $metadata_property = $regs[1]; 
     300                $value = @$object->metadata->$metadata_property; 
     301                 
     302                switch ($metadata_property) 
     303                { 
     304                    case 'created': 
     305                    case 'revised': 
     306                    case 'published': 
     307                    case 'schedulestart': 
     308                    case 'scheduleend': 
     309                    case 'imported': 
     310                    case 'exported': 
     311                    case 'approved': 
     312                        if ($value) 
     313                        { 
     314                            $value = strftime('%x %X', $value); 
     315                        } 
     316                        break; 
     317                     
     318                    case 'creator': 
     319                    case 'revisor': 
     320                    case 'approver': 
     321                    case 'locker': 
     322                        if ($value) 
     323                        { 
     324                            $person = new midcom_db_person($value); 
     325                            $value = $person->name; 
     326                        } 
     327                        break; 
     328                } 
     329            } 
     330            else 
     331            { 
     332                $value = @$object->$item_name; 
     333            } 
     334             
    292335            if (   $generate_path_for == $item_name 
    293336                || (   $class == 'midcom_db_topic' 
     
    298341                $value = resolve_path($object->id, $class, $value); 
    299342            } 
     343             
     344            $item_name = str_replace('.', '_', $item_name); 
    300345 
    301346            debug_add("adding header item: name={$item_name} value={$value}"); 
     
    324369    $result_components = array(); 
    325370     
    326     if ($class == 'midcom_db_topic') 
    327     { 
    328         $id = $object_id; 
    329         $last_name = ''; 
    330         while ($id != 0) 
    331         { 
    332             $mc = midcom_db_topic::new_collector('id', $id); 
    333             $mc->add_value_property('extra'); 
    334             $mc->add_value_property('up'); 
    335             $mc->add_value_property('name'); 
     371    switch ($class) 
     372    { 
     373        case 'midcom_db_article': 
     374        case 'midcom_baseclaases_database_article': 
     375            $result_components[] = $title; 
     376             
     377            // Get the owner topic 
     378            $mc = midcom_db_article::new_collector('id', $object_id); 
     379            $mc->add_value_property('topic'); 
    336380            $mc->execute(); 
    337             $topics = $mc->list_keys(); 
    338  
    339             if (! $topics) 
    340             { 
    341                 $id = 0; 
    342                 $rc_count = count($result_components); 
    343                 $result_components[$rc_count-1] = $last_name; 
    344                 break; 
    345             } 
    346  
    347             foreach ($topics as $topic_guid => $value) 
    348             { 
    349                 $id = $mc->get_subkey($topic_guid, 'up'); 
    350                 $last_name = $mc->get_subkey($topic_guid, 'name'); 
     381            $keys = $mc->list_keys(); 
     382             
     383            foreach ($keys as $guid => $array) 
     384            { 
     385                $id = $mc->get_subkey($guid, 'topic'); 
     386            } 
     387             
     388            // Fall through 
     389             
     390        case 'midcom_db_topic': 
     391            if (!isset($id)) 
     392            { 
     393                $id = $object_id; 
     394            } 
     395             
     396            $last_name = ''; 
     397            while ($id != 0) 
     398            { 
     399                $mc = midcom_db_topic::new_collector('id', $id); 
     400                $mc->add_value_property('extra'); 
     401                $mc->add_value_property('up'); 
     402                $mc->add_value_property('name'); 
     403                $mc->execute(); 
     404                $topics = $mc->list_keys(); 
     405     
     406                if (! $topics) 
     407                { 
     408                    $id = 0; 
     409                    $rc_count = count($result_components); 
     410                    $result_components[$rc_count-1] = $last_name; 
     411                    break; 
     412                } 
     413     
     414                foreach ($topics as $topic_guid => $value) 
     415                { 
     416                    $id = $mc->get_subkey($topic_guid, 'up'); 
     417                    $last_name = $mc->get_subkey($topic_guid, 'name'); 
     418                     
     419                    if ($id == 0) 
     420                    { 
     421                        $result_components[] = $last_name; 
     422                    } 
     423                    else 
     424                    { 
     425                        $result_components[] = $mc->get_subkey($topic_guid, 'extra'); 
     426                    } 
     427                } 
     428            } 
     429            break; 
     430         
     431        case 'midcom_db_group': 
     432        case 'midcom_baseclasses_database_group': 
     433            $result_components[] = $title; 
     434             
     435            $id = $object_id; 
     436            while ($id != 0) 
     437            { 
     438                $mc = midcom_db_group::new_collector('id', $id); 
     439                $mc->add_value_property('name'); 
     440                $mc->add_value_property('owner'); 
     441                $mc->execute(); 
     442                $groups = $mc->list_keys(); 
    351443                 
    352                 if ($id == 0
     444                if (! $groups
    353445                { 
    354                     $result_components[] = $last_name; 
     446                    $id = 0; 
     447                    break; 
    355448                } 
    356                 else 
     449     
     450                foreach ($groups as $group_guid => $value) 
    357451                { 
    358                     $result_components[] = $mc->get_subkey($topic_guid, 'extra'); 
     452                    if ($object_id != $id) 
     453                    { 
     454                        $result_components[] = $mc->get_subkey($group_guid, 'name'); 
     455                    } 
     456                    $id = $mc->get_subkey($group_guid, 'owner'); 
    359457                } 
    360458            } 
    361         }         
    362     } 
    363     else if (   $class == 'midcom_db_group' 
    364              || $class == 'midcom_baseclasses_database_group') 
    365     { 
    366         $result_components[] = $title; 
    367          
    368         $id = $object_id; 
    369         while ($id != 0) 
    370         { 
    371             $mc = midcom_db_group::new_collector('id', $id); 
    372             $mc->add_value_property('name'); 
    373             $mc->add_value_property('owner'); 
    374             $mc->execute(); 
    375             $groups = $mc->list_keys(); 
    376              
    377             if (! $groups) 
    378             { 
    379                 $id = 0; 
    380                 break; 
    381             } 
    382  
    383             foreach ($groups as $group_guid => $value) 
    384             { 
    385                 if ($object_id != $id) 
    386                 { 
    387                     $result_components[] = $mc->get_subkey($group_guid, 'name'); 
    388                 } 
    389                 $id = $mc->get_subkey($group_guid, 'owner'); 
    390             } 
    391         } 
    392     } 
     459            break; 
     460    } 
     461     
    393462     
    394463    if (empty($result_components)) 
  • trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.js

    r16617 r17864  
    527527        jQuery.each( options.result_headers, function(i,n) 
    528528        { 
     529            n.name = n.name.replace(/\./, '_'); 
     530             
    529531            var li_elem = jQuery('<li>') 
    530532                .addClass('chooser_widget_header_item') 
  • trunk/midcom/midcom.helper.datamanager2/widget/chooser.php

    r17835 r17864  
    88 */ 
    99 
    10 $_MIDCOM->load_library('midcom.helper.reflector'); 
     10if (! class_exists('midcom_helper_reflector')) 
     11
     12    $_MIDCOM->load_library('midcom.helper.reflector'); 
     13
    1114 
    1215/** 
     
    3134 *     'type_config' => array 
    3235 *     ( 
    33  *          'require_corresponding_option' => false, 
     36 *          'require_corresponding_option' => false, 
    3437 *          'allow_multiple' => true, 
    3538 *          'multiple_storagemode' => 'array', 
     
    131134     * Example: 
    132135     * <code> 
    133      *     'constraints' => array ( 
    134      *         array( 
     136     *     'constraints' => array 
     137     *     ( 
     138     *         array 
     139     *         ( 
    135140     *             'field' => 'username', 
    136141     *             'op' => '<>', 
     
    173178     * Example: 
    174179     * <code> 
    175      *      'searchfields' => array('firstname', 'lastname', 'email', 'username'), 
     180     *      'searchfields' => array 
     181     *      ( 
     182     *          'firstname', 
     183     *          'lastname', 
     184     *          'email', 
     185     *          'username' 
     186     *      ), 
    176187     * </code> 
    177188     * 
     
    185196     * Example: 
    186197     * <code> 
    187      *     'orders' => array(array('lastname' => 'ASC'), array('firstname' => 'ASC')), 
     198     *     'orders' => array 
     199     *     ( 
     200     *         array 
     201     *         ( 
     202     *             'lastname' => 'ASC', 
     203     *         ), 
     204     *         array 
     205     *         ( 
     206     *             'firstname' => 'ASC', 
     207     *         ) 
     208     *     ), 
    188209     * </code> 
    189210     * 
     
    384405        $_MIDCOM->enable_jquery(); 
    385406 
    386         $_MIDCOM->add_link_head( 
    387             array( 
     407        $_MIDCOM->add_link_head 
     408        ( 
     409            array 
     410            ( 
    388411                'rel' => 'stylesheet', 
    389412                'type' => 'text/css', 
     
    968991        $this->_js_widget_options['format_items'] = 'null'; 
    969992         
     993        if ($this->generate_path_for) 
     994        { 
     995            $this->_js_widget_options['generate_path_for'] = "'{$this->generate_path_for}'"; 
     996        } 
     997         
    970998        if ($this->sortable) 
    971999        { 
     
    10561084            '_renderer_callback_class', '_renderer_callback_args', 
    10571085            'constraints', 'searchfields', 'orders', 
    1058             'result_headers', 
     1086            'result_headers', 'generate_path_for', 
    10591087            'auto_wildcards', 
    10601088            'reflector_key' 
     
    10691097 
    10701098        $this->_js_widget_options['extra_params'] = "'" . base64_encode(serialize($params)) . "'"; 
     1099    } 
     1100 
     1101    /** 
     1102     * Internal helper for parsing the $_REQUEST data for including the elements requested via GET or POST 
     1103     * 
     1104     * @access private 
     1105     * @return Array 
     1106     */ 
     1107    function _get_request_elements() 
     1108    { 
     1109        $results = array(); 
     1110         
     1111        // No results available 
     1112        if (!isset($_REQUEST["{$this->_element_id}_selections"])) 
     1113        { 
     1114            return $results; 
     1115        } 
     1116         
     1117        foreach ($_REQUEST["{$this->_element_id}_selections"] as $guid => $value) 
     1118        { 
     1119            if (!$value) 
     1120            { 
     1121                continue; 
     1122            } 
     1123             
     1124            $results[$guid] = $value; 
     1125        } 
     1126         
     1127        return $results; 
    10711128    } 
    10721129 
     
    11701227        $existing_elements = $this->_type->selection; 
    11711228 
     1229        // Add to existing elements the ones requested (POST/GET) to this page 
     1230        $new_elements = $this->_get_request_elements(); 
     1231 
    11721232        //debug_print_r('existing_elements',$existing_elements); 
    11731233 
    11741234        // debug_print_r('static_options',$this->static_options); 
    11751235 
    1176         $elements = array_merge($this->static_options, $existing_elements); 
     1236        $elements = array_merge($this->static_options, $existing_elements, $new_elements); 
    11771237        // debug_print_r('all elements to be added',$elements); 
    11781238        // debug_pop(); 
    11791239 
    11801240        // $this->_static_items_html = "<noscript>\n";         
    1181         $this->_static_items_html .= "<table class=\"widget_chooser_static_items_table\">\n<thead><tr>\n"; 
     1241        $this->_static_items_html .= "<table class=\"widget_chooser_static_items_table\">\n"; 
     1242        $this->_static_items_html .= "    <thead>\n"; 
     1243        $this->_static_items_html .= "        <tr>\n"; 
    11821244         
    11831245        if (   !empty($this->reflector_key) 
     
    11851247        { 
    11861248            $title = $_MIDCOM->i18n->get_string('Label', 'midcom'); 
    1187             $this->_static_items_html .= "    <th class=\"label\">{$title}&nbsp;</th>\n"; 
     1249            $this->_static_items_html .= "            <th class=\"label\">{$title}&nbsp;</th>\n"; 
    11881250        } 
    11891251        else 
     
    11911253            foreach ($this->result_headers as $header_item) 
    11921254            { 
    1193                 $this->_static_items_html .= "    <th class=\"{$header_item['name']}\">{$header_item['title']}&nbsp;</th>\n"; 
     1255                $this->_static_items_html .= "            <th class=\"{$header_item['name']}\">{$header_item['title']}&nbsp;</th>\n"; 
    11941256            }             
    11951257        } 
    11961258         
    11971259        $title = $_MIDCOM->i18n->get_string('Selected', 'midcom.helper.datamanager2'); 
    1198         $this->_static_items_html .= "    <th class=\"selected\">{$title}&nbsp;</th>\n"; 
    1199          
    1200         $this->_static_items_html .= "</tr></thead>\n<tbody>\n"; 
     1260        $this->_static_items_html .= "            <th class=\"selected\">{$title}&nbsp;</th>\n"; 
     1261        $this->_static_items_html .= "        </tr>\n"; 
     1262        $this->_static_items_html .= "    </thead>\n"; 
     1263        $this->_static_items_html .= "    <tbody>\n"; 
    12011264         
    12021265        $ee_script = ''; 
     
    12281291                { 
    12291292                    // debug_add("Got data: {$data}"); 
    1230                     $ee_script .= "\njQuery('#{$this->_element_id}_search_input').midcom_helper_datamanager2_widget_chooser_add_result_item({$data});\n"; 
     1293                    $ee_script .= "\n"; 
     1294                    $ee_script .= "jQuery('#{$this->_element_id}_search_input')\n"; 
     1295                    $ee_script .= ".midcom_helper_datamanager2_widget_chooser_add_result_item(\n"; 
     1296                    $ee_script .= "    {$data},\n"; 
     1297                    $ee_script .= "    this\n"; 
     1298                    $ee_script .= ");\n"; 
    12311299 
    12321300                    $this->_add_existing_item_as_static($key); 
     
    12371305        $this->_jscript .= $ee_script; 
    12381306        $this->_jscript .= '});'; 
     1307         
     1308        $this->_jscript .= "\nclose_dialog = function(widget_id){jQuery('#' + widget_id + '_creation_dialog').hide();};"; 
     1309        $this->_jscript .= "\nadd_item = function(data, widget_id){jQuery('#' + widget_id + '_search_input').midcom_helper_datamanager2_widget_chooser_add_result_item(data);};"; 
     1310         
    12391311        $this->_jscript .= '</script>'; 
    12401312 
    1241         $this->_static_items_html .= "</tbody>\n"; 
     1313        $this->_static_items_html .= "    </tbody>\n"; 
    12421314        $this->_static_items_html .= "</table>\n"; 
    12431315        // $this->_static_items_html .= "</noscript>\n"; 
     
    13851457                $value = rawurlencode(utf8_decode($value)); 
    13861458                // debug_add("adding header item: name={$item_name} value={$value}"); 
    1387                 $jsdata .= "{$item_name}: '{$value}'"; 
     1459                 
     1460                $tmp = str_replace('.', '_', $item_name); 
     1461                 
     1462                $jsdata .= "{$tmp}: '{$value}'"; 
    13881463 
    13891464                if ($i < $hi_count)