diff --git a/Resources/public/js/views/fields/ez-relation-editview.js b/Resources/public/js/views/fields/ez-relation-editview.js index c1955f07b..d3130006a 100644 --- a/Resources/public/js/views/fields/ez-relation-editview.js +++ b/Resources/public/js/views/fields/ez-relation-editview.js @@ -91,16 +91,47 @@ YUI.add('ez-relation-editview', function (Y) { * @return Object */ _variables: function () { - var dest = this.get('destinationContent'); + var destinationContent = this.get('destinationContent'), + destinationContentJSON = null, + isLoaded = destinationContent !== null; + + if (isLoaded && (this._isNewRelation(destinationContent) || !this._isTrashed(destinationContent))) { + destinationContentJSON = destinationContent.toJSON(); + } return { - destinationContent: dest ? dest.toJSON() : null, + destinationContent: destinationContentJSON, loadingError: this.get('loadingError'), isEmpty: this._isFieldEmpty(), + isLoaded: isLoaded, isRequired: this.get('fieldDefinition').isRequired, }; }, + /** + * Check if related content is trashed. + * + * @method _isTrashed + * @protected + * @param {eZ.ContentInfo|ez.eZ.Content} model + * @return {boolean} + */ + _isTrashed: function(model) { + return !model.get('resources.MainLocation'); + }, + + /** + * Check if relation to the content is new (non-existed before edit) + * + * @method _isNewRelation + * @protected + * @param {eZ.ContentInfo|ez.eZ.Content} model + * @return {boolean} + */ + _isNewRelation: function (model) { + return model.name === 'contentInfoModel'; + }, + /** * Tap event handler for the remove button. It resets the relation. * diff --git a/Resources/public/js/views/fields/ez-relation-view.js b/Resources/public/js/views/fields/ez-relation-view.js index 8f45a898b..f490349ea 100644 --- a/Resources/public/js/views/fields/ez-relation-view.js +++ b/Resources/public/js/views/fields/ez-relation-view.js @@ -59,10 +59,18 @@ YUI.add('ez-relation-view', function (Y) { * @return Object */ _variables: function () { - var dest = this.get('destinationContent'); + var destinationContent = this.get('destinationContent'), + destinationContentJSON = null, + isLoaded = destinationContent !== null; + + if (isLoaded && destinationContent.get('resources.MainLocation') !== undefined) { + destinationContentJSON = destinationContent.toJSON(); + } return { - destinationContent: dest ? dest.toJSON() : null, + destinationContent: destinationContentJSON, + isLoaded: isLoaded, + isEmpty: this._isFieldEmpty(), loadingError: this.get('loadingError'), }; }, diff --git a/Resources/public/templates/fields/edit/relation.hbt b/Resources/public/templates/fields/edit/relation.hbt index be466ce65..9364a98ae 100644 --- a/Resources/public/templates/fields/edit/relation.hbt +++ b/Resources/public/templates/fields/edit/relation.hbt @@ -15,50 +15,58 @@
- {{translate "relation.empty" "fieldedit"}} -
- {{else}} - {{#if destinationContent }} -+ {{translate "relation.empty" "fieldedit"}} +
{{else}} - {{#if loadingError}} - + {{#if isLoaded}} + {{#if destinationContent }} ++ {{translate "relation.empty" "fieldedit"}} +
+ {{/if}} + {{/if}} {{else}} {{/if}} {{/if}} - {{/if}} -- - -
-+ + +
+{{ translate_property fieldDefinition.names }}