diff --git a/creator/packages/steedos-autoform/client/coreform/inputTypes/coreform-user/lib/cf_data_manager.js b/creator/packages/steedos-autoform/client/coreform/inputTypes/coreform-user/lib/cf_data_manager.js index 86c6203931..6790a2ff42 100644 --- a/creator/packages/steedos-autoform/client/coreform/inputTypes/coreform-user/lib/cf_data_manager.js +++ b/creator/packages/steedos-autoform/client/coreform/inputTypes/coreform-user/lib/cf_data_manager.js @@ -430,9 +430,11 @@ CFDataManager.getRoot = function (spaceId, options) { } var showLimitedCompanyOnly = options && options.showLimitedCompanyOnly; + var needSort = false; if(showLimitedCompanyOnly){ user_company_ids = Steedos.getUserCompanyOrganizationIds(); if (user_company_ids && user_company_ids.length) { + needSort = true; query._id = { $in: user_company_ids }; @@ -445,7 +447,7 @@ CFDataManager.getRoot = function (spaceId, options) { } } - return SteedosDataManager.organizationRemote.find(query, { + var result = SteedosDataManager.organizationRemote.find(query, { fields: { _id: 1, name: 1, @@ -457,6 +459,13 @@ CFDataManager.getRoot = function (spaceId, options) { hidden: 1, } }); + + if(needSort){ + var curSpaceUser = db.space_users.findOne({space: Creator.USER_CONTEXT.user.spaceId,'user': Creator.USER_CONTEXT.user.userId}); + return Creator.getOrderlySetByIds(result, curSpaceUser.organizations); + } + + return result }; CFDataManager.getOrganizationsByIds = function(ids) { diff --git a/creator/packages/steedos-objects/coreSupport.coffee b/creator/packages/steedos-objects/coreSupport.coffee index 29dd9e6e75..edb40521cd 100644 --- a/creator/packages/steedos-objects/coreSupport.coffee +++ b/creator/packages/steedos-objects/coreSupport.coffee @@ -154,7 +154,11 @@ Creator.getOrderlySetByIds = (docs, ids, id_key, hit_first)-> return ids.length + _.indexOf(values, doc[id_key]) else return _.sortBy docs, (doc)-> - return ids.indexOf(doc[id_key]) + v = ids.indexOf(doc[id_key]); + if v < 0 + return 99999 + else + return v ### 按用户所属本地化语言进行排序,支持中文、数值、日期等字段排序