Yaron Koren has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/360870 )
Change subject: Added "use Cargo" checkboxes to CreateClass, CreateTemplate
pages
......................................................................
Added "use Cargo" checkboxes to CreateClass, CreateTemplate pages
Change-Id: I8c808d778fc933cfcc68e0793bb86c58e5eea57c
---
M i18n/en.json
M libs/PF_CreateClass.js
M libs/PF_CreateTemplate.js
M specials/PF_CreateClass.php
M specials/PF_CreateTemplate.php
5 files changed, 111 insertions(+), 33 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms
refs/changes/70/360870/2
diff --git a/i18n/en.json b/i18n/en.json
index f113752..3b82468 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -43,7 +43,8 @@
"pf_createtemplate_multipleinstance": "This template can be included
multiple times on the page.",
"pf_createtemplate_connectingproperty": "Name of property to connect
this template's fields to the rest of the page:",
"pf_createtemplate_categorylabel": "Category defined by template
(optional):",
- "pf_createtemplate_cargotablelabel": "Cargo table defined by template
(optional):",
+ "pf_createtemplate_usecargo": "Use the Cargo extension to store this
template's data",
+ "pf_createtemplate_cargotablelabel": "Name of Cargo table defined by
template:",
"pf_createtemplate_templatefields": "Template fields",
"pf_createtemplate_fieldsdesc": "To have the fields in this template no
longer require field names, simply enter the index of each field (e.g. 1, 2, 3,
etc.) as the name, instead of an actual name.",
"pf_createtemplate_fieldname": "Field name:",
diff --git a/libs/PF_CreateClass.js b/libs/PF_CreateClass.js
index 2402f13..44e5fe7 100644
--- a/libs/PF_CreateClass.js
+++ b/libs/PF_CreateClass.js
@@ -23,10 +23,23 @@
}
}
+function toggleCargoInputs() {
+ if (jQuery('#use_cargo').prop('checked')) {
+ jQuery('#cargo_table_input').show('medium');
+ $('td:nth-child(4),th:nth-child(3)').show('medium');
+ } else {
+ jQuery('#cargo_table_input').hide('medium');
+ $('td:nth-child(4),th:nth-child(3)').hide('medium');
+ }
+}
+
jQuery( document ).ready( function () {
jQuery( ".disableFormAndCategoryInputs" ).click( function () {
disableFormAndCategoryInputs();
} );
+ jQuery( "#use_cargo" ).click( function() {
+ toggleCargoInputs();
+ } );
jQuery( ".createClassAddRow" ).click( function () {
createClassAddRow();
} );
diff --git a/libs/PF_CreateTemplate.js b/libs/PF_CreateTemplate.js
index 29e40ea..6a8210e 100644
--- a/libs/PF_CreateTemplate.js
+++ b/libs/PF_CreateTemplate.js
@@ -1,3 +1,15 @@
+function toggleCargoInputs() {
+ if (jQuery('#use_cargo').prop('checked')) {
+ jQuery('#cargo_table_input').show('medium');
+ jQuery('label.cargo_field_type').show('medium');
+ jQuery('p.allowed_values_input').show('medium');
+ } else {
+ jQuery('#cargo_table_input').hide('medium');
+ jQuery('label.cargo_field_type').hide('medium');
+ jQuery('p.allowed_values_input').hide('medium');
+ }
+}
+
var fieldNum = 1;
function createTemplateAddField() {
fieldNum++;
@@ -31,6 +43,9 @@
}
jQuery( document ).ready( function () {
+ jQuery( "#use_cargo" ).click( function() {
+ toggleCargoInputs();
+ } );
jQuery( ".createTemplateAddField" ).click( function () {
createTemplateAddField();
} );
diff --git a/specials/PF_CreateClass.php b/specials/PF_CreateClass.php
index 97a9f7e..65130a9 100644
--- a/specials/PF_CreateClass.php
+++ b/specials/PF_CreateClass.php
@@ -31,6 +31,8 @@
$template_name = trim( $req->getVal( "template_name" ) );
$template_multiple = $req->getBool( "template_multiple" );
+ $use_cargo = trim( $req->getBool( "use_cargo" ) );
+ $cargo_table = trim( $req->getVal( "cargo_table" ) );
// If this is a multiple-instance template, there
// shouldn't be a corresponding form or category.
if ( $template_multiple ) {
@@ -40,12 +42,14 @@
$form_name = trim( $req->getVal( "form_name" ) );
$category_name = trim( $req->getVal( "category_name" )
);
}
- if ( $template_name === '' || ( !$template_multiple && (
$form_name === '' || $category_name === '' ) ) ) {
+ if ( $template_name === '' || ( !$template_multiple && (
$form_name === '' || $category_name === '' ) ) ||
+ ( $use_cargo && ( $cargo_table === '' ) ) ) {
$out->addWikiMsg( 'pf_createclass_missingvalues' );
return;
}
$fields = array();
$jobs = array();
+ $allowedValuesForFields = array();
// Cycle through all the rows passed in.
for ( $i = 1; $req->getVal( "field_name_$i" ) != ''; $i++ ) {
// Go through the query values, setting the appropriate
@@ -60,11 +64,19 @@
$field = PFTemplateField::create( $field_name,
$field_name, $property_name, $is_list );
if ( defined( 'CARGO_VERSION' ) ) {
- $field->setFieldType( $property_type );
// Hopefully it's safe to use a Cargo
// utility method here.
$possibleValues = CargoUtils::smartSplit( ',',
$allowed_values );
$field->setPossibleValues( $possibleValues );
+ if ( $use_cargo ) {
+ $field->setFieldType( $property_type );
+ $field->setPossibleValues(
$possibleValues );
+ } else {
+ if ( $allowed_values != '' ) {
+
$allowedValuesForFields[$field_name] = $allowed_values;
+ }
+ }
+
}
$fields[] = $field;
@@ -100,8 +112,8 @@
// one page, instead of just creating jobs for all of them).
$template_format = $req->getVal( "template_format" );
$pfTemplate = new PFTemplate( $template_name, $fields );
- if ( defined( 'CARGO_VERSION' ) ) {
- $pfTemplate->mCargoTable = trim( $req->getVal(
"cargo_table" ) );
+ if ( defined( 'CARGO_VERSION' ) && $use_cargo ) {
+ $pfTemplate->mCargoTable = $cargo_table;
}
if ( defined( 'SMW_VERSION' ) && $template_multiple ) {
$pfTemplate->setConnectingProperty( $connectingProperty
);
@@ -119,11 +131,23 @@
// Create the form, and make a job for it.
if ( $form_name != '' ) {
- $form_template = PFTemplateInForm::create(
$template_name, '', false );
+ $formFields = array();
+ foreach ( $fields as $field ) {
+ $formField = PFFormField::create( $field );
+ $fieldName = $field->getFieldName();
+ if ( array_key_exists( $fieldName,
$allowedValuesForFields ) ) {
+ $formField->setInputType( 'dropdown' );
+ $formField->setFieldArg( 'values',
$allowedValuesForFields[$fieldName] );
+ }
+ $formFields[] = $formField;
+ }
+ $form_template = PFTemplateInForm::create(
$template_name, '', false, false, $formFields );
$form_items = array();
- $form_items[] = array( 'type' => 'template',
- 'name' =>
$form_template->getTemplateName(),
- 'item' =>
$form_template );
+ $form_items[] = array(
+ 'type' => 'template',
+ 'name' => $form_template->getTemplateName(),
+ 'item' => $form_template
+ );
$form = PFForm::create( $form_name, $form_items );
$full_text = $form->createMarkup();
$form_title = Title::makeTitleSafe( PF_NS_FORM,
$form_name );
@@ -214,7 +238,20 @@
$templateNameLabel = wfMessage( 'pf_createtemplate_namelabel'
)->escaped();
$templateNameInput = Html::input( 'template_name', null,
'text', array( 'size' => 30 ) );
$text .= "\t" . Html::rawElement( 'p', null, $templateNameLabel
. ' ' . $templateNameInput ) . "\n";
- $templateInfo = PFCreateTemplate::printTemplateStyleInput(
'template_format' );
+
+ $templateInfo = '';
+ if ( defined( 'CARGO_VERSION' ) && !defined( 'SMW_VERSION' ) ) {
+ $templateInfo .= "\t<p><label>" .
+ Html::check( 'use_cargo', true, array( 'id' =>
'use_cargo' ) ) .
+ ' ' . wfMessage( 'pf_createtemplate_usecargo'
)->escaped() .
+ "</label></p>\n";
+ $cargo_table_label = wfMessage(
'pf_createtemplate_cargotablelabel' )->escaped();
+ $templateInfo .= "\t" . Html::rawElement( 'p', array(
'id' => 'cargo_table_input' ),
+ Html::element( 'label', array( 'for' =>
'cargo_table' ), $cargo_table_label ) . ' ' .
+ Html::element( 'input', array( 'size' => '30',
'name' => 'cargo_table', 'id' => 'cargo_table' ), null )
+ ) . "\n";
+ }
+ $templateInfo .= PFCreateTemplate::printTemplateStyleInput(
'template_format' );
$templateInfo .= Html::rawElement( 'p', null,
Html::element( 'input', array(
'type' => 'checkbox',
@@ -240,14 +277,10 @@
}
$text .= Html::rawElement( 'blockquote', null, $templateInfo );
- $form_name_label = wfMessage( 'pf_createclass_nameinput'
)->text();
- $text .= "\t" . Html::rawElement( 'p', null, Html::element(
'label', array( 'for' => 'form_name' ), $form_name_label ) . ' ' .
Html::element( 'input', array( 'size' => '30', 'name' => 'form_name', 'id' =>
'form_name' ), null ) ) . "\n";
- $category_name_label = wfMessage( 'pf_createcategory_name'
)->text();
- $text .= "\t" . Html::rawElement( 'p', null, Html::element(
'label', array( 'for' => 'category_name' ), $category_name_label ) . ' ' .
Html::element( 'input', array( 'size' => '30', 'name' => 'category_name', 'id'
=> 'category_name' ), null ) ) . "\n";
- if ( defined( 'CARGO_VERSION' ) && !defined( 'SMW_VERSION' ) ) {
- $cargo_table_label = wfMessage(
'pf_createtemplate_cargotablelabel' )->escaped();
- $text .= "\t" . Html::rawElement( 'p', null,
Html::element( 'label', array( 'for' => 'cargo_table' ), $cargo_table_label ) .
' ' . Html::element( 'input', array( 'size' => '30', 'name' => 'cargo_table',
'id' => 'cargo_table' ), null ) ) . "\n";
- }
+ $form_name_input = Html::element( 'input', array( 'size' =>
'30', 'name' => 'form_name', 'id' => 'form_name' ), null );
+ $text .= "\t<p><label>" . wfMessage( 'pf_createclass_nameinput'
)->escaped() . " $form_name_input</label></p>\n";
+ $category_name_input = Html::element( 'input', array( 'size' =>
'30', 'name' => 'category_name', 'id' => 'category_name' ), null );
+ $text .= "\t<p><label>" . wfMessage( 'pf_createcategory_name'
)->escaped() . " $category_name_input</label></p>\n";
$text .= "\t" . Html::element( 'br', null, null ) . "\n";
$text .= <<<END
<div>
@@ -281,10 +314,15 @@
END;
}
- $type_label = wfMessage( 'pf_createproperty_proptype'
)->escaped();
+ if ( defined( 'CARGO_VERSION' ) || defined( 'SMW_VERSION' ) ) {
+ $type_label = wfMessage( 'pf_createproperty_proptype'
)->escaped();
+ $text .= <<<END
+ <th style="background: $specialBGColor; padding:
4px;">$type_label</th>
+
+END;
+ }
$allowed_values_label = wfMessage(
'pf_createclass_allowedvalues' )->escaped();
$text .= <<<END
- <th style="background: $specialBGColor; padding:
4px;">$type_label</th>
<th style="background: $specialBGColor; padding:
4px;">$allowed_values_label</th>
</tr>
@@ -307,21 +345,23 @@
<td style="text-align: center;"><input type="checkbox"
name="is_list_$n" /></td>
END;
- if ( defined( 'SMW_VERSION' ) ) {
- $text .= <<<END
+ if ( defined( 'SMW_VERSION' ) ) {
+ $text .= <<<END
<td style="background: $specialBGColor; padding:
4px;"><input type="text" size="25" name="property_name_$n" /></td>
END;
- }
- $text .= <<<END
+ }
+ if ( defined( 'CARGO_VERSION' ) || defined(
'SMW_VERSION' ) ) {
+ $text .= <<<END
<td style="background: $specialBGColor; padding: 4px;">
END;
- $typeDropdownBody = '';
- foreach ( $possibleTypes as $typeName ) {
- $typeDropdownBody .=
"\t\t\t\t<option>$typeName</option>\n";
+ $typeDropdownBody = '';
+ foreach ( $possibleTypes as $typeName ) {
+ $typeDropdownBody .=
"\t\t\t\t<option>$typeName</option>\n";
+ }
+ $text .= "\t\t\t\t" . Html::rawElement(
'select', array( 'name' => "property_type_$n" ), $typeDropdownBody ) . "\n";
}
- $text .= "\t\t\t\t" . Html::rawElement( 'select',
array( 'name' => "property_type_$n" ), $typeDropdownBody ) . "\n";
$text .= <<<END
</td>
<td style="background: $specialBGColor; padding:
4px;"><input type="text" size="25" name="allowed_values_$n" /></td>
diff --git a/specials/PF_CreateTemplate.php b/specials/PF_CreateTemplate.php
index c967ac9..9dfb76d 100644
--- a/specials/PF_CreateTemplate.php
+++ b/specials/PF_CreateTemplate.php
@@ -110,7 +110,7 @@
$text .= "\t<label>" . wfMessage(
'pf_createtemplate_semanticproperty' )->escaped() . ' ' . $dropdown_html .
"</label></p>\n";
} elseif ( defined( 'CARGO_VERSION' ) ) {
$dropdown_html = self::printFieldTypeDropdown( $id );
- $text .= "\t<label>" . wfMessage(
'pf_createproperty_proptype' )->escaped() . ' ' . $dropdown_html .
"</label></p>\n";
+ $text .= "\t<label class=\"cargo_field_type\">" .
wfMessage( 'pf_createproperty_proptype' )->escaped() . ' ' . $dropdown_html .
"</label></p>\n";
}
$text .= "\t<p>" . '<label><input type="checkbox"
name="is_list_' . $id . '" class="isList" /> ' . wfMessage(
'pf_createtemplate_fieldislist' )->escaped() . "</label> \n";
@@ -121,7 +121,7 @@
$text .= "\t</p>\n";
if ( !defined( 'SMW_VERSION' ) && defined( 'CARGO_VERSION' ) ) {
$text .= "\t<p>\n";
- $text .= "\t<label>" . wfMessage(
'pf_createproperty_allowedvalsinput' )->escaped();
+ $text .= "\t<label class=\"allowed_values_input\">" .
wfMessage( 'pf_createproperty_allowedvalsinput' )->escaped();
$text .= Html::input( 'allowed_values_' . $id, null,
'text',
array( 'size' => '80' ) ) . "</label>\n";
$text .= "\t</p>\n";
@@ -219,7 +219,9 @@
$template_format = $req->getVal( 'template_format' );
$pfTemplate = new PFTemplate( $template_name, $fields );
$pfTemplate->setCategoryName( $category );
- $pfTemplate->mCargoTable = $cargo_table;
+ if ( $req->getBool( 'use_cargo' ) ) {
+ $pfTemplate->mCargoTable = $cargo_table;
+ }
$pfTemplate->setAggregatingInfo( $aggregating_property,
$aggregation_label );
$pfTemplate->setFormat( $template_format );
$full_text = $pfTemplate->createText();
@@ -231,13 +233,20 @@
$text .= ' <form id="createTemplateForm" action=""
method="post">' . "\n";
if ( is_null( $presetTemplateName ) ) {
- // Set 'title' field, in case there's no URL niceness
+ // Set 'title' field, in case there's no URL niceness.
$text .= Html::hidden( 'title',
$this->getTitle()->getPrefixedText() ) . "\n";
- $text .= "\t<p id=\"template_name_p\">" . wfMessage(
'pf_createtemplate_namelabel' )->escaped() . ' <input size="25"
id="template_name" name="template_name" /></p>' . "\n";
+ $text .= "\t<p id=\"template_name_p\">" .
+ wfMessage( 'pf_createtemplate_namelabel'
)->escaped() .
+ ' <input size="25" id="template_name"
name="template_name" /></p>' . "\n";
}
$text .= "\t<p>" . wfMessage( 'pf_createtemplate_categorylabel'
)->escaped() . ' <input size="25" name="category" /></p>' . "\n";
if ( !defined( 'SMW_VERSION' ) && defined( 'CARGO_VERSION' ) ) {
$text .= "\t<p>" . wfMessage(
'pf_createtemplate_cargotablelabel' )->escaped() . ' <input size="25"
name="cargo_table" /></p>' . "\n";
++ $text .= "\t<p><label>" . Html::check( 'use_cargo',
true, array( 'id' => 'use_cargo' ) ) .
++ ' ' . wfMessage( 'pf_createtemplate_usecargo'
)->escaped() . "</label></p>\n";
++ $text .= "\t<p id=\"cargo_table_input\"><label>" .
++ wfMessage( 'pf_createtemplate_cargotablelabel'
)->escaped() .
++ ' <input size="25" name="cargo_table"
/></label></p>' . "\n";
}
$text .= "\t<fieldset>\n";
--
To view, visit https://gerrit.wikimedia.org/r/360870
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8c808d778fc933cfcc68e0793bb86c58e5eea57c
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits