Last active
August 29, 2015 14:11
-
-
Save pierr/9b7014dc66048ab74617 to your computer and use it in GitHub Desktop.
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
var turnoverPeriodAutoComplete = function turnoverPeriodAutoComplete(query) { | |
if (query !== undefined) { | |
var countryId = null; | |
if (query.element !== undefined) { | |
countryId = query.element[0].getAttribute('data-cty'); | |
} | |
query.limit = 12; | |
Service.loadTurnoverPeriodListByCountryId(query.id, countryId, query.page, query.limit).then(function (results) { | |
Fmk.Helpers.select2Helper.autocompleteCallback(query, results); | |
}); | |
} | |
} |
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
//Dependencies. | |
var URL = require('../URL'); | |
var SingleModel = require('./contact'); | |
var PaginatedCollection = Fmk.Models.PaginatedCollection; | |
var Service = require('../../services/autocomplete/serviceAutocomplete'); | |
var AutocompleteFunction = require('../../lib/autocompleteFunction'); | |
//define a collection of contact | |
module.exports = PaginatedCollection.extend({ | |
model: SingleModel, | |
modelName: "centerStructure.contact", | |
url: URL.centerStructure.contactCollection, | |
sortField: { field: 'function' }, | |
metadatas: { | |
autoCompleteContact: { | |
domain: "DO_LISTE_MULTI", | |
decoratorOptions: Fmk.Helpers.select2Helper.autocompleteDecoratorOption(AutocompleteFunction.contactAutoComplete) | |
} | |
}, | |
exportColumnLabels: { | |
"function": "centerStructure.contact.function", | |
"name": "centerStructure.contact.name", | |
"firstName": "centerStructure.contact.firstName", | |
"phoneNumber": "centerStructure.contact.phoneNumber", | |
"emailAdress": "centerStructure.contact.emailAdress", | |
"comment": "centerStructure.contact.comment" | |
} | |
}); |
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
"use strict"; | |
(function(NS) { | |
NS = NS || {}; | |
var isInBrowser = typeof module === 'undefined' && typeof window !== 'undefined'; | |
function autocompleteCallback(query, results) { | |
var list = results.value; | |
var isMore = results.odata.count > (query.page * query.limit) | |
if (isMore) { | |
list.pop(); | |
} | |
var res = { results: list, more: isMore }; | |
if (query.element === undefined && res.results.length == 1) { | |
res = res.results[0]; | |
} | |
query.callback(res); | |
} | |
function autocompleteDecoratorOption(autocompleteFunction) { | |
return { | |
query: autocompleteFunction, | |
initSelection: function (element, callback) { | |
var id = $(element).val(); | |
if (id !== undefined) { | |
var query = { callback: callback } | |
if (id % 1 == 0) { | |
query.id = id; | |
} else { | |
query.term = id; | |
} | |
autocompleteFunction(query); | |
} | |
} | |
} | |
} | |
var select2Helper = { | |
autocompleteCallback: autocompleteCallback, | |
autocompleteDecoratorOption: autocompleteDecoratorOption | |
} | |
if (isInBrowser) { | |
NS.Helpers = NS.Helpers || {}; | |
NS.Helpers.select2Helper = select2Helper; | |
} else { | |
module.exports = select2Helper; | |
} | |
})(typeof module === 'undefined' && typeof window !== 'undefined' ? window.Fmk : module.exports); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
modele du critere