-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
198575f
commit 1645f61
Showing
4 changed files
with
95 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
/*global define*/ | ||
|
||
define(function (require) { | ||
'use strict'; | ||
|
||
/** | ||
* Edition field for an element in a list - a select. | ||
* | ||
* @example <ma-choice-field entry="entry" field="field" value="value"></ma-choice-field> | ||
*/ | ||
function maChoiceField() { | ||
return { | ||
scope: { | ||
'field': '&', | ||
'value': '=', | ||
'entry': '=?', | ||
'datastore': '&?' | ||
}, | ||
restrict: 'E', | ||
link: function(scope, element) { | ||
var field = scope.field(); | ||
scope.name = field.name(); | ||
scope.v = field.validation(); | ||
var choices; | ||
if (field.type() === 'reference' || field.type() === 'reference_many') { | ||
choices = scope.datastore().getChoices(field); | ||
} else { | ||
choices = field.choices(); | ||
} | ||
scope.getChoices = typeof(choices) === 'function' ? choices : function() { return choices; }; | ||
var select = element.children()[0]; | ||
var attributes = field.attributes(); | ||
for (var name in Object.keys(attributes)) { | ||
select[name] = attributes[name]; | ||
} | ||
}, | ||
template: ` | ||
<ui-select ng-model="$parent.value" ng-required="v.required" id="{{ name }}" name="{{ name }}"> | ||
<ui-select-match placeholder="Filter values">{{ $select.selected.label }}</ui-select-match> | ||
<ui-select-choices repeat="item.value as item in getChoices(entry) | filter: {label: $select.search}"> | ||
{{ item.label }} | ||
</ui-select-choices> | ||
</ui-select>` | ||
}; | ||
} | ||
|
||
maChoiceField.$inject = []; | ||
|
||
return maChoiceField; | ||
}); | ||
function maChoiceField($compile) { | ||
return { | ||
scope: { | ||
'field': '&', | ||
'value': '=', | ||
'entry': '=?', | ||
'datastore': '&?' | ||
}, | ||
restrict: 'E', | ||
compile: function() { | ||
return { | ||
pre: function(scope, element) { | ||
var template = ` | ||
<ui-select ng-model="$parent.value" ng-required="v.required" id="{{ name }}" name="{{ name }}"> | ||
<ui-select-match placeholder="Filter values">{{ $select.selected.label }}</ui-select-match> | ||
<ui-select-choices repeat="item.value as item in getChoices(entry) | filter: {label: $select.search}"> | ||
{{ item.label }} | ||
</ui-select-choices> | ||
</ui-select>`; | ||
|
||
var field = scope.field(); | ||
scope.name = field.name(); | ||
scope.v = field.validation(); | ||
|
||
var choices; | ||
if (field.type() === 'reference' || field.type() === 'reference_many') { | ||
choices = scope.datastore().getChoices(field); | ||
} else { | ||
choices = field.choices(); | ||
} | ||
scope.getChoices = typeof(choices) === 'function' ? choices : function() { return choices; }; | ||
element.html(template); | ||
|
||
var select = element.children()[0]; | ||
var attributes = field.attributes(); | ||
for (var name in attributes) { | ||
select.setAttribute(name, attributes[name]); | ||
} | ||
|
||
$compile(element.contents())(scope); | ||
}, | ||
|
||
}; | ||
} | ||
}; | ||
} | ||
|
||
maChoiceField.$inject = ['$compile']; | ||
|
||
module.exports = maChoiceField; | ||
|
28 changes: 10 additions & 18 deletions
28
src/javascripts/ng-admin/Crud/fieldView/ChoiceFieldView.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
define(function(require) { | ||
"use strict"; | ||
|
||
function getReadWidget() { | ||
module.exports = { | ||
getReadWidget: function() { | ||
return '<ma-string-column value="::field.getLabelForChoice(entry.values[field.name()], entry)"></ma-string-column>'; | ||
} | ||
function getLinkWidget() { | ||
return '<a ng-click="gotoDetail()">' + getReadWidget() + '</a>'; | ||
} | ||
function getFilterWidget() { | ||
}, | ||
getLinkWidget: function() { | ||
'<a ng-click="gotoDetail()">' + getReadWidget() + '</a>' | ||
}, | ||
getFilterWidget: function() { | ||
return '<ma-choice-field field="::field" value="values[field.name()]"></ma-choice-field>'; | ||
} | ||
function getWriteWidget() { | ||
}, | ||
getWriteWidget: function() { | ||
return '<ma-choice-field field="::field" entry="entry" value="entry.values[field.name()]"></ma-choice-field>'; | ||
} | ||
return { | ||
getReadWidget: getReadWidget, | ||
getLinkWidget: getLinkWidget, | ||
getFilterWidget: getFilterWidget, | ||
getWriteWidget: getWriteWidget, | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters