Skip to content

Commit 90ccbd6

Browse files
author
Nathan McMinn
committed
Multiple fixes to pageSelect and dependentSelect
JS and FTL fixes to page select and dependent select controls.
1 parent 8fc819e commit 90ccbd6

File tree

3 files changed

+67
-33
lines changed

3 files changed

+67
-33
lines changed

pdf-toolkit-share/src/main/amp/config/alfresco/web-extension/site-webscripts/org/alfresco/pdftoolkit/components/form/controls/dependentSelect.ftl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<#else>
3232
<label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
3333
<#if field.control.params.options?? && field.control.params.options != "">
34-
<select id="${fieldHtmlId}" name="${field.name}" onchange="DependentSelect.toggleDependentFields()" tabindex="0"
34+
<select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
3535
<#if field.description??>title="${field.description}"</#if>
3636
<#if field.control.params.size??>size="${field.control.params.size}"</#if>
3737
<#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
@@ -56,20 +56,26 @@
5656
5757
// first, set up the list of select values that trigger a change
5858
59-
var showSelectValues = {
59+
var showSelectValues = [
6060
<#list selectValues as value>
6161
6262
<#assign showWhenSelectedName = value?split(":")[0]>
63-
${value}
64-
${value?split(":")?size}
65-
${showWhenSelectedName}:[
66-
],
63+
<#assign showWhenSelectedValues = value?split(":")[1]?split(",")>
64+
{'name':'${showWhenSelectedName}',
65+
'fields':[
66+
<#list showWhenSelectedValues as show>
67+
'${show}'<#if show_has_next>,</#if>
68+
</#list>
69+
]}<#if value_has_next>,</#if>
6770
</#list>
68-
}
71+
]
6972
// next, set up the object that contains the fields to show / hide based on
7073
// the value of the selects
7174
var DependentSelect = new PDFToolkit.DependentSelect("${fieldHtmlId}").setOptions(
7275
{
7376
showSelectValues: showSelectValues,
74-
});
77+
htmlId: "${args.htmlid}"
78+
}).setMessages(
79+
{}
80+
);
7581
//]]></script>

pdf-toolkit-share/src/main/resources/META-INF/pdftoolkit/components/doclib/pdftoolkit-doclib-actions.js

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ PDFToolkit.Util = {};
4949
* @property nodeRef
5050
* @type string
5151
*/
52-
nodeRef: null
52+
nodeRef: null,
53+
54+
/**
55+
* Do we show the page scheme options?
56+
*
57+
* @property showPageSchemes
58+
* @type boolean
59+
*/
60+
showPageScheme: false,
5361
},
5462

5563
schemesModule: null,
@@ -59,13 +67,15 @@ PDFToolkit.Util = {};
5967
onReady: function SelectPage_onReady()
6068
{
6169
this.getPageCount(this.options.nodeRef);
62-
this.getPageSchemes(this.options.nodeRef);
63-
64-
this.schemesModule = new YAHOO.widget.Module(this.id + "-schemeModule");
6570
this.pagesModule = new YAHOO.widget.Module(this.id + "-pageModule");
6671

67-
// default state is schemes enabled, page select hidden
68-
this.pagesModule.hide();
72+
if(this.options.showPageScheme === "true")
73+
{
74+
this.schemesModule = new YAHOO.widget.Module(this.id + "-schemeModule");
75+
this.getPageSchemes(this.options.nodeRef);
76+
// default state is page select hidden if page schemes enabled,
77+
this.pagesModule.hide();
78+
}
6979

7080
YAHOO.util.Event.addListener([this.id + "-useScheme"], "click", this.toggleSchemes, this);
7181
},
@@ -169,10 +179,10 @@ PDFToolkit.Util = {};
169179
Selector = YAHOO.util.Selector;
170180

