[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: date input for spreadsheet display - based on a patch by Bal...
Yaron Koren has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/376452 ) Change subject: date input for spreadsheet display - based on a patch by Balabky9 .. date input for spreadsheet display - based on a patch by Balabky9 Also made some unrelated small fixes to PF_jsGrid.js. Change-Id: I04319040853e5037342407efc81f40c4c5fddf69 --- M includes/PF_FormPrinter.php M includes/PF_Hooks.php M libs/PF_jsGrid.js 3 files changed, 146 insertions(+), 11 deletions(-) Approvals: Yaron Koren: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/PF_FormPrinter.php b/includes/PF_FormPrinter.php index cd29a1e..7b4db18 100644 --- a/includes/PF_FormPrinter.php +++ b/includes/PF_FormPrinter.php @@ -466,6 +466,8 @@ $gridParamValues['type'] = 'textarea'; } elseif ( $inputType == 'checkbox' ) { $gridParamValues['type'] = 'checkbox'; + } elseif ( $inputType == 'date' ) { + $gridParamValues['type'] = 'date'; } elseif ( ( $possibleValues = $formField->getPossibleValues() ) != null ) { array_unshift( $possibleValues, '' ); $completePossibleValues = array(); diff --git a/includes/PF_Hooks.php b/includes/PF_Hooks.php index b4d6ce2..67e6c17 100644 --- a/includes/PF_Hooks.php +++ b/includes/PF_Hooks.php @@ -157,6 +157,7 @@ global $wgPageFormsGridValues, $wgPageFormsGridParams; global $wgPageFormsShowOnSelect, $wgPageFormsScriptPath; global $edgValues, $wgPageFormsEDSettings; + global $wgAmericanDates; //global $wgPageFormsInitJSFunctions, $wgPageFormsValidationJSFunctions; $vars['wgPageFormsAutocompleteValues'] = $wgPageFormsAutocompleteValues; @@ -170,6 +171,7 @@ $vars['wgPageFormsScriptPath'] = $wgPageFormsScriptPath; $vars['edgValues'] = $edgValues; $vars['wgPageFormsEDSettings'] = $wgPageFormsEDSettings; + $vars['wgAmericanDates'] = $wgAmericanDates; //$vars['wgPageFormsInitJSFunctions'] = $wgPageFormsInitJSFunctions; //$vars['wgPageFormsValidationJSFunctions'] = $wgPageFormsValidationJSFunctions; diff --git a/libs/PF_jsGrid.js b/libs/PF_jsGrid.js index 5ce6757..0d4b43c 100644 --- a/libs/PF_jsGrid.js +++ b/libs/PF_jsGrid.js @@ -2,21 +2,150 @@ * Code to integrate the pfGrid JavaScript library into Page Forms. * * @author Yaron Koren + * @author Balabky9 */ -/* global wgPageFormsGridParams, wgPageFormsGridValues */ +/* global jsGrid, mw */ +(function(jsGrid, $, undefined) { + /** +* The following code handles the 'date' input type within the grid. +* insertTemplate preprocesses the value and returns it to the grid cell to display; +* editTemplate/insertTemplate generate the edition/insertion forms; +* editValue/insertValue is in charge of putting the final values into the grid. +*/ + + // Global variables to store edit and insert values to be used + // by the editValue and insertValue functions to put them into + // the date field. + var Global_Edit_day_of_month; + var Global_Edit_month; + var Global_Edit_year; + var Global_Insert_day_of_month; + var Global_Insert_month; + var Global_Insert_year; + + // Create month selector dropdown. + function buildSelect( currentMonth ) { + var monthNames = mw.config.get('wgMonthNamesShort'); + var str = ''; + for (var val=1; val<=12; val++) { + var val2; + if (val < 10) { //Adds a leading 0 to single digit months, ex 01 instead of 1. + val2 = "0" + val; + } else { + val2 = val; + } + var option = '' + monthNames[val] + ''; + str += option; + } + str += ''; + return str; + } + + var PFDateField = function(config) { + jsGrid.Field.call(this, config); + }; + + PFDateField.prototype = new jsGrid.Field({ + sorter: function(date1, date2) { + return new Date(date1) - new Date(date2); + }, + + itemTemplate: function(value) { +
[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: date input for spreadsheet display - based on a patch by Bal...
Yaron Koren has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/376452 ) Change subject: date input for spreadsheet display - based on a patch by Balabky9 .. date input for spreadsheet display - based on a patch by Balabky9 Change-Id: I04319040853e5037342407efc81f40c4c5fddf69 --- M includes/PF_FormPrinter.php M includes/PF_Hooks.php M libs/PF_jsGrid.js 3 files changed, 166 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms refs/changes/52/376452/3 diff --git a/includes/PF_FormPrinter.php b/includes/PF_FormPrinter.php index cd29a1e..7b4db18 100644 --- a/includes/PF_FormPrinter.php +++ b/includes/PF_FormPrinter.php @@ -466,6 +466,8 @@ $gridParamValues['type'] = 'textarea'; } elseif ( $inputType == 'checkbox' ) { $gridParamValues['type'] = 'checkbox'; + } elseif ( $inputType == 'date' ) { + $gridParamValues['type'] = 'date'; } elseif ( ( $possibleValues = $formField->getPossibleValues() ) != null ) { array_unshift( $possibleValues, '' ); $completePossibleValues = array(); diff --git a/includes/PF_Hooks.php b/includes/PF_Hooks.php index b4d6ce2..67e6c17 100644 --- a/includes/PF_Hooks.php +++ b/includes/PF_Hooks.php @@ -157,6 +157,7 @@ global $wgPageFormsGridValues, $wgPageFormsGridParams; global $wgPageFormsShowOnSelect, $wgPageFormsScriptPath; global $edgValues, $wgPageFormsEDSettings; + global $wgAmericanDates; //global $wgPageFormsInitJSFunctions, $wgPageFormsValidationJSFunctions; $vars['wgPageFormsAutocompleteValues'] = $wgPageFormsAutocompleteValues; @@ -170,6 +171,7 @@ $vars['wgPageFormsScriptPath'] = $wgPageFormsScriptPath; $vars['edgValues'] = $edgValues; $vars['wgPageFormsEDSettings'] = $wgPageFormsEDSettings; + $vars['wgAmericanDates'] = $wgAmericanDates; //$vars['wgPageFormsInitJSFunctions'] = $wgPageFormsInitJSFunctions; //$vars['wgPageFormsValidationJSFunctions'] = $wgPageFormsValidationJSFunctions; diff --git a/libs/PF_jsGrid.js b/libs/PF_jsGrid.js index 5ce6757..bffa20a 100644 --- a/libs/PF_jsGrid.js +++ b/libs/PF_jsGrid.js @@ -2,8 +2,167 @@ * Code to integrate the pfGrid JavaScript library into Page Forms. * * @author Yaron Koren + * @author Balabky9 */ /* global wgPageFormsGridParams, wgPageFormsGridValues */ +(function(jsGrid, $, undefined) { + /** +* The following code handles the 'date' input type within the grid. +* insertTemplate preprocesses the value and returns it to the grid cell to display; +* editTemplate/insertTemplate generate the edition/insertion forms; +* editValue/insertValue is in charge of putting the final values into the grid. +*/ + + // Global variables to store edit and insert values to be used + // by the editValue and insertValue functions to put them into + // the date field. + var Global_Edit_day_of_month; + var Global_Edit_month; + var Global_Edit_year; + var Global_Insert_day_of_month; + var Global_Insert_month; + var Global_Insert_year; + + // Create month selector dropdown. + function buildSelect( currentMonth ) { + var i18n_month_obj = mw.config.get(wgMonthNamesShort); + // Convert it to an array with key value pairs. + var i18n_month_array = $.map(i18n_month_obj, function(value, index) { + return index; + }); + var str = ''; + for (val=1; val<=12; val++) { + if (val < 10) { //Adds a leading 0 to single digit months, ex 01 instead of 1. + var val2 = "0" + val; + } else { + var val2 = val; + } + var option = '' + i18n_month_array[val] + ''; + str += option; + } + str += ''; + return str; + } + + var MyDateField = function(config) { + jsGrid.Field.call(this, config); + }; + + MyDateField.prototype = new jsGrid.Field({ + sorter: function(date1, date2) { + return new