r68344 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68343‎ | r68344 | r68345 >
Date:02:14, 21 June 2010
Author:yaron
Status:deferred
Tags:
Comment:
Removed "choosers" functionality, originally added in r24819 (no longer necessary, due to "show on select" feature added in v1.9)
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -281,8 +281,6 @@
282282 $instance_num = 0;
283283 $all_instances_printed = false;
284284 $strict_parsing = false;
285 - // initialize list of choosers (dropdowns with available templates)
286 - $choosers = array();
287285 for ( $section_num = 0; $section_num < count( $form_def_sections ); $section_num++ ) {
288286 $tif = new SFTemplateInForm();
289287 $start_position = 0;
@@ -307,8 +305,6 @@
308306 // also replace periods with underlines, since that's what
309307 // POST does to strings anyway
310308 $query_template_name = str_replace( '.', '_', $query_template_name );
311 - $chooser_name = false;
312 - $chooser_caption = false;
313309 // cycle through the other components
314310 for ( $i = 2; $i < count( $tag_components ); $i++ ) {
315311 $component = $tag_components[$i];
@@ -318,22 +314,12 @@
319315 if ( count( $sub_components ) == 2 ) {
320316 if ( $sub_components[0] == 'label' ) {
321317 $template_label = $sub_components[1];
322 - } elseif ( $sub_components[0] == 'chooser' ) {
323 - $allow_multiple = true;
324 - $chooser_name = $sub_components[1];
325 - } elseif ( $sub_components[0] == 'chooser caption' ) {
326 - $chooser_caption = $sub_components[1];
327318 }
328319 }
329320 }
330321 // if this is the first instance, add the label in the form
331322 if ( ( $old_template_name != $template_name ) && isset( $template_label ) ) {
332 - // add a placeholder to the form text so the fieldset can be
333 - // hidden if chooser support demands it
334 - if ( $chooser_name !== false )
335 - $form_text .= "<fieldset [[placeholder]] haschooser=true>\n";
336 - else
337 - $form_text .= "<fieldset>\n";
 323+ $form_text .= "<fieldset>\n";
338324 $form_text .= "<legend>$template_label</legend>\n";
339325 }
340326 $template_text .= "{{" . $tif->template_name;
@@ -496,10 +482,6 @@
497483 $allow_multiple = false;
498484 $all_instances_printed = false;
499485 $instance_num = 0;
500 - // if the hiding placeholder is still around, this fieldset should
501 - // be hidden because it is empty and choosers are being used. So,
502 - // hide it.
503 - $form_text = str_replace( "[[placeholder]]", "style='display:none'", $form_text );
504486 // =====================================================
505487 // field processing
506488 // =====================================================
@@ -1134,10 +1116,7 @@
11351117 END;
11361118 // this will cause the section to be re-parsed on the next go
11371119 $section_num--;
1138 - // because there is an instance, the fieldset will never be hidden,
1139 - // even if choosers are being used. So, do not hide the fieldset.
1140 - $form_text = str_replace( "[[placeholder]]", "", $form_text );
1141 - } else {
 1120+ } else {
11421121 // this is the last instance of this template - stick an 'add'
11431122 // button in the form
11441123 $form_text .= <<<END
@@ -1153,10 +1132,6 @@
11541133 <p><input type="button" onclick="addInstance('starter_$query_template_name', 'main_$query_template_name', '$sfgFieldNum');" value="$add_another" tabindex="$sfgTabIndex" class="addAnother" /></p>
11551134
11561135 END;
1157 - // if a chooser is being used for this template, add the template
1158 - // to the chooser data array
1159 - if ( $chooser_name !== false )
1160 - $choosers[$chooser_name][] = array( $query_template_name, $sfgFieldNum, $chooser_caption );
11611136 }
11621137 } else {
11631138 $form_text .= $section;
@@ -1228,84 +1203,6 @@
12291204 $form_text = ' <div class="warningMessage">' . wfMsg( 'sf_formedit_formwarning', $this->mPageTitle->getFullURL() ) . "</div>\n" . $form_text;
12301205 }
12311206
1232 - // Substitute the choosers in here too.
1233 - $chooser_count = 0;
1234 - $chooser_text = "";
1235 - $using_choosers = "false";
1236 - foreach ( $choosers as $choosername => $chooser ) {
1237 - if ( count( $chooser ) != 0 ) {
1238 - $chooser_count++;
1239 - if ( $chooser_count == 1 ) {
1240 - // emit the initial javascript code
1241 - $using_choosers = "true";
1242 - $chooser_text .= <<<END
1243 -<script type="text/javascript">/* <![CDATA[ */
1244 -
1245 -function updatechooserbutton(f,n)
1246 -{
1247 - document.getElementById(n).disabled = (f.options[f.selectedIndex].value=="invalid");
1248 -}
1249 -
1250 -function addInstanceFromChooser(chooserid)
1251 -{
1252 - var chooser = document.getElementById(chooserid);
1253 - var optionstring = chooser.options[chooser.selectedIndex].value;
1254 - var pos = optionstring.indexOf(",");
1255 - var tabindex = optionstring.substr(0,pos);
1256 - var chooservalue = optionstring.substr(pos+1);
1257 - addInstance('starter_' + chooservalue, 'main_' + chooservalue, parseInt(tabindex));
1258 -}
1259 -
1260 -//The fieldset containing the given element was just updated. If the fieldset is associated with a chooser,
1261 -//ensure that the fieldset is hidden if and only if there are no template instances inside.
1262 -function hideOrShowFieldset(element)
1263 -{
1264 - //Find fieldset
1265 - while (element.tagName.toLowerCase() != "fieldset")
1266 - element = element.parentNode;
1267 - //Bail out if fieldset is not part of chooser
1268 - if (!element.getAttribute("haschooser"))
1269 - return;
1270 - //Now look for "input" or "select" tags that don't look like they're part of the starter template
1271 - var inputs = element.getElementsByTagName("input");
1272 - var x;
1273 - var show = false;
1274 - for (x=0;x<inputs.length;x++)
1275 - {
1276 - if (inputs[x].type=="text" && inputs[x].name.indexOf("[num]") == -1)
1277 - show = true;
1278 - }
1279 - var selects = element.getElementsByTagName("select");
1280 - for (x=0;x<selects.length;x++)
1281 - {
1282 - if (selects[x].name.indexOf("[num]") == -1)
1283 - show = true;
1284 - }
1285 - //Now show or hide fieldset
1286 - element.style.display = (show?"block":"none");
1287 -}
1288 -/* ]]> */ </script>
1289 -
1290 -END;
1291 - }
1292 -
1293 - $chooser_text .= "<p>$choosername:<select id='chooserselect$chooser_count' size='1' onchange='updatechooserbutton(this,\"chooserbutton$chooser_count\")'>\n";
1294 - $chooser_text .= "<option value='invalid'>" . wfMsg( 'sf_createform_choosefield' ) . "</option>\n";
1295 - foreach ( $chooser as $chooser_item ) {
1296 - $chooser_value = str_replace( '"', '\\"', $chooser_item[0] );
1297 - $tabindex = $chooser_item[1];
1298 - $chooser_caption = $chooser_item[2];
1299 - if ( $chooser_caption === false )
1300 - $chooser_caption = str_replace( '_', ' ', $chooser_value );
1301 - $chooser_text .= "<option value=\"$tabindex ,$chooser_value\">$chooser_caption</option>\n";
1302 - }
1303 - $chooser_text .= "</select>\n";
1304 - }
1305 - $chooser_text .= "<input type='button' onclick=\"addInstanceFromChooser('chooserselect$chooser_count');\" value='" . wfMsg( 'sf_formedit_addanother' ) . "' disabled='true' id='chooserbutton$chooser_count'></p>";
1306 - }
1307 -
1308 - $form_text = str_replace( '{{{choosers}}}', $chooser_text, $form_text );
1309 -
13101207 // add form bottom, if no custom "standard inputs" have been defined
13111208 if ( !$this->standardInputsIncluded ) {
13121209 if ( $is_query )
@@ -1329,7 +1226,7 @@
13301227
13311228 // add Javascript code for form-wide use
13321229 $javascript_text .= SFFormUtils::validationJavascript();
1333 - $javascript_text .= SFFormUtils::instancesJavascript( $using_choosers );
 1230+ $javascript_text .= SFFormUtils::instancesJavascript();
13341231 $javascript_text .= SFFormUtils::autocompletionJavascript();
13351232 if ( $free_text_was_included && $showFCKEditor > 0 ) {
13361233 $javascript_text .= SFFormUtils::mainFCKJavascript( $showFCKEditor );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r24819Improved formatting, added Jeffrey Stuckman's "chooser" functionality, fixed...yaron13:37, 15 August 2007

Status & tagging log