171181
/**
172-
* SelectPage constructor.
182+
* DependentSelect constructor.
173183
*
174184
* @param {String} htmlId The HTML id of the parent element
175-
* @return {PDFToolkit.SelectPage} The new component instance
185+
* @return {PDFToolkit.DependentSelect} The new component instance
176186
* @constructor
177187
*/
178188
PDFToolkit.DependentSelect = function DependentSelect_constructor(htmlId)
@@ -183,31 +193,51 @@ PDFToolkit.Util = {};
183193

184194
YAHOO.extend(PDFToolkit.DependentSelect, Alfresco.component.Base,
185195
{
186-
/**
187-
* Object container for initialization options
188-
*
189-
* @property options
190-
* @type {object} object literal
191-
*/
192196
options:
193197
{
194198
/**
195-
* Reference to the pdf document
199+
* The show / hide configuration(s) for the form controls
196200
*
197201
* @property nodeRef
198202
* @type string
199203
*/
200-
nodeRef: null
204+
showSelectValues: []
201205
},
202206

203207
onReady: function DependentSelect_onReady()
204208
{
205-
209+
YAHOO.util.Event.addListener([this.id], "change", this.toggleDependentFields, this);
206210
},
207211

208-
toggleDependentFields: function DependentSelect_toggleSchemes(event, that)
212+
toggleDependentFields: function DependentSelect_toggleDependentFields(event, that)
209213
{
210-
214+
var config = that.options.showSelectValues;
215+
// anything assigned to another show value will be hidden
216+
for(index in config)
217+
{
218+
219+
var name = config[index].name;
220+
var fields = config[index].fields;
221+
222+
// if the event source is the right option, show the fields
223+
// if it is not, hide these fields
224+
if(name === event.srcElement.value)
225+
{
226+
for(fieldIndex in fields)
227+
{
228+
var fieldId = YAHOO.util.Dom.get(that.options.htmlId) + "_" + fields[fieldIndex] + "-cntrl";
229+
fieldId.style.display = 'block';
230+
}
231+
}
232+
else
233+
{
234+
for(fieldIndex in fields)
235+
{
236+
var fieldId = YAHOO.util.Dom.get(that.options.htmlId) + "_" + fields[fieldIndex] + "-cntrl";
237+
fieldId.style.display = 'none';
238+
}
239+
}
240+
}
211241
}
212242
});
213243
})();

pdf-toolkit-share/src/main/resources/META-INF/share-config-custom.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@
372372
<show id="key-type"/>
373373
<show id="key-password"/>
374374
<show id="store-password"/>
375-
<show id="visibility"/>
376375
<show id="location"/>
377376
<show id="reason"/>
377+
<show id="visibility"/>
378378
<show id="page"/>
379379
<show id="position"/>
380380
<show id="location-x"/>
@@ -395,8 +395,7 @@
395395
</field>
396396
<field id="position">
397397
<control template="/org/alfresco/pdftoolkit/components/form/controls/dependentSelect.ftl">
398-
<control-param name="showSelectValues">manual</control-param>
399-
<control-param name="showWhenSelected-manual">location-x,location-y</control-param>
398+
<control-param name="showSelectValues">manual:prop_location-x,prop_location-y</control-param>
400399
</control>
401400
</field>
402401
</appearance>
@@ -434,13 +433,12 @@
434433
</field>
435434
<field id="position">
436435
<control template="/org/alfresco/pdftoolkit/components/form/controls/dependentSelect.ftl">
437-
<control-param name="showSelectValues">manual</control-param>
438-
<control-param name="showWhenSelected-manual">location-x,location-y</control-param>
436+
<control-param name="showSelectValues">manual:prop_location-x,prop_location-y</control-param>
439437
</control>
440438
</field>
441439
<field id="watermark-type">
442440
<control template="/org/alfresco/pdftoolkit/components/form/controls/dependentSelect.ftl">
443-
<control-param name="showSelectValues">text:watermark-text,watermark-font,watermark-size;image:watermark-image</control-param>
441+
<control-param name="showSelectValues">text:prop_watermark-text,prop_watermark-font,prop_watermark-size;image:assoc_watermark-image</control-param>
444442
</control>
445443
</field>
446444
</appearance>

0 commit comments

Comments
 (0)