jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/371160 )

Change subject: Add hierarchy field creation in Special:CreateTemplate
......................................................................


Add hierarchy field creation in Special:CreateTemplate

Change-Id: Icdac918b41d0456b720617f85b385a5c166ee4d9
---
M i18n/en.json
M i18n/qqq.json
M includes/PF_Template.php
M libs/PF_CreateTemplate.js
M specials/PF_CreateTemplate.php
5 files changed, 48 insertions(+), 6 deletions(-)

Approvals:
  Yaron Koren: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index 19f67e3..fcf781e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -51,6 +51,9 @@
        "pf_createtemplate_displaylabel": "Display label:",
        "pf_createtemplate_semanticproperty": "Semantic property:",
        "pf_createtemplate_fieldislist": "Field holds a list of values",
+       "pf_createtemplate_fieldishierarchy": "Field holds a hierarchy",
+       "pf_createtemplate_hierarchystructureplaceholder": 
"*Enter\n**hierarchy\n***values\n***in\n**a\n***format\n*like\n**this\n",
+       "pf_createproperty_allowedvalsforhierarchy": "Allowed values for 
hierarchy:",
        "pf_createtemplate_delimiter": "Delimiter:",
        "pf_createtemplate_aggregation": "Aggregation",
        "pf_createtemplate_aggregationdesc": "To list, on any page using this 
template, all of the pages that have a certain property pointing to that page, 
specify the appropriate property below:",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index ed55b48..924d232 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -67,6 +67,9 @@
        "pf_createtemplate_displaylabel": "The term for the text that shows up 
next to a field when it is displayed",
        "pf_createtemplate_semanticproperty": "Used as label for the \"Property 
name\" select box.",
        "pf_createtemplate_fieldislist": "Used as label for the checkbox.",
+       "pf_createtemplate_fieldishierarchy": "Used as label for the checkbox.",
+       "pf_createtemplate_hierarchystructureplaceholder": "Placeholder for 
hierarchy structure as allowed values",
+       "pf_createproperty_allowedvalsforhierarchy": "Used as label for 
providing hierarchy allowed values",
        "pf_createtemplate_delimiter": "Used as label for the input to set a 
list delimiter.\n{{Identical|Delimiter}}",
        "pf_createtemplate_aggregation": "Used as fieldset label.\n\nFollowed 
by the following description:\n* {{msg-mw|pf createtemplate aggregationdesc}}",
        "pf_createtemplate_aggregationdesc": "Used as description in the 
form.\n\nPreceded by the fieldset label {{msg-mw|pf createtemplate 
aggregation}}.",
diff --git a/includes/PF_Template.php b/includes/PF_Template.php
index 68c4bf2..9002e3e 100644
--- a/includes/PF_Template.php
+++ b/includes/PF_Template.php
@@ -334,7 +334,10 @@
                                $text .= "List ($delimiter) of ";
                        }
                        $text .= $field->getFieldType();
-                       if ( count( $field->getPossibleValues() ) > 0 ) {
+                       if ( $field->getHierarchyStructure() ) {
+                               $hierarchyStructureString = 
$field->getHierarchyStructure();
+                               $text .= " (hierarchy;allowed 
values=$hierarchyStructureString)";
+                       } elseif ( count( $field->getPossibleValues() ) > 0 ) {
                                $allowedValuesString = implode( ',', 
$field->getPossibleValues() );
                                $text .= " (allowed 
values=$allowedValuesString)";
                        }
diff --git a/libs/PF_CreateTemplate.js b/libs/PF_CreateTemplate.js
index cab466d..16df71c 100644
--- a/libs/PF_CreateTemplate.js
+++ b/libs/PF_CreateTemplate.js
@@ -2,11 +2,15 @@
        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');
+               jQuery('.allowed_values_input').show('medium');
+               jQuery('.is_hierarchy').show('medium');
        } else {
                jQuery('#cargo_table_input').hide('medium');
                jQuery('label.cargo_field_type').hide('medium');
-               jQuery('p.allowed_values_input').hide('medium');
+               jQuery("input[name*='is_hierarchy_']").prop('checked', false);
+               jQuery('.is_hierarchy').hide('medium');
+               jQuery('.hierarchy_structure_input').hide('medium');
+               jQuery('.allowed_values_input').show('medium');
        }
 }
 
