Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/app/dashboard/model/edit/ModelEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ angular.module('dashboard.Dashboard.Model.Edit', [
displayInfo = key;
} else {
var property = $scope.model.properties[key];
displayInfo = property.display;
if (property) displayInfo = property.display;
}

if (!displayInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ angular.module('dashboard.directives.ModelFieldReference', [
if (!scope.data) scope.selected = {};
});

scope.$watch('selected.items', function() { // watch selected.items to ensure previously selected items are accounted for.
if (scope.selected.items) {
scope.refreshChoices();
}
});

function removeSelectedFromList(selected, list, id) {
var filteredList = _.reject(list, function(o) {
return _.find(selected, function(s) {
return o[id] === s[id];
})
});
return filteredList;
}

function replaceSessionVariables(string) {
if (typeof string !== 'string') return string;
try {
Expand Down Expand Up @@ -120,7 +135,7 @@ angular.module('dashboard.directives.ModelFieldReference', [
scope.refreshChoices = function(search) {
var model = Config.serverParams.models[scope.options.model];
var params = { 'filter[limit]': 100 }; //limit only 100 items in drop down list
params['filter[where]['+scope.options.searchField+'][like]'] = "%" + search + "%";
if (search) params['filter[where]['+scope.options.searchField+'][like]'] = "%" + search + "%";
if (scope.options.where) {
//Add additional filtering on reference results
var keys = Object.keys(scope.options.where);
Expand All @@ -140,7 +155,7 @@ angular.module('dashboard.directives.ModelFieldReference', [
if (scope.options.api) apiPath = replaceSessionVariables(scope.options.api);
GeneralModelService.list(apiPath, params, {preventCancel: true}).then(function(response) {
if (!response) return; //in case http request was cancelled by newer request
scope.list = response;
scope.list = removeSelectedFromList(scope.selected.items, response, scope.options.key);
if (scope.options.allowInsert) {
var addNewItem = {};
addNewItem[scope.options.searchField] = "[Add New Item]";
Expand Down Expand Up @@ -337,6 +352,7 @@ angular.module('dashboard.directives.ModelFieldReference', [
//For single record reference just assign null
scope.data = null;
}
scope.refreshChoices();
};

scope.$on('ngGridEventStartCellEdit', function () {
Expand Down