Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | '</tr>' . |
75 | 75 | "</table>\n"; |
76 | 76 | // sorting and prinouts |
77 | | - $result .= '<div class="smw-qc-sortbox" style="padding-left:10px;">'.$this->getPoSortFormBox().'</div>'; |
| 77 | + $result .= '<div class="smw-qc-sortbox" style="padding-left:10px;">' . $this->getPoSortFormBox() . '</div>'; |
78 | 78 | // show|hide additional options and querying help |
79 | 79 | $result .= '<br><span id="show_additional_options" style="display:inline;"><a href="#addtional" rel="nofollow" onclick="' . |
80 | 80 | "document.getElementById('additional_options').style.display='block';" . |
— | — | @@ -104,6 +104,59 @@ |
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
| 108 | + * Decodes printouts and sorting - related form options generated by its |
| 109 | + * complement, getPoSortFormBox(). UIs may overload both to change form |
| 110 | + * parameters. |
| 111 | + * |
| 112 | + * Overrides method from SMWQueryUI (modal window added) |
| 113 | + * |
| 114 | + * @global boolean $smwgQSortingSupport |
| 115 | + * @param WebRequest $wgRequest |
| 116 | + * @return string |
| 117 | + */ |
| 118 | + protected function processPoSortFormBox( WebRequest $wgRequest ) { |
| 119 | + global $smwgQSortingSupport; |
| 120 | + if ( !$smwgQSortingSupport ) return array(); |
| 121 | + |
| 122 | + $params = array(); |
| 123 | + $order_values = $wgRequest->getArray( 'order' ); |
| 124 | + $property_values = $wgRequest->getArray( 'property' ); |
| 125 | + $po = array(); |
| 126 | + if ( is_array( $property_values ) ) { |
| 127 | + $params['sort'] = ''; |
| 128 | + $params['order'] = ''; |
| 129 | + foreach ( $property_values as $key => $property_value ) { |
| 130 | + $property_values[$key] = trim( $property_value ); |
| 131 | + if ( $property_value == '' ) { |
| 132 | + unset( $property_values[$key] ); |
| 133 | + } |
| 134 | + if ( is_array( $order_values ) and array_key_exists( $key, $order_values ) and $order_values[$key] != 'NONE' ) { |
| 135 | + $prop = substr( $property_values[$key], 1 ); // removing the leading '?' |
| 136 | + if ( !strpos( $prop, '#' ) === false ) $prop = strstr( $prop, '#', true ); // removing format options |
| 137 | + if ( !strpos( $prop, '=' ) === false ) $prop = strstr( $prop, '=', true ); // removing format options |
| 138 | + |
| 139 | + $params['sort'] .= ( $params['sort'] != '' ? ',':'' ) . $prop; |
| 140 | + $params['order'] .= ( $params['order'] != '' ? ',':'' ) . $order_values[$key]; |
| 141 | + } |
| 142 | + } |
| 143 | + $display_values = $wgRequest->getArray( 'display' ); |
| 144 | + if ( is_array( $display_values ) ) { |
| 145 | + foreach ( $display_values as $key => $value ) { |
| 146 | + if ( $value == '1' and array_key_exists( $key, $property_values ) ) { |
| 147 | + $po[] = trim( $property_values[$key] ); |
| 148 | + } |
| 149 | + |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + $params = array_merge( $params, $po ); |
| 155 | + |
| 156 | + return $params; |
| 157 | + |
| 158 | + } |
| 159 | + |
| 160 | + /** |
108 | 161 | * Generates the forms elements(s) for choosing printouts and sorting |
109 | 162 | * options. Use its complement processPoSortFormBox() to decode data |
110 | 163 | * sent by these elements. |
— | — | @@ -118,7 +171,6 @@ |
119 | 172 | if ( !$smwgQSortingSupport ) return ''; |
120 | 173 | $this->enableJQueryUI(); |
121 | 174 | $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.dialog.min.js" ); |
122 | | - $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.tabs.min.js" ); |
123 | 175 | $wgOut->addStyle( "$smwgScriptPath/skins/SMW_custom.css" ); |
124 | 176 | |
125 | 177 | $result = ''; |
— | — | @@ -181,10 +233,10 @@ |
182 | 234 | $num_sort_values = count( $property_values ); |
183 | 235 | foreach ( $property_values as $i => $property_value ) { |
184 | 236 | |
185 | | - $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i" ) ); |
186 | | - $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>'; |
| 237 | + $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smw-sort' ) ); |
| 238 | + $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>'; |
187 | 239 | $result .= wfMsg( 'smw_qui_property' ); |
188 | | - $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35' ) ) . "\n"; |
| 240 | + $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35', 'id' => "property$i" ) ) . "\n"; |
189 | 241 | $result .= Html::openElement( 'select', array( 'name' => "order[$i]" ) ); |
190 | 242 | |
191 | 243 | $if1 = ( !is_array( $order_values ) or !array_key_exists( $i, $order_values ) or $order_values[$i] == 'NONE' ); |
— | — | @@ -200,14 +252,15 @@ |
201 | 253 | |
202 | 254 | $if4 = ( is_array( $display_values ) and array_key_exists( $i, $display_values ) ); |
203 | 255 | $result .= Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display[$i]", "display$i", $if4 ); |
| 256 | + $result .= ' <a id="more' . $i . '" "class="smwq-more" href="javascript:smw_makeDialog(\'' . $i . '\')"> options </a> '; // TODO: i18n |
204 | 257 | |
205 | 258 | $result .= Xml::closeElement( 'div' ); |
206 | 259 | } |
207 | 260 | // END: create form elements already submitted earlier via form |
208 | 261 | |
209 | 262 | // create hidden form elements to be cloned later |
210 | | - $hidden = Html::openElement( 'div', array( 'id' => 'sorting_starter', 'class'=>'smw-sort', 'style' => 'display:none' ) ) . |
211 | | - '<span class="smw-remove"><a><img src="'.$smwgScriptPath.'/skins/images/close-button.png" alt="'. wfMsg('smw_qui_delete').'"></a></span>' . |
| 263 | + $hidden = Html::openElement( 'div', array( 'id' => 'sorting_starter', 'class' => 'smw-sort', 'style' => 'display:none' ) ) . |
| 264 | + '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' . |
212 | 265 | wfMsg( 'smw_qui_property' ) . |
213 | 266 | Xml::input( "property_num", '35' ) . " "; |
214 | 267 | |
— | — | @@ -222,38 +275,17 @@ |
223 | 276 | |
224 | 277 | $hidden = json_encode( $hidden ); |
225 | 278 | |
226 | | - $dialogbox = Xml::openElement( 'div', array( 'id' => 'dialog', 'title' => 'Advanced Print-Out Options' ) ) . // todo i18n |
227 | | - Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), '', 'dialog-show-results', true ) . |
228 | | - '<div id="tab-box">' . |
229 | | - '<ul>' . |
230 | | - '<li><a href="#property-tab">Property</a></li>' . // todo i18n |
231 | | - '<li><a href="#category-tab">Category</a></li>' . // todo i18n |
232 | | - '</ul>' . |
233 | | - '<div id="property-tab">' . |
234 | | - Xml::inputLabel( 'Property', '', 'tab-property', 'tab-property' ) . '<br/>' . // todo i18n |
235 | | - Xml::inputLabel( 'Label (optional):', '', 'tab-property-label', 'tab-property-label' ) . '<br/>' . // todo i18n |
236 | | - 'Format: ' . Html::openElement( 'select', array( 'name' => 'tab-format' ) ) . // todo i18n |
237 | | - Xml::option( 'None (default)', 'NONE' ) . // todo i18n |
238 | | - Xml::option( 'Simple', '-' ) . // todo i18n |
239 | | - Xml::option( 'Numeric', 'n' ) . // todo i18n |
240 | | - Xml::option( 'Unit', 'u' ) . // todo i18n |
241 | | - Xml::option( 'Custom', 'CUSTOM' ) . // todo i18n |
| 279 | + $dialogbox = Xml::openElement( 'div', array( 'id' => 'dialog', 'title' => 'Property Options', 'class' => 'smw-prop-dialog' ) ) . // todo i18n |
| 280 | + Xml::inputLabel( 'Property:', '', 'd-property', 'd-property' ) . '<br/>' . // todo i18n |
| 281 | + Xml::inputLabel( 'Label:', '', 'd-property-label', 'd-property-label' ) . '<br/>' . // todo i18n |
| 282 | + 'Format: ' . Html::openElement( 'select', array( 'name' => 'd-format', 'id' => 'd-format' ) ) . // todo i18n |
| 283 | + Xml::option( 'None (default)', ' ' ) . // todo i18n |
| 284 | + Xml::option( 'Simple', '#-' ) . // todo i18n |
242 | 285 | Xml::closeElement( 'select' ) . |
243 | | - Xml::input( 'format-custom' ) . '<br/>' . |
244 | | - Xml::inputLabel( 'limit (optional):', '', 'tab-property-limit', 'tab-property-limit' ) . '<br/>' . // todo i18n |
245 | | - '</div>' . |
246 | | - '<div id="category-tab">' . |
247 | | - Xml::inputLabel( 'Label (optional):', '', 'tab-category-label', 'tab-category-label' ) . '<br/>' . // todo i18n |
248 | | - Xml::inputLabel( 'Specify a category (optional)', '', 'tab-category', 'tab-category' ) . '<br/>' . // todo i18n |
249 | | - 'If result belongs to category, display' . Html::input( 'tab-yes', 'X' ) . '<br/>' . |
250 | | - 'else display' . Html::input( 'tab-yes', ' ' ) . |
251 | | - '</div>' . |
252 | | - '</div>' . |
253 | | - '<br>Sort by: <select id ="dialog-order">' . // todo i18n |
254 | | - '<option value="NONE">' . wfMsg( 'smw_qui_nosort' ) . '</option>' . |
255 | | - '<option value="ASC">' . wfMsg( 'smw_qui_ascorder' ) . '</option>' . |
256 | | - '<option value="DESC">' . wfMsg( 'smw_qui_descorder' ) . '</option>' . |
257 | | - '</select>' . '</form></div>'; |
| 286 | + Xml::input( 'format-custom', false, false, array( 'id' => 'd-property-format-custom' ) ) . '<br/>' . |
| 287 | + // Xml::inputLabel( 'Limit:', 'd-property-limit', 'd-property-limit' ) . '<br/>' . // todo i18n |
| 288 | + '<input type="hidden" name="d-property-code" id="d-property-code">' . |
| 289 | + Xml::closeElement( 'div' ); |
258 | 290 | |
259 | 291 | $result .= '<div id="sorting_main"></div>' . "\n"; |
260 | 292 | $result .= '[<a href="javascript:addPOInstance(\'sorting_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addnprop' ) . '</a>]' . "\n"; |
— | — | @@ -264,39 +296,44 @@ |
265 | 297 | } |
266 | 298 | $javascript_text = <<<EOT |
267 | 299 | <script type="text/javascript"> |
| 300 | +var num_elements = {$num_sort_values}; |
268 | 301 | // code for handling adding and removing the "sort" inputs |
269 | | - |
270 | | -jQuery(function(){ |
271 | | - jQuery('$hidden').appendTo(document.body); |
272 | | - jQuery('$dialogbox').appendTo(document.body); |
273 | | - jQuery('#dialog').dialog({ |
274 | | - autoOpen: false, |
275 | | - modal: true, |
276 | | - resizable: true, |
277 | | - minHeight: 300, |
278 | | - minWidth: 500 |
279 | | - }); |
280 | | - jQuery('#tab-box').tabs({ |
281 | | - selected:1 |
282 | | - }); |
283 | | -}); |
284 | | -jQuery(document).ready(function(){ |
285 | | - jQuery('#sort-more').click(function(){jQuery('#dialog').dialog("open");}); |
286 | | - jQuery('#dialog-show-results').click(function(){ |
287 | | - if(jQuery('#dialog-show-results')[0].checked){ |
288 | | - jQuery('#tab-box').show('blind'); |
289 | | - } else { |
290 | | - jQuery('#tab-box').hide('blind'); |
| 302 | +function smw_prop_code_update(){ |
| 303 | + code = '?'+\$j('#d-property')[0].value; |
| 304 | + if(code!=''){ |
| 305 | + if(\$j('#d-property-format-custom')[0].value !=''){ |
| 306 | + code = code + \$j('#d-property-format-custom')[0].value; |
| 307 | + } |
| 308 | + if(\$j('#d-property-label')[0].value !=''){ |
| 309 | + code = code + ' = '+ \$j('#d-property-label')[0].value; |
| 310 | + } |
| 311 | + \$j('#d-property-code')[0].value= code; |
291 | 312 | } |
292 | | - }); |
293 | | -}); |
| 313 | +} |
294 | 314 | function smw_makeDialog(prop_id){ |
295 | | - \$j('#tab-property')[0].value=\$j('#property'+prop_id)[0].value; |
| 315 | + jQuery('#dialog input').attr('value',''); |
| 316 | + prop=val=\$j('#property'+prop_id)[0].value; |
| 317 | + if(val[0]='?') val=prop=prop.substr(1); |
| 318 | + if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i); |
| 319 | + if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i); |
| 320 | + if(val.split('=')[1]){ |
| 321 | + label=val.split('=')[1].trim(); |
| 322 | + }else{ |
| 323 | + label=""; |
| 324 | + } |
| 325 | + format = val.split('=')[0]; |
| 326 | + if(format.indexOf('#')!=-1){ |
| 327 | + format=format.substr(format.indexOf('#')); |
| 328 | + }else{ |
| 329 | + format=""; |
| 330 | + } |
| 331 | + |
| 332 | + \$j('#d-property').attr('value', prop.trim()); |
| 333 | + \$j('#d-property-label').attr('value', label); |
| 334 | + \$j('#d-property-format-custom').attr('value', format.trim()); |
| 335 | + \$j('#dialog').dialog.id=prop_id; |
296 | 336 | \$j('#dialog').dialog('open'); |
297 | 337 | } |
298 | | - |
299 | | -var num_elements = {$num_sort_values}; |
300 | | - |
301 | 338 | function addPOInstance(starter_div_id, main_div_id) { |
302 | 339 | var starter_div = document.getElementById(starter_div_id); |
303 | 340 | var main_div = document.getElementById(main_div_id); |
— | — | @@ -306,10 +343,11 @@ |
307 | 344 | var div_id = 'sort_div_' + num_elements; |
308 | 345 | new_div.id = div_id; |
309 | 346 | new_div.style.display = 'block'; |
310 | | - |
| 347 | + jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements); |
311 | 348 | var children = new_div.getElementsByTagName('*'); |
312 | 349 | var x; |
313 | 350 | for (x = 0; x < children.length; x++) { |
| 351 | + if (children[x].for) children[x].for="display"+num_elements; |
314 | 352 | if (children[x].name){ |
315 | 353 | children[x].id = children[x].name.replace(/_num/, ''+num_elements); |
316 | 354 | children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']'); |
— | — | @@ -318,7 +356,7 @@ |
319 | 357 | |
320 | 358 | //Create 'more' link |
321 | 359 | var more_button =document.createElement('span'); |
322 | | - more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makeDialog(\'' + num_elements + '\')">more</a> '; //TODO: i18n |
| 360 | + more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makeDialog(\'' + num_elements + '\')">options</a> '; //TODO: i18n |
323 | 361 | more_button.id = 'more'+num_elements; |
324 | 362 | new_div.appendChild(more_button); |
325 | 363 | |
— | — | @@ -328,9 +366,42 @@ |
329 | 367 | // initialize delete button |
330 | 368 | st='sort_div_'+num_elements; |
331 | 369 | jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')"; |
| 370 | + num_elements++; |
| 371 | +} |
| 372 | + |
| 373 | +function removePOInstance(div_id) { |
| 374 | + var olddiv = document.getElementById(div_id); |
| 375 | + var parent = olddiv.parentNode; |
| 376 | + parent.removeChild(olddiv); |
| 377 | +} |
| 378 | + |
| 379 | +jQuery(function(){ |
| 380 | + jQuery('$hidden').appendTo(document.body); |
| 381 | + jQuery('$dialogbox').appendTo(document.body); |
| 382 | + jQuery('#dialog').dialog({ |
| 383 | + autoOpen: false, |
| 384 | + modal: true, |
| 385 | + resizable: true, |
| 386 | + minHeight: 200, |
| 387 | + minWidth: 400, |
| 388 | + buttons: { |
| 389 | + "Ok": function(){ //todo: i18n |
| 390 | + smw_prop_code_update(); |
| 391 | + \$j('#property'+\$j('#dialog').dialog.id)[0].value=\$j('#d-property-code')[0].value; |
| 392 | + jQuery(this).dialog("close"); |
| 393 | + }, |
| 394 | + "Cancel": function(){ //todo: i18n |
| 395 | + jQuery('#dialog input').attr('value',''); |
| 396 | + jQuery(this).dialog("close"); |
| 397 | + } |
| 398 | + } |
| 399 | + }); |
| 400 | +}); |
| 401 | + |
| 402 | +jQuery(document).ready(function(){ |
332 | 403 | EOT; |
333 | | - if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) { |
334 | | - $javascript_text .= <<<EOT |
| 404 | + if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) { |
| 405 | + $javascript_text .= <<<EOT |
335 | 406 | //add autocomplete |
336 | 407 | jQuery('[name*="property"]').autocomplete({ |
337 | 408 | minLength: 2, |
— | — | @@ -339,23 +410,24 @@ |
340 | 411 | |
341 | 412 | jQuery.getJSON(url, 'search='+request.term, function(data){ |
342 | 413 | //remove the namespace prefix 'Property:' from returned data |
343 | | - for(i=0;i<data[1].length;i++) data[1][i]=data[1][i].substr(data[1][i].indexOf(':')+1); |
| 414 | + for(i=0;i<data[1].length;i++) data[1][i]='?'+data[1][i].substr(data[1][i].indexOf(':')+1); |
344 | 415 | response(data[1]); |
345 | 416 | }); |
| 417 | + |
346 | 418 | } |
347 | 419 | }); |
348 | 420 | EOT; |
349 | | - } |
| 421 | + } |
350 | 422 | $javascript_text .= <<<EOT |
351 | | - num_elements++; |
| 423 | + jQuery('#sort-more').click(function(){jQuery('#dialog').dialog("open");}); |
| 424 | + jQuery('#dialog input').bind('keyup click', smw_prop_code_update ); |
352 | 425 | |
353 | | -} |
| 426 | + jQuery('#d-format').bind('change', function(event){ |
| 427 | + jQuery('#d-property-format-custom').attr('value', jQuery('#d-format').attr('value')); |
| 428 | + smw_prop_code_update(); |
| 429 | + }); |
| 430 | +}); |
354 | 431 | |
355 | | -function removePOInstance(div_id) { |
356 | | - var olddiv = document.getElementById(div_id); |
357 | | - var parent = olddiv.parentNode; |
358 | | - parent.removeChild(olddiv); |
359 | | -} |
360 | 432 | </script> |
361 | 433 | |
362 | 434 | EOT; |
Index: trunk/extensions/SemanticMediaWiki/skins/SMW_custom.css |
— | — | @@ -133,6 +133,7 @@ |
134 | 134 | /* ui buttons for QueryUI */ |
135 | 135 | .smw-sort input, .smw-sort a, .smw-sort select, .smw-sort checkbox{ |
136 | 136 | margin-left: 5px; |
| 137 | + margin-bottom: 5px; |
137 | 138 | } |
138 | 139 | span.smw-remove a img{ |
139 | 140 | text-decoration: none; |
— | — | @@ -140,7 +141,12 @@ |
141 | 142 | vertical-align: -3px; |
142 | 143 | } |
143 | 144 | |
| 145 | +.smw-prop-dialog input, .smw-prop-dialog select{ |
| 146 | + margin-top: 10px; |
| 147 | + margin-right: 5px; |
| 148 | +} |
144 | 149 | |
| 150 | + |
145 | 151 | /* search, browse, RDF icons */ |
146 | 152 | |
147 | 153 | span.smwsearchicon { /*FIXME: this was only used for Factbox docu, should be removed from code*/ |