@@ -25,6 +29,9 @@
        } );
        newField.find( ".isList" ).click( function () {
                jQuery( this ).closest( ".fieldBox" ).find( ".delimiter" 
).toggle();
+       } );
+       newField.find( ".is_hierarchy" ).click( function () {
+               toggleHierarchyInput(jQuery( this ).closest( ".fieldBox" ));
        } );
        var combobox = new pf.select2.combobox();
        combobox.apply( $( newField.find( '.pfComboBox' ) ) );
@@ -49,6 +56,16 @@
        }
 }
 
+function toggleHierarchyInput(containerElement) {
+       if (containerElement.find( "input[name*='is_hierarchy_']" 
).prop('checked')) {
+               containerElement.find( ".allowed_values_input" ).hide('medium');
+               containerElement.find( ".hierarchy_structure_input" 
).show('medium');
+       } else {
+               containerElement.find( ".hierarchy_structure_input" 
).hide('medium');
+               containerElement.find( ".allowed_values_input" ).show('medium');
+       }
+}
+
 jQuery( document ).ready( function () {
        jQuery( "#use_cargo" ).click( function() {
                toggleCargoInputs();
@@ -66,6 +83,9 @@
        jQuery( ".isList" ).click( function () {
                jQuery( this ).closest( ".fieldBox" ).find( ".delimiter" 
).toggle();
        } );
+       jQuery( ".is_hierarchy" ).click( function () {
+               toggleHierarchyInput( jQuery( this ).closest( ".fieldBox" ) );
+       } );
        jQuery( '#createTemplateForm' ).submit( function () {
                return validateCreateTemplateForm();
        } );
diff --git a/specials/PF_CreateTemplate.php b/specials/PF_CreateTemplate.php
index 0ba2cce..13189ae 100644
--- a/specials/PF_CreateTemplate.php
+++ b/specials/PF_CreateTemplate.php
@@ -121,9 +121,17 @@
                $text .= "\t</p>\n";
                if ( !defined( 'SMW_VERSION' ) && defined( 'CARGO_VERSION' ) ) {
                        $text .= "\t<p>\n";
+                       $text .= "<label class=\"is_hierarchy\"><input 
type=\"checkbox\" name=\"is_hierarchy_" . $id . "\"/> " . wfMessage( 
'pf_createtemplate_fieldishierarchy' )->escaped() . 
"</label>&nbsp;&nbsp;&nbsp;\n";
+                       $text .= "\t</p>\n";
+
+                       $text .= "\t<p>\n";
                        $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<label class=\"hierarchy_structure_input\" 
style=\"display: none;\">" . wfMessage( 
'pf_createproperty_allowedvalsforhierarchy' )->escaped();
+                       $text .= Html::textarea( 'hierarchy_structure_' . $id, 
null,
+                               array( 'rows' => '10', 'cols' => '80', 
'placeholder' => wfMessage( 'pf_createtemplate_hierarchystructureplaceholder' 
)->escaped() ) ) . "</label>\n";
                        $text .= "\t</p>\n";
                }
                $text .= "\t</td><td>\n";
@@ -204,9 +212,14 @@
                                        $field->setFieldType( $req->getVal( 
'field_type_' . $id ) );
 
                                        if ( defined( 'CARGO_VERSION' ) ) {
-                                               $allowedValuesStr = 
$req->getVal( 'allowed_values_' . $id );
-                                               $possibleValues = 
CargoUtils::smartSplit( ',', $allowedValuesStr );
-                                               $field->setPossibleValues( 
$possibleValues );
+                                               if ( $req->getCheck( 
'is_hierarchy_' .  $id ) ) {
+                                                       $hierarchyStructureStr 
= $req->getVal( 'hierarchy_structure_' . $id );
+                                                       
$field->setHierarchyStructure( $hierarchyStructureStr );
+                                               } else {
+                                                       $allowedValuesStr = 
$req->getVal( 'allowed_values_' . $id );
+                                                       $possibleValues = 
CargoUtils::smartSplit( ',', $allowedValuesStr );
+                                                       
$field->setPossibleValues( $possibleValues );
+                                               }
                                        }
 
                                        $fields[] = $field;

-- 
To view, visit https://gerrit.wikimedia.org/r/371160
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Icdac918b41d0456b720617f85b385a5c166ee4d9
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 <[email protected]>
Gerrit-Reviewer: Nischayn22 <[email protected]>
Gerrit-Reviewer: Oetterer <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to