API Docs for: 1.0.0
Show:

File: Resources/public/js/views/fields/ez-relationlist-view.js

  1. /*
  2. * Copyright (C) eZ Systems AS. All rights reserved.
  3. * For full copyright and license information view LICENSE file distributed with this source code.
  4. */
  5. YUI.add('ez-relationlist-view', function (Y) {
  6. "use strict";
  7. /**
  8. * Provides the Relation list View class
  9. *
  10. * @module ez-relationlist-view
  11. */
  12. Y.namespace('eZ');
  13.  
  14. /**
  15. * The relation list view
  16. *
  17. * @namespace eZ
  18. * @class RelationListView
  19. * @constructor
  20. * @extends eZ.FieldView
  21. */
  22. Y.eZ.RelationListView = Y.Base.create('relationlistView', Y.eZ.FieldView, [Y.eZ.AsynchronousView], {
  23. initializer: function () {
  24. this._fireMethod = this._fireLoadObjectRelations;
  25. this._watchAttribute = 'relatedContents';
  26. },
  27.  
  28. /**
  29. * Checks whether the field is empty
  30. *
  31. * @method _isFieldEmpty
  32. * @protected
  33. * @return {Boolean}
  34. */
  35. _isFieldEmpty: function () {
  36. var fieldValue = this.get('field').fieldValue;
  37.  
  38. return (!fieldValue || !fieldValue.destinationContentIds || !fieldValue.destinationContentIds.length);
  39. },
  40.  
  41. /**
  42. * Fire the `loadObjectRelations` event to retrieve the related contents
  43. *
  44. * @method _fireLoadObjectRelations
  45. * @protected
  46. */
  47. _fireLoadObjectRelations: function () {
  48. if (!this._isFieldEmpty()){
  49. this.fire('loadObjectRelations', {
  50. relationType: 'ATTRIBUTE',
  51. fieldDefinitionIdentifier: this.get('fieldDefinition').identifier,
  52. content: this.get('content'),
  53. });
  54. }
  55. },
  56.  
  57. /**
  58. * Returns an object containing the additional variables
  59. *
  60. * @method _variables
  61. * @protected
  62. * @return Object
  63. */
  64. _variables: function () {
  65. var relatedContents = this.get('relatedContents'),
  66. relatedContentsJSON = [];
  67.  
  68. Y.Array.each(relatedContents, function (value) {
  69. relatedContentsJSON.push(value.toJSON());
  70. });
  71.  
  72. return {
  73. relatedContents: relatedContentsJSON,
  74. loadingError: this.get('loadingError'),
  75. };
  76. },
  77. },{
  78. ATTRS: {
  79. /**
  80. * The related contents of the relation list
  81. *
  82. * @attribute relatedContents
  83. * @type Array
  84. */
  85. relatedContents: {
  86. value: null,
  87. },
  88. },
  89. });
  90.  
  91. Y.eZ.FieldView.registerFieldView('ezobjectrelationlist', Y.eZ.RelationListView);
  92. });
  93.