http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94055
Revision: 94055 Author: devayon Date: 2011-08-08 11:26:18 +0000 (Mon, 08 Aug 2011) Log Message: ----------- follow-up:r93878 (stable) Modified Paths: -------------- trunk/extensions/SemanticMediaWiki/skins/SMW_custom.css trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php Modified: trunk/extensions/SemanticMediaWiki/skins/SMW_custom.css =================================================================== --- trunk/extensions/SemanticMediaWiki/skins/SMW_custom.css 2011-08-08 11:11:02 UTC (rev 94054) +++ trunk/extensions/SemanticMediaWiki/skins/SMW_custom.css 2011-08-08 11:26:18 UTC (rev 94055) @@ -133,6 +133,7 @@ /* ui buttons for QueryUI */ .smw-sort input, .smw-sort a, .smw-sort select, .smw-sort checkbox{ margin-left: 5px; + margin-bottom: 5px; } span.smw-remove a img{ text-decoration: none; @@ -140,7 +141,12 @@ vertical-align: -3px; } +.smw-prop-dialog input, .smw-prop-dialog select{ + margin-top: 10px; + margin-right: 5px; +} + /* search, browse, RDF icons */ span.smwsearchicon { /*FIXME: this was only used for Factbox docu, should be removed from code*/ Modified: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php =================================================================== --- trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php 2011-08-08 11:11:02 UTC (rev 94054) +++ trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php 2011-08-08 11:26:18 UTC (rev 94055) @@ -73,7 +73,7 @@ '</tr>' . "</table>\n"; // sorting and prinouts - $result .= '<div class="smw-qc-sortbox" style="padding-left:10px;">'.$this->getPoSortFormBox().'</div>'; + $result .= '<div class="smw-qc-sortbox" style="padding-left:10px;">' . $this->getPoSortFormBox() . '</div>'; // show|hide additional options and querying help $result .= '<br><span id="show_additional_options" style="display:inline;"><a href="#addtional" rel="nofollow" onclick="' . "document.getElementById('additional_options').style.display='block';" . @@ -104,6 +104,59 @@ } /** + * Decodes printouts and sorting - related form options generated by its + * complement, getPoSortFormBox(). UIs may overload both to change form + * parameters. + * + * Overrides method from SMWQueryUI (modal window added) + * + * @global boolean $smwgQSortingSupport + * @param WebRequest $wgRequest + * @return string + */ + protected function processPoSortFormBox( WebRequest $wgRequest ) { + global $smwgQSortingSupport; + if ( !$smwgQSortingSupport ) return array(); + + $params = array(); + $order_values = $wgRequest->getArray( 'order' ); + $property_values = $wgRequest->getArray( 'property' ); + $po = array(); + if ( is_array( $property_values ) ) { + $params['sort'] = ''; + $params['order'] = ''; + foreach ( $property_values as $key => $property_value ) { + $property_values[$key] = trim( $property_value ); + if ( $property_value == '' ) { + unset( $property_values[$key] ); + } + if ( is_array( $order_values ) and array_key_exists( $key, $order_values ) and $order_values[$key] != 'NONE' ) { + $prop = substr( $property_values[$key], 1 ); // removing the leading '?' + if ( !strpos( $prop, '#' ) === false ) $prop = strstr( $prop, '#', true ); // removing format options + if ( !strpos( $prop, '=' ) === false ) $prop = strstr( $prop, '=', true ); // removing format options + + $params['sort'] .= ( $params['sort'] != '' ? ',':'' ) . $prop; + $params['order'] .= ( $params['order'] != '' ? ',':'' ) . $order_values[$key]; + } + } + $display_values = $wgRequest->getArray( 'display' ); + if ( is_array( $display_values ) ) { + foreach ( $display_values as $key => $value ) { + if ( $value == '1' and array_key_exists( $key, $property_values ) ) { + $po[] = trim( $property_values[$key] ); + } + + } + } + } + + $params = array_merge( $params, $po ); + + return $params; + + } + + /** * Generates the forms elements(s) for choosing printouts and sorting * options. Use its complement processPoSortFormBox() to decode data * sent by these elements. @@ -118,7 +171,6 @@ if ( !$smwgQSortingSupport ) return ''; $this->enableJQueryUI(); $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.dialog.min.js" ); - $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.tabs.min.js" ); $wgOut->addStyle( "$smwgScriptPath/skins/SMW_custom.css" ); $result = ''; @@ -181,10 +233,10 @@ $num_sort_values = count( $property_values ); foreach ( $property_values as $i => $property_value ) { - $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i" ) ); - $result .= '<span class="smw-remove"><a href="javascript:removePOInstance(\'sort_div_' . $i . '\')"><img src="'.$smwgScriptPath.'/skins/images/close-button.png" alt="'. wfMsg('smw_qui_delete').'"></a></span>'; + $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smw-sort' ) ); + $result .= '<span class="smw-remove"><a href="javascript:removePOInstance(\'sort_div_' . $i . '\')"><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>'; $result .= wfMsg( 'smw_qui_property' ); - $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35' ) ) . "\n"; + $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35', 'id' => "property$i" ) ) . "\n"; $result .= Html::openElement( 'select', array( 'name' => "order[$i]" ) ); $if1 = ( !is_array( $order_values ) or !array_key_exists( $i, $order_values ) or $order_values[$i] == 'NONE' ); @@ -200,14 +252,15 @@ $if4 = ( is_array( $display_values ) and array_key_exists( $i, $display_values ) ); $result .= Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display[$i]", "display$i", $if4 ); + $result .= ' <a id="more' . $i . '" "class="smwq-more" href="javascript:smw_makeDialog(\'' . $i . '\')"> options </a> '; // TODO: i18n $result .= Xml::closeElement( 'div' ); } // END: create form elements already submitted earlier via form // create hidden form elements to be cloned later - $hidden = Html::openElement( 'div', array( 'id' => 'sorting_starter', 'class'=>'smw-sort', 'style' => 'display:none' ) ) . - '<span class="smw-remove"><a><img src="'.$smwgScriptPath.'/skins/images/close-button.png" alt="'. wfMsg('smw_qui_delete').'"></a></span>' . + $hidden = Html::openElement( 'div', array( 'id' => 'sorting_starter', 'class' => 'smw-sort', 'style' => 'display:none' ) ) . + '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' . wfMsg( 'smw_qui_property' ) . Xml::input( "property_num", '35' ) . " "; @@ -222,38 +275,17 @@ $hidden = json_encode( $hidden ); - $dialogbox = Xml::openElement( 'div', array( 'id' => 'dialog', 'title' => 'Advanced Print-Out Options' ) ) . // todo i18n - Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), '', 'dialog-show-results', true ) . - '<div id="tab-box">' . - '<ul>' . - '<li><a href="#property-tab">Property</a></li>' . // todo i18n - '<li><a href="#category-tab">Category</a></li>' . // todo i18n - '</ul>' . - '<div id="property-tab">' . - Xml::inputLabel( 'Property', '', 'tab-property', 'tab-property' ) . '<br/>' . // todo i18n - Xml::inputLabel( 'Label (optional):', '', 'tab-property-label', 'tab-property-label' ) . '<br/>' . // todo i18n - 'Format: ' . Html::openElement( 'select', array( 'name' => 'tab-format' ) ) . // todo i18n - Xml::option( 'None (default)', 'NONE' ) . // todo i18n - Xml::option( 'Simple', '-' ) . // todo i18n - Xml::option( 'Numeric', 'n' ) . // todo i18n - Xml::option( 'Unit', 'u' ) . // todo i18n - Xml::option( 'Custom', 'CUSTOM' ) . // todo i18n + $dialogbox = Xml::openElement( 'div', array( 'id' => 'dialog', 'title' => 'Property Options', 'class' => 'smw-prop-dialog' ) ) . // todo i18n + Xml::inputLabel( 'Property:', '', 'd-property', 'd-property' ) . '<br/>' . // todo i18n + Xml::inputLabel( 'Label:', '', 'd-property-label', 'd-property-label' ) . '<br/>' . // todo i18n + 'Format: ' . Html::openElement( 'select', array( 'name' => 'd-format', 'id' => 'd-format' ) ) . // todo i18n + Xml::option( 'None (default)', ' ' ) . // todo i18n + Xml::option( 'Simple', '#-' ) . // todo i18n Xml::closeElement( 'select' ) . - Xml::input( 'format-custom' ) . '<br/>' . - Xml::inputLabel( 'limit (optional):', '', 'tab-property-limit', 'tab-property-limit' ) . '<br/>' . // todo i18n - '</div>' . - '<div id="category-tab">' . - Xml::inputLabel( 'Label (optional):', '', 'tab-category-label', 'tab-category-label' ) . '<br/>' . // todo i18n - Xml::inputLabel( 'Specify a category (optional)', '', 'tab-category', 'tab-category' ) . '<br/>' . // todo i18n - 'If result belongs to category, display' . Html::input( 'tab-yes', 'X' ) . '<br/>' . - 'else display' . Html::input( 'tab-yes', ' ' ) . - '</div>' . - '</div>' . - '<br>Sort by: <select id ="dialog-order">' . // todo i18n - '<option value="NONE">' . wfMsg( 'smw_qui_nosort' ) . '</option>' . - '<option value="ASC">' . wfMsg( 'smw_qui_ascorder' ) . '</option>' . - '<option value="DESC">' . wfMsg( 'smw_qui_descorder' ) . '</option>' . - '</select>' . '</form></div>'; + Xml::input( 'format-custom', false, false, array( 'id' => 'd-property-format-custom' ) ) . '<br/>' . + // Xml::inputLabel( 'Limit:', 'd-property-limit', 'd-property-limit' ) . '<br/>' . // todo i18n + '<input type="hidden" name="d-property-code" id="d-property-code">' . + Xml::closeElement( 'div' ); $result .= '<div id="sorting_main"></div>' . "\n"; $result .= '[<a href="javascript:addPOInstance(\'sorting_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addnprop' ) . '</a>]' . "\n"; @@ -264,39 +296,44 @@ } $javascript_text = <<<EOT <script type="text/javascript"> +var num_elements = {$num_sort_values}; // code for handling adding and removing the "sort" inputs - -jQuery(function(){ - jQuery('$hidden').appendTo(document.body); - jQuery('$dialogbox').appendTo(document.body); - jQuery('#dialog').dialog({ - autoOpen: false, - modal: true, - resizable: true, - minHeight: 300, - minWidth: 500 - }); - jQuery('#tab-box').tabs({ - selected:1 - }); -}); -jQuery(document).ready(function(){ - jQuery('#sort-more').click(function(){jQuery('#dialog').dialog("open");}); - jQuery('#dialog-show-results').click(function(){ - if(jQuery('#dialog-show-results')[0].checked){ - jQuery('#tab-box').show('blind'); - } else { - jQuery('#tab-box').hide('blind'); +function smw_prop_code_update(){ + code = '?'+\$j('#d-property')[0].value; + if(code!=''){ + if(\$j('#d-property-format-custom')[0].value !=''){ + code = code + \$j('#d-property-format-custom')[0].value; + } + if(\$j('#d-property-label')[0].value !=''){ + code = code + ' = '+ \$j('#d-property-label')[0].value; + } + \$j('#d-property-code')[0].value= code; } - }); -}); +} function smw_makeDialog(prop_id){ - \$j('#tab-property')[0].value=\$j('#property'+prop_id)[0].value; + jQuery('#dialog input').attr('value',''); + prop=val=\$j('#property'+prop_id)[0].value; + if(val[0]='?') val=prop=prop.substr(1); + if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i); + if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i); + if(val.split('=')[1]){ + label=val.split('=')[1].trim(); + }else{ + label=""; + } + format = val.split('=')[0]; + if(format.indexOf('#')!=-1){ + format=format.substr(format.indexOf('#')); + }else{ + format=""; + } + + \$j('#d-property').attr('value', prop.trim()); + \$j('#d-property-label').attr('value', label); + \$j('#d-property-format-custom').attr('value', format.trim()); + \$j('#dialog').dialog.id=prop_id; \$j('#dialog').dialog('open'); } - -var num_elements = {$num_sort_values}; - function addPOInstance(starter_div_id, main_div_id) { var starter_div = document.getElementById(starter_div_id); var main_div = document.getElementById(main_div_id); @@ -306,10 +343,11 @@ var div_id = 'sort_div_' + num_elements; new_div.id = div_id; new_div.style.display = 'block'; - + jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements); var children = new_div.getElementsByTagName('*'); var x; for (x = 0; x < children.length; x++) { + if (children[x].for) children[x].for="display"+num_elements; if (children[x].name){ children[x].id = children[x].name.replace(/_num/, ''+num_elements); children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']'); @@ -318,7 +356,7 @@ //Create 'more' link var more_button =document.createElement('span'); - more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makeDialog(\'' + num_elements + '\')">more</a> '; //TODO: i18n + more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makeDialog(\'' + num_elements + '\')">options</a> '; //TODO: i18n more_button.id = 'more'+num_elements; new_div.appendChild(more_button); @@ -328,9 +366,42 @@ // initialize delete button st='sort_div_'+num_elements; jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')"; + num_elements++; +} + +function removePOInstance(div_id) { + var olddiv = document.getElementById(div_id); + var parent = olddiv.parentNode; + parent.removeChild(olddiv); +} + +jQuery(function(){ + jQuery('$hidden').appendTo(document.body); + jQuery('$dialogbox').appendTo(document.body); + jQuery('#dialog').dialog({ + autoOpen: false, + modal: true, + resizable: true, + minHeight: 200, + minWidth: 400, + buttons: { + "Ok": function(){ //todo: i18n + smw_prop_code_update(); + \$j('#property'+\$j('#dialog').dialog.id)[0].value=\$j('#d-property-code')[0].value; + jQuery(this).dialog("close"); + }, + "Cancel": function(){ //todo: i18n + jQuery('#dialog input').attr('value',''); + jQuery(this).dialog("close"); + } + } + }); +}); + +jQuery(document).ready(function(){ EOT; - if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) { - $javascript_text .= <<<EOT + if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) { + $javascript_text .= <<<EOT //add autocomplete jQuery('[name*="property"]').autocomplete({ minLength: 2, @@ -339,23 +410,24 @@ jQuery.getJSON(url, 'search='+request.term, function(data){ //remove the namespace prefix 'Property:' from returned data - for(i=0;i<data[1].length;i++) data[1][i]=data[1][i].substr(data[1][i].indexOf(':')+1); + for(i=0;i<data[1].length;i++) data[1][i]='?'+data[1][i].substr(data[1][i].indexOf(':')+1); response(data[1]); }); + } }); EOT; - } + } $javascript_text .= <<<EOT - num_elements++; + jQuery('#sort-more').click(function(){jQuery('#dialog').dialog("open");}); + jQuery('#dialog input').bind('keyup click', smw_prop_code_update ); -} + jQuery('#d-format').bind('change', function(event){ + jQuery('#d-property-format-custom').attr('value', jQuery('#d-format').attr('value')); + smw_prop_code_update(); + }); +}); -function removePOInstance(div_id) { - var olddiv = document.getElementById(div_id); - var parent = olddiv.parentNode; - parent.removeChild(olddiv); -} </script> EOT; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs