Changeset 14468

Show
Ignore:
Timestamp:
01/17/08 13:44:21 (11 months ago)
Author:
w_i
Message:

Added simple noscript support

Files:

Legend:

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

    r14452 r14468  
    6767} 
    6868 
    69 if (! empty($reflector_key)) 
    70 
    71     $_MIDCOM->componentloader->load_graceful('midgard.admin.asgard'); 
    72 
     69// if (! empty($reflector_key)) 
     70//
     71//      
     72//
    7373 
    7474debug_pop(); 
  • trunk/midcom/midcom.helper.datamanager2/static/chooser/jquery.chooser_widget.js

    r14441 r14468  
    3535        // }); 
    3636    }, 
    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]); 
    4040    }, 
    4141    midcom_helper_datamanager2_widget_chooser_remove_result_item: function(item_id) 
     
    7979        insert_after = creation_dialog; 
    8080    } 
     81     
     82    input_element.show(); 
    8183     
    8284    var results_holder = jQuery.midcom_helper_datamanager2_widget_chooser.ResultsHolder(options, input, insert_after, selectCurrent);     
     
    296298        input_element.focus(); 
    297299        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); 
    300302    }).bind("remove_result_item", function(event, item_id){ 
    301303        results_holder.del_item(); 
     
    308310        creation_dialog = jQuery('#' + options.widget_id + '_creation_dialog'); 
    309311        create_button = jQuery('#' + options.widget_id + '_create_button'); 
     312        create_button.css('display', 'block'); 
    310313        create_button.bind('click', function(){ 
    311314            if (jQuery('#' + options.widget_id + '_creation_dialog').css('display') == 'block') 
     
    460463    } 
    461464     
    462     function add(data
     465    function add(data, item
    463466    { 
    464467        // console.log('ResultsHolder add'); 
     
    468471         
    469472        var n=null; 
    470         jQuery.each( options.result_headers, function(i,n) { 
    471             //console.log("data."+n.name+": "+data[n.name]); 
    472         }); 
    473473         
    474474        var item_id = data[options.id_field]; 
    475475        //console.log('options.id_field: '+options.id_field); 
    476476        //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         
    477486        if (! can_add(item_id)) 
    478487        { 
     
    483492        //console.log("Can add!"); 
    484493         
    485         if (!has_content) 
     494        if (! has_content) 
    486495        { 
    487496            has_content = true; 
     
    550559        }         
    551560         
    552         if (options.renderer_callback) 
     561        if (   options.renderer_callback 
     562            && typeof item != 'undefined') 
    553563        { 
    554564            //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? 
    557566            //          We could use custom javascript function, or require the data 
    558567            //          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' }) 
    562572            .appendTo(li_elem); 
    563573        } 
     
    568578            var input_elem = jQuery("<input type=\"hidden\">") 
    569579            .attr({ name: input_elem_name, value: 0, id: options.widget_id + '_result_item_'+item_id+'_input' }) 
    570             .hide() 
    571580            .appendTo(li_elem); 
    572581        } 
     
    734743            dataToDom(); 
    735744        }, 
    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]; 
    740749            activate(item_id); 
    741750        }, 
  • trunk/midcom/midcom.helper.datamanager2/widget/chooser.php

    r14397 r14468  
    77 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License 
    88 */ 
     9 
     10if (! class_exists('midcom_helper_reflector')) 
     11{ 
     12    $filename = MIDCOM_ROOT . "/midcom/helper/reflector.php"; 
     13    require_once($filename); 
     14} 
    915 
    1016/** 
     
    283289     */ 
    284290    var $widget_elements = array(); 
    285  
     291     
     292    var $_static_items_html = ""; 
     293    var $_added_static_items = array(); 
     294     
    286295    var $allow_multiple = true; 
    287296    var $require_corresponding_option = true; 
     
    766775        { 
    767776            // debug_add("clever class {$this->clever_class} not found in predefined list. Trying to use reflector"); 
    768             $_MIDCOM->componentloader->load_graceful('midgard.admin.asgard'); 
    769777 
    770778            $matching_type = false; 
     
    817825            } 
    818826 
    819             $maa_reflector =& new midgard_admin_asgard_reflector($matching_type); 
     827            $midcom_reflector =& new midcom_helper_reflector($matching_type); 
    820828            $mgd_reflector = new midgard_reflection_property($matching_type); 
    821829 
     
    846854            if (empty($labels)) 
    847855            { 
    848                 $label_properties = $maa_reflector->get_label_property(); 
     856                $label_properties = $midcom_reflector->get_label_property(); 
    849857                // debug_print_r('$label_properties',$label_properties); 
    850858                if (is_array($label_properties)) 
     
    874882            if (empty($this->searchfields)) 
    875883            { 
    876                 $this->searchfields = $maa_reflector->get_search_properties(); 
     884                $this->searchfields = $midcom_reflector->get_search_properties(); 
    877885                if (empty($this->searchfields)) 
    878886                { 
     
    885893            } 
    886894 
    887             $reflection_l10n =& $maa_reflector->get_component_l10n(); 
     895            $reflection_l10n =& $midcom_reflector->get_component_l10n(); 
    888896            if (empty($this->result_headers)) 
    889897            { 
     
    10791087                'class'         => 'shorttext chooser_widget_search_input', 
    10801088                'id'            => "{$this->_element_id}_search_input", 
     1089                'style'         => "display: none;", 
    10811090            ) 
    10821091        ); 
     
    10971106            $dialog_html .= '</div>'; 
    10981107 
    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;">'; 
    11001109            $button_html .= '</div>'; 
    11011110 
     
    11431152        // debug_pop(); 
    11441153 
     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}&nbsp;</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']}&nbsp;</th>\n"; 
     1168            }             
     1169        } 
     1170         
     1171        $title = $_MIDCOM->i18n->get_string('Selected', 'midcom.helper.datamanager2'); 
     1172        $this->_static_items_html .= "    <th class=\"selected\">{$title}&nbsp;</th>\n"; 
     1173         
     1174        $this->_static_items_html .= "</tr></thead>\n<tbody>\n"; 
     1175         
    11451176        $ee_script = ''; 
    11461177        if ($this->_renderer_callback) 
     
    11561187                    // debug_add("Got item: {$item}"); 
    11571188                    $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); 
    11581191                } 
    11591192            } 
     
    11641197            { 
    11651198                // debug_add("Processing key {$key}"); 
     1199                $this->_add_existing_item_as_static($key); 
    11661200                $data = $this->_get_key_data($key); 
    11671201                if ($data) 
     
    11691203                    // debug_add("Got data: {$data}"); 
    11701204                    $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         
    11741211        $this->_jscript .= $ee_script; 
    11751212 
    11761213        $this->_jscript .= '});'; 
    11771214        $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"; 
    11781219 
    11791220        //$this->_form->addElement('static', "{$this->_element_id}_initscripts", '', $this->_jscript); 
     
    11861227            $this->_jscript 
    11871228        ); 
     1229         
     1230        $this->widget_elements[] =& HTML_QuickForm::createElement 
     1231        ( 
     1232            'static', 
     1233            "{$this->_element_id}_noscript", 
     1234            '', 
     1235            $this->_static_items_html 
     1236        ); 
    11881237 
    11891238        $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}&nbsp;</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}&nbsp;</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; 
    11901284    } 
    11911285 
     
    12841378    } 
    12851379 
    1286     function _get_key_data($key, $in_render_mode=false
     1380    function _get_key_data($key, $in_render_mode=false, $return_object=false
    12871381    { 
    12881382        // debug_push_class(__CLASS__, __FUNCTION__); 
     
    13591453 
    13601454        $_MIDCOM->auth->drop_sudo(); 
    1361  
     1455         
    13621456        // debug_pop(); 
     1457 
     1458        if ($return_object) 
     1459        { 
     1460            return $object; 
     1461        } 
    13631462 
    13641463        if ($in_render_mode)