r101055 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101054‎ | r101055 | r101056 >
Date:21:13, 27 October 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
remove usage of origID; allow "current user" to be used as default for any input type
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)
  • /trunk/extensions/SemanticForms/libs/SemanticForms.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -272,9 +272,7 @@
273273 // in the form, to differentiate the inputs the form starts out
274274 // with from any inputs added by the Javascript.
275275 $section = str_replace( '[num]', "[{$instance_num}a]", $section );
276 - // @TODO - this replacement should be
277 - // case- and spacing-insensitive
278 - $section = str_replace( ' id=', ' origID=', $section );
 276+
279277 $text = "\t\t" . Xml::tags( 'div',
280278 array(
281279 // The "multipleTemplate" class is there for
@@ -1206,15 +1204,14 @@
12071205 // to 'current user', and it has no current value, set $cur_value
12081206 // to be the current user.
12091207 if ( $default_value == 'current user' &&
1210 - // if the date is hidden, cur_value will already be set
1211 - // to the default value
1212 - ( $cur_value == '' || $cur_value == 'current user' ) ) {
1213 - if ( $input_type == 'text' || $input_type == '' ) {
1214 - $cur_value_in_template = $wgUser->getName();
1215 - $cur_value = $cur_value_in_template;
1216 - }
 1208+ // if the date is hidden, cur_value will already be set
 1209+ // to the default value
 1210+ ( $cur_value == '' || $cur_value == 'current user' ) ) {
 1211+
 1212+ $cur_value_in_template = $wgUser->getName();
 1213+ $cur_value = $cur_value_in_template;
12171214 }
1218 -
 1215+
12191216 // Generate a hidden field with a placeholder value that will be replaced
12201217 // by the multiple-instances template output at form submission.
12211218 ////<input type="hidden" value="@replace_Town___mayors@" name="Town[town_mayors]" />
Index: trunk/extensions/SemanticForms/libs/SemanticForms.js
@@ -309,13 +309,8 @@
310310
311311 // Display a div that would otherwise be hidden by "show on select".
312312 function showDiv(div_id, instanceWrapperDiv) {
313 - if (instanceWrapperDiv != null) {
314 - instanceWrapperDiv.find('[origID=' + div_id + ']').find(".hiddenBySF").removeClass('hiddenBySF');
315 - instanceWrapperDiv.find('[origID=' + div_id + ']').show();
316 - } else {
317 - jQuery('#' + div_id).find(".hiddenBySF").removeClass('hiddenBySF');
318 - jQuery('#' + div_id).show();
319 - }
 313+ jQuery('[id="' + div_id + '"]', instanceWrapperDiv).find(".hiddenBySF").removeClass('hiddenBySF');
 314+ jQuery('[id="' + div_id + '"]', instanceWrapperDiv).show();
320315 }
321316
322317 // Hide a div due to "show on select". The CSS class is there so that SF can
@@ -328,13 +323,9 @@
329324 // hardcoded in English.
330325 alert( "Warning: this form has \"show on select\" pointing to an invalid element ID (\"" + div_id + "\") - IDs in HTML cannot contain spaces." );
331326 }
332 - if (instanceWrapperDiv != null) {
333 - instanceWrapperDiv.find('[origID=' + div_id + ']').find("span, div").addClass('hiddenBySF');
334 - instanceWrapperDiv.find('[origID=' + div_id + ']').hide();
335 - } else {
336 - jQuery('#' + div_id).find("span, div").addClass('hiddenBySF');
337 - jQuery('#' + div_id).hide();
338 - }
 327+
 328+ jQuery('[id="' + div_id + '"]', instanceWrapperDiv).find("span, div").addClass('hiddenBySF');
 329+ jQuery('[id="' + div_id + '"]', instanceWrapperDiv).hide();
339330 }
340331
341332 // Show this div if the current value is any of the relevant options -
@@ -355,13 +346,9 @@
356347 // Used for handling 'show on select' for the 'dropdown' and 'listbox' inputs.
357348 jQuery.fn.showIfSelected = function(partOfMultiple) {
358349 var inputVal = this.val();
359 - if (partOfMultiple) {
360 - var showOnSelectVals = sfgShowOnSelect[this.attr("origID")];
361 - var instanceWrapperDiv = this.closest(".multipleTemplateInstance");
362 - } else {
363 - var showOnSelectVals = sfgShowOnSelect[this.attr("id")];
364 - var instanceWrapperDiv = null;
365 - }
 350+ var showOnSelectVals = sfgShowOnSelect[this.attr("id")];
 351+ var instanceWrapperDiv = null;
 352+
366353 if ( showOnSelectVals !== undefined ) {
367354 for ( var i = 0; i < showOnSelectVals.length; i++ ) {
368355 var options = showOnSelectVals[i][0];
@@ -386,13 +373,10 @@
387374 // Used for handling 'show on select' for the 'checkboxes' and 'radiobutton'
388375 // inputs.
389376 jQuery.fn.showIfChecked = function(partOfMultiple) {
390 - if (partOfMultiple) {
391 - var showOnSelectVals = sfgShowOnSelect[this.attr("origID")];
392 - var instanceWrapperDiv = this.closest(".multipleTemplateInstance");
393 - } else {
394 - var showOnSelectVals = sfgShowOnSelect[this.attr("id")];
395 - var instanceWrapperDiv = null;
396 - }
 377+
 378+ var showOnSelectVals = sfgShowOnSelect[this.attr("id")];
 379+ var instanceWrapperDiv = null;
 380+
397381 if ( showOnSelectVals !== undefined ) {
398382 for ( var i = 0; i < showOnSelectVals.length; i++ ) {
399383 var options = showOnSelectVals[i][0];
@@ -404,13 +388,10 @@
405389
406390 // Used for handling 'show on select' for the 'checkbox' input.
407391 jQuery.fn.showIfCheckedCheckbox = function(partOfMultiple) {
408 - if (partOfMultiple) {
409 - var div_id = sfgShowOnSelect[this.attr("origID")];
410 - var instanceWrapperDiv = this.closest(".multipleTemplateInstance");
411 - } else {
412 - var div_id = sfgShowOnSelect[this.attr("id")];
413 - var instanceWrapperDiv = null;
414 - }
 392+
 393+ var div_id = sfgShowOnSelect[this.attr("id")];
 394+ var instanceWrapperDiv = null;
 395+
415396 if (jQuery(this).is(":checked")) {
416397 showDiv(div_id, instanceWrapperDiv);
417398 } else {