Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #177 from StephaneDiot/EZP-21715_Give_config_to_fi…
Browse files Browse the repository at this point in the history
…eldEditViews

EZP-21715: As an editor, I want to be able edit country fields. 1rst part: Give route config to fieldEditViews
  • Loading branch information
dpobel committed Feb 20, 2015
2 parents cbd84d4 + 8f839f4 commit ba9aa0b
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 76 deletions.
40 changes: 29 additions & 11 deletions Resources/public/js/views/ez-contenteditformview.js
Expand Up @@ -32,11 +32,7 @@ YUI.add('ez-contenteditformview', function (Y) {
},

initializer: function () {
this.after('contentTypeChange', this._setFieldEditViews);
if ( this.get('contentType') ) {
this._setFieldEditViews();
}

this._setFieldEditViews();
this.after('activeChange', function (e) {
Y.Array.each(this._fieldEditViews, function (view) {
view.set('active', e.newVal);
Expand All @@ -56,20 +52,25 @@ YUI.add('ez-contenteditformview', function (Y) {
contentType = this.get('contentType'),
fieldDefinitions = contentType.get('fieldDefinitions'),
views = [],
that = this;
that = this,
config = this.get('config');

Y.Object.each(fieldDefinitions, function (def) {
var EditView, view;
var EditView, view, fieldConfig;

try {
EditView = Y.eZ.FieldEditView.getFieldEditView(def.fieldType);

if (config && config.fieldEditViews && config.fieldEditViews[def.fieldType]) {
fieldConfig = config.fieldEditViews[def.fieldType];
}
view = new EditView({
content: content,
version: version,
contentType: contentType,
fieldDefinition: def,
field: version.getField(def.identifier)
field: version.getField(def.identifier),
config: fieldConfig,
});
views.push(view);
view.addTarget(that);
Expand Down Expand Up @@ -195,7 +196,9 @@ YUI.add('ez-contenteditformview', function (Y) {
* @type {eZ.ContentType}
* @required
*/
contentType: {},
contentType: {
writeOnce: "initOnly",
},

/**
* The content instance
Expand All @@ -205,7 +208,9 @@ YUI.add('ez-contenteditformview', function (Y) {
* @type {eZ.Content}
* @required
*/
content: {},
content: {
writeOnce: "initOnly",
},

/**
* The version handled in the form view
Expand All @@ -215,7 +220,20 @@ YUI.add('ez-contenteditformview', function (Y) {
* @type {eZ.Version}
* @required
*/
version: {},
version: {
writeOnce: "initOnly",
},

/**
* A configuration object for the field edit views.
*
* @attribute config
* @type Mixed
* @writeOnce
*/
config: {
writeOnce: "initOnly",
},
}
});
});
46 changes: 25 additions & 21 deletions Resources/public/js/views/ez-contenteditview.js
Expand Up @@ -221,12 +221,7 @@ YUI.add('ez-contenteditview', function (Y) {
* @required
*/
content: {
value: {},
setter: function (val, name) {
this.get('formView').set('content', val);
this.get('actionBar').set('content', val);
return val;
}
writeOnce: "initOnly",
},

/**
Expand All @@ -237,12 +232,7 @@ YUI.add('ez-contenteditview', function (Y) {
* @required
*/
version: {
value: {},
setter: function (val, name) {
this.get('formView').set('version', val);
this.get('actionBar').set('version', val);
return val;
}
writeOnce: "initOnly",
},

/**
Expand All @@ -253,11 +243,7 @@ YUI.add('ez-contenteditview', function (Y) {
* @required
*/
contentType: {
value: {},
setter: function (val, name) {
this.get('formView').set('contentType', val);
return val;
}
writeOnce: "initOnly",
},

/**
Expand All @@ -268,7 +254,7 @@ YUI.add('ez-contenteditview', function (Y) {
* @required
*/
mainLocation: {
value: {}
writeOnce: "initOnly",
},

/**
Expand All @@ -279,7 +265,18 @@ YUI.add('ez-contenteditview', function (Y) {
* @required
*/
owner: {
value: {}
writeOnce: "initOnly",
},

/**
* A configuration object coming from the application route configuration
*
* @attribute config
* @type Mixed
* @writeOnce
*/
config: {
writeOnce: "initOnly",
},

/**
Expand All @@ -292,7 +289,12 @@ YUI.add('ez-contenteditview', function (Y) {
*/
formView: {
valueFn: function () {
return new Y.eZ.ContentEditFormView();
return new Y.eZ.ContentEditFormView({
config: this.get('config'),
contentType: this.get('contentType'),
content: this.get('content'),
version: this.get('version')
});
}
},

Expand All @@ -306,7 +308,9 @@ YUI.add('ez-contenteditview', function (Y) {
*/
actionBar: {
valueFn: function () {
return new Y.eZ.EditActionBarView();
return new Y.eZ.EditActionBarView({
version: this.get('version')
});
}
}
}
Expand Down
Expand Up @@ -146,7 +146,8 @@ YUI.add('ez-contenteditviewservice', function (Y) {
version: this.get('version'),
mainLocation: this.get('location'),
contentType: this.get('contentType'),
owner: this.get('owner')
owner: this.get('owner'),
config: this.get('config'),
};
},

Expand Down
3 changes: 3 additions & 0 deletions Resources/views/PlatformUI/shell.html.twig
Expand Up @@ -80,6 +80,9 @@
"fieldViews": {
"ezcountry": {{countriesInfo|json_encode|raw}}
}
},
"editContent": {
"fieldEditViews": {}
}
}
});
Expand Down
64 changes: 59 additions & 5 deletions Tests/js/views/assets/ez-contenteditformview-tests.js
Expand Up @@ -28,6 +28,12 @@ YUI.add('ez-contenteditformview-tests', function (Y) {
this.contentType = new Y.Mock();
this.content = new Y.Mock();
this.version = new Y.Mock();
this.config = {
editViews: {
test1: 'hello'
}
};

Y.Mock.expect(this.contentType, {
method: 'getFieldGroups',
returns: [{
Expand Down Expand Up @@ -72,7 +78,8 @@ YUI.add('ez-contenteditformview-tests', function (Y) {
container: '.container',
contentType: this.contentType,
content: this.content,
version: this.version
version: this.version,
config: this.config
});
},

Expand Down Expand Up @@ -164,8 +171,37 @@ YUI.add('ez-contenteditformview-tests', function (Y) {
});
});
this.wait();
}
},

"Should give the config to the fieldEditView": function () {
var that = this;

this.view = new Y.eZ.ContentEditFormView({
container: '.container',
contentType: this.contentType,
content: this.content,
version: this.version,
config: {
editViews: {
test1: 'hello'
}
}
});

this.view.set('active', true);

Y.Array.each(this.fieldDefinitions, function (def) {
if (that.view.get('config').editViews[def.fieldType]){
Y.Assert.areSame(
that.config[def.fieldType],
that.view.get('config').editViews[def.fieldType],
"The config should be passed to the fieldView if fieldType match"
);
} else {
Y.Assert.isUndefined(that.config[def.fieldType], 'The fieldView should NOT have config if fieldType do Not match');
}
});
},
});

isValidTest = new Y.Test.Case({
Expand All @@ -176,6 +212,11 @@ YUI.add('ez-contenteditformview-tests', function (Y) {

this.contentType = new Y.Mock();
this.version = new Y.Mock();
this.config = {
editViews: {
something: 'hello'
}
};

Y.Mock.expect(this.contentType, {
method: 'get',
Expand Down Expand Up @@ -226,7 +267,8 @@ YUI.add('ez-contenteditformview-tests', function (Y) {

this.view = new Y.eZ.ContentEditFormView({
contentType: this.contentType,
version: this.version
version: this.version,
config: this.config
});
},

Expand Down Expand Up @@ -290,6 +332,11 @@ YUI.add('ez-contenteditformview-tests', function (Y) {

this.contentType = new Y.Mock();
this.version = new Y.Mock();
this.config = {
editViews: {
something: 'hello'
}
};

Y.Mock.expect(this.contentType, {
method: 'get',
Expand Down Expand Up @@ -340,7 +387,8 @@ YUI.add('ez-contenteditformview-tests', function (Y) {

this.view = new Y.eZ.ContentEditFormView({
contentType: this.contentType,
version: this.version
version: this.version,
config: this.config
});
},

Expand Down Expand Up @@ -385,6 +433,11 @@ YUI.add('ez-contenteditformview-tests', function (Y) {

this.contentType = new Y.Mock();
this.version = new Y.Mock();
this.config = {
editViews: {
something: 'hello'
}
};

Y.Mock.expect(this.contentType, {
method: 'get',
Expand Down Expand Up @@ -430,7 +483,8 @@ YUI.add('ez-contenteditformview-tests', function (Y) {

this.view = new Y.eZ.ContentEditFormView({
contentType: this.contentType,
version: this.version
version: this.version,
config: this.config
});
},

Expand Down

0 comments on commit ba9aa0b

Please sign in to comment.