Fixed default options support in Inspector, minor improvement in the components API.

This commit is contained in:
alekseybobkov 2015-01-18 19:20:33 -08:00
parent 291a5b46aa
commit 8ff242c1d0
3 changed files with 61 additions and 15 deletions

View File

@ -1537,6 +1537,12 @@ try{this.originalPropertyValues=$.extend(true,{},this.propertyValues)}catch(err)
Inspector.prototype.readProperty=function(property,returnUndefined){if(this.propertyValues[property]!==undefined)
return this.propertyValues[property]
return returnUndefined?undefined:null}
Inspector.prototype.getDefaultValue=function(property){for(var index in this.config){var propertyInfo=this.config[index]
if(propertyInfo.itemType!=='property')
continue
if(propertyInfo.property==property)
return propertyInfo.default}
return undefined}
Inspector.prototype.writeProperty=function(property,value,noChangedStatusUpdate){this.propertyValues[property]=value
if(this.propertyValuesField.length)
this.propertyValuesField.val(JSON.stringify(this.propertyValues))
@ -1685,7 +1691,9 @@ InspectorEditorDropdown.prototype.getTemplate=function(){return'
</select> \
</td> \
';}
InspectorEditorDropdown.prototype.init=function(){var value=this.inspector.readProperty(this.fieldDef.property),self=this
InspectorEditorDropdown.prototype.init=function(){var value=this.inspector.readProperty(this.fieldDef.property,true),self=this
if(value===undefined)
value=this.inspector.getDefaultValue(this.fieldDef.property)
$(this.selector).attr('data-no-auto-update-on-render','true')
$(this.selector).val(value)
if(!Modernizr.touch){var options={dropdownCssClass:'ocInspectorDropdown'}
@ -1710,7 +1718,12 @@ InspectorEditorDropdown.prototype.showLoadingIndicator=function(){if(!Modernizr.
this.indicatorContainer.loadIndicator({'opaque':true})}
InspectorEditorDropdown.prototype.hideLoadingIndicator=function(){if(!Modernizr.touch)
this.indicatorContainer.loadIndicator('hide')}
InspectorEditorDropdown.prototype.loadOptions=function(initialization){var $form=$(this.selector).closest('form'),data=this.inspector.propertyValues,$select=$(this.selector),currentValue=this.inspector.readProperty(this.fieldDef.property),self=this
InspectorEditorDropdown.prototype.loadOptions=function(initialization){var $form=$(this.selector).closest('form'),data=this.inspector.propertyValues,$select=$(this.selector),currentValue=this.inspector.readProperty(this.fieldDef.property,true),self=this
if(currentValue===undefined)
currentValue=this.inspector.getDefaultValue(this.fieldDef.property)
for(var index in this.inspector.config){var propertyInfo=this.inspector.config[index]
if(propertyInfo.itemType=='property'){if(data[propertyInfo.property]===undefined)
data[propertyInfo.property]=this.inspector.getDefaultValue(propertyInfo.property)}}
if(this.fieldDef.depends)
this.saveDependencyValues()
data.inspectorProperty=this.fieldDef.property

View File

@ -28,6 +28,7 @@
* - validationPattern (regex pattern for for validating the value, supported by the text editor)
* - validationMessage (a message to display if the validation fails)
* - placeholder - placholder text, for text and dropdown properties
* - default - default option for dropdown properties
* - depends - a list of properties the property depend on, for dropdown lists
* - options - an option list for dropdown lists, optional. If not provided the options are loaded with AJAX.
* - showExternalParam - specifies the visibility of the external parameter feature for the property. Default: true.
@ -609,6 +610,20 @@
return returnUndefined ? undefined : null
}
Inspector.prototype.getDefaultValue = function(property) {
for (var index in this.config) {
var propertyInfo = this.config[index]
if (propertyInfo.itemType !== 'property')
continue
if (propertyInfo.property == property)
return propertyInfo.default
}
return undefined
}
Inspector.prototype.writeProperty = function(property, value, noChangedStatusUpdate) {
this.propertyValues[property] = value
@ -987,9 +1002,12 @@
}
InspectorEditorDropdown.prototype.init = function() {
var value = this.inspector.readProperty(this.fieldDef.property),
var value = this.inspector.readProperty(this.fieldDef.property, true),
self = this
if (value === undefined)
value = this.inspector.getDefaultValue(this.fieldDef.property)
$(this.selector).attr('data-no-auto-update-on-render', 'true')
$(this.selector).val(value)
@ -1058,9 +1076,21 @@
var $form = $(this.selector).closest('form'),
data = this.inspector.propertyValues,
$select = $(this.selector),
currentValue = this.inspector.readProperty(this.fieldDef.property),
currentValue = this.inspector.readProperty(this.fieldDef.property, true),
self = this
if (currentValue === undefined)
currentValue = this.inspector.getDefaultValue(this.fieldDef.property)
for (var index in this.inspector.config) {
var propertyInfo = this.inspector.config[index]
if (propertyInfo.itemType == 'property') {
if (data[propertyInfo.property] === undefined)
data[propertyInfo.property] = this.inspector.getDefaultValue(propertyInfo.property)
}
}
if (this.fieldDef.depends)
this.saveDependencyValues()

View File

@ -13,22 +13,25 @@ class ComponentHelpers
/**
* Returns a component property configuration as a JSON string.
* @param mixed $component The component object
* @param boolean $addAliasProperty Determines if the Alias property should be added to the result.
* @return string
*/
public static function getComponentsPropertyConfig($component)
public static function getComponentsPropertyConfig($component, $addAliasProperty = true)
{
$result = [];
$property = [
'property' => 'oc.alias',
'title' => Lang::get('cms::lang.component.alias'),
'description' => Lang::get('cms::lang.component.alias_description'),
'type' => 'string',
'validationPattern' => '^[a-zA-Z]+[0-9a-z\_]*$',
'validationMessage' => Lang::get('cms::lang.component.validation_message'),
'showExternalParam' => false
];
$result[] = $property;
if ($addAliasProperty) {
$property = [
'property' => 'oc.alias',
'title' => Lang::get('cms::lang.component.alias'),
'description' => Lang::get('cms::lang.component.alias_description'),
'type' => 'string',
'validationPattern' => '^[a-zA-Z]+[0-9a-z\_]*$',
'validationMessage' => Lang::get('cms::lang.component.validation_message'),
'showExternalParam' => false
];
$result[] = $property;
}
$properties = $component->defineProperties();
foreach ($properties as $name => $params) {