Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371160 )

Change subject: Work in Progress : Add hierarchy field creation in create 
template
......................................................................

Work in Progress : Add hierarchy field creation in create template

Change-Id: Icdac918b41d0456b720617f85b385a5c166ee4d9
---
M i18n/en.json
M i18n/qqq.json
M libs/PF_CreateTemplate.js
M specials/PF_CreateTemplate.php
4 files changed, 33 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms 
refs/changes/60/371160/1

diff --git a/i18n/en.json b/i18n/en.json
index 19f67e3..42f77cb 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -51,6 +51,8 @@
        "pf_createtemplate_displaylabel": "Display label:",
        "pf_createtemplate_semanticproperty": "Semantic property:",
        "pf_createtemplate_fieldislist": "Field holds a list of values",
+       "pf_createtemplate_fieldishierarchy": "Field holds hierarchy value(s)",
+       "pf_createtemplate_hierarchystructureplaceholder": 
"*Asia\n**India\n***New Delhi\n**China\n***Beijing\n*North America\n**United 
States\n***Washington\n",
        "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..6d43040 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -67,6 +67,8 @@
        "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_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/libs/PF_CreateTemplate.js b/libs/PF_CreateTemplate.js
index cab466d..7f198b8 100644
--- a/libs/PF_CreateTemplate.js
+++ b/libs/PF_CreateTemplate.js
@@ -26,6 +26,10 @@
        newField.find( ".isList" ).click( function () {
                jQuery( this ).closest( ".fieldBox" ).find( ".delimiter" 
).toggle();
        } );
+       newField.find( ".isHierarchy" ).click( function () {
+               jQuery( this ).closest( ".fieldBox" ).find( 
".allowed_values_input" ).toggle();
+               jQuery( this ).closest( ".fieldBox" ).find( 
".hierarchy_structure_input" ).toggle();
+       } );
        var combobox = new pf.select2.combobox();
        combobox.apply( $( newField.find( '.pfComboBox' ) ) );
        jQuery( '#fieldsList' ).append( newField );
@@ -66,6 +70,10 @@
        jQuery( ".isList" ).click( function () {
                jQuery( this ).closest( ".fieldBox" ).find( ".delimiter" 
).toggle();
        } );
+       jQuery( ".isHierarchy" ).click( function () {
+               jQuery( this ).closest( ".fieldBox" ).find( 
".allowed_values_input" ).toggle();
+               jQuery( this ).closest( ".fieldBox" ).find( 
".hierarchy_structure_input" ).toggle();
+       } );
        jQuery( '#createTemplateForm' ).submit( function () {
                return validateCreateTemplateForm();
        } );
diff --git a/specials/PF_CreateTemplate.php b/specials/PF_CreateTemplate.php
index 0ba2cce..b19b635 100644
--- a/specials/PF_CreateTemplate.php
+++ b/specials/PF_CreateTemplate.php
@@ -121,9 +121,19 @@
                $text .= "\t</p>\n";
                if ( !defined( 'SMW_VERSION' ) && defined( 'CARGO_VERSION' ) ) {
                        $text .= "\t<p>\n";
+                       $text .= "<label><input type=\"checkbox\" 
name=\"is_hierarchy_" . $id . "\" class=\"isHierarchy\" /> " . 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</p>\n";
+
+                       $text .= "\t<p>\n";
+                       $text .= "\t<label class=\"hierarchy_structure_input\" 
style=\"display: none;\">" . wfMessage( 'pf_createproperty_allowedvalsinput' 
)->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 +214,17 @@
                                        $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->setPossibleValues( array( $hierarchyStructureStr ) );
+                                                       // TODO Probably can do 
with setHierarchyStructure
+                                                       
$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: newchange
Gerrit-Change-Id: Icdac918b41d0456b720617f85b385a5c166ee4d9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 <f29ah...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to