diff --git a/examples/blog/config.js b/examples/blog/config.js index bbde5db6..95bfcc7d 100644 --- a/examples/blog/config.js +++ b/examples/blog/config.js @@ -128,7 +128,7 @@ nga.field('average_note', 'float') .cssClasses('col-sm-4'), nga.field('comments', 'referenced_list') // display list of related comments - .targetEntity(comment) + .targetEntity(nga.entity('comments')) .targetReferenceField('post_id') .targetFields([ nga.field('id').isDetailLink(true), diff --git a/src/javascripts/ng-admin/Crud/CrudModule.js b/src/javascripts/ng-admin/Crud/CrudModule.js index c9521ff1..b6bf5689 100644 --- a/src/javascripts/ng-admin/Crud/CrudModule.js +++ b/src/javascripts/ng-admin/Crud/CrudModule.js @@ -55,6 +55,7 @@ CrudModule.directive('maChoicesColumn', require('./column/maChoicesColumn')); CrudModule.directive('maDateColumn', require('./column/maDateColumn')); CrudModule.directive('maJsonColumn', require('./column/maJsonColumn')); CrudModule.directive('maNumberColumn', require('./column/maNumberColumn')); +CrudModule.directive('maReferencedListColumn', require('./column/maReferencedListColumn')); CrudModule.directive('maReferenceManyColumn', require('./column/maReferenceManyColumn')); CrudModule.directive('maReferenceManyLinkColumn', require('./column/maReferenceManyLinkColumn')); CrudModule.directive('maStringColumn', require('./column/maStringColumn')); diff --git a/src/javascripts/ng-admin/Crud/column/maReferencedListColumn.js b/src/javascripts/ng-admin/Crud/column/maReferencedListColumn.js new file mode 100644 index 00000000..2ee15787 --- /dev/null +++ b/src/javascripts/ng-admin/Crud/column/maReferencedListColumn.js @@ -0,0 +1,29 @@ +function maReferencedListColumn(NgAdminConfiguration) { + return { + scope: { + 'field': '&', + 'datastore': '&' + }, + restrict: 'E', + link: { + pre: function(scope) { + scope.field = scope.field(); + var targetEntity = scope.field.targetEntity(); + scope.entries = scope.datastore().getEntries(targetEntity.uniqueId + '_list'); + scope.entity = NgAdminConfiguration().getEntity(targetEntity.name()); + } + }, + template: ` + +` + }; +} + +maReferencedListColumn.$inject = ['NgAdminConfiguration']; + +module.exports = maReferencedListColumn; + diff --git a/src/javascripts/ng-admin/Crud/field/maField.js b/src/javascripts/ng-admin/Crud/field/maField.js index c2d4bea0..5e1f6ebc 100644 --- a/src/javascripts/ng-admin/Crud/field/maField.js +++ b/src/javascripts/ng-admin/Crud/field/maField.js @@ -1,83 +1,77 @@ -/*global define*/ +var _ = require('lodash'); -define(function (require) { - 'use strict'; - - var _ = require('lodash'); - - function maField(FieldViewConfiguration) { - var writeWidgetTypes = _(FieldViewConfiguration) - .map(function(fieldView, field) { - return '' + fieldView.getWriteWidget() +''; - }).join(''); - var template = +function maField(FieldViewConfiguration) { + var writeWidgetTypes = _(FieldViewConfiguration) + .map(function(fieldView, field) { + return '' + fieldView.getWriteWidget() +''; + }).join(''); + var template = '
' + - '' + - '
' + - writeWidgetTypes + - '' + - '
' + - '
' + - '

' + - '' + - '

' + - '
' + +'' + +'
' + + writeWidgetTypes + + '' + +'
' + +'
' + + '

' + + '' + + '

' + +'
' + '
'; - return { - restrict: 'E', - scope: { - field: '&', - entry: '=', - entity: '&', - form: '&', - 'datastore': '&' - }, - link: function(scope) { - scope.field = scope.field(); - scope.type = scope.field.type(); - scope.entity = scope.entity(); - scope.form = scope.form(); - scope.datastore = scope.datastore(); + return { + restrict: 'E', + scope: { + field: '&', + entry: '=', + entity: '&', + form: '&', + datastore: '&' + }, + link: function(scope) { + scope.field = scope.field(); + scope.type = scope.field.type(); + scope.entity = scope.entity(); + scope.form = scope.form(); + scope.datastore = scope.datastore(); - scope.getClassesForField = function(field, entry) { - return 'ng-admin-field-' + field.name().replace('.', '_') + ' ' + (field.getCssClasses(entry) || 'col-sm-10 col-md-8 col-lg-7'); - }; + scope.getClassesForField = function(field, entry) { + return 'ng-admin-field-' + field.name().replace('.', '_') + ' ' + (field.getCssClasses(entry) || 'col-sm-10 col-md-8 col-lg-7'); + }; - scope.getInputForField = function(field) { - return scope.form[field.name()]; - }; + scope.getInputForField = function(field) { + return scope.form[field.name()]; + }; - /** - * Should validation status be displayed for a given field? - * - * - No for non-editable fields, or template fields which not have a corresponding input - * - No for non-altered input - * - Yes otherwise - */ - scope.fieldHasValidation = function(field) { - var input = this.getInputForField(field); - return input && input.$dirty; - }; + /** + * Should validation status be displayed for a given field? + * + * - No for non-editable fields, or template fields which not have a corresponding input + * - No for non-altered input + * - Yes otherwise + */ + scope.fieldHasValidation = function(field) { + var input = this.getInputForField(field); + return input && input.$dirty; + }; - scope.fieldIsValid = function(field) { - var input = this.getInputForField(field); - return input && input.$valid; - }; + scope.fieldIsValid = function(field) { + var input = this.getInputForField(field); + return input && input.$valid; + }; - scope.getFieldValidationClass = function(field) { - if (this.fieldHasValidation(field)) { - return this.fieldIsValid(field) ? 'has-success' : 'has-error'; - } - }; + scope.getFieldValidationClass = function(field) { + if (this.fieldHasValidation(field)) { + return this.fieldIsValid(field) ? 'has-success' : 'has-error'; + } + }; - }, - template: template - }; - } + }, + template: template + }; +} - maField.$inject = ['FieldViewConfiguration']; +maField.$inject = ['FieldViewConfiguration']; - return maField; -}); +module.exports = maField; diff --git a/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js index 8297dad9..ee65b78a 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js @@ -1,18 +1,6 @@ module.exports = { - getReadWidget: () => - '' + - '', + getReadWidget: () => '', getLinkWidget: () => 'error: cannot display referenced_list field as linkable', getFilterWidget: () => 'error: cannot display referenced_list field as filter', - getWriteWidget: () => - '' + - '' + getWriteWidget: () => '' }; diff --git a/src/javascripts/ng-admin/Crud/show/show.html b/src/javascripts/ng-admin/Crud/show/show.html index 0d030945..769a307d 100644 --- a/src/javascripts/ng-admin/Crud/show/show.html +++ b/src/javascripts/ng-admin/Crud/show/show.html @@ -24,7 +24,7 @@

- +