MCPcopy Create free account
hub / github.com/apache/cloudstack / Options

Function Options

tools/ngui/static/js/lib/angular.js:14554–14777  ·  view source on GitHub ↗
(scope, selectElement, ctrl)

Source from the content-addressed store, hash-verified

14552 }
14553
14554 function Options(scope, selectElement, ctrl) {
14555 var match;
14556
14557 if (! (match = optionsExp.match(NG_OPTIONS_REGEXP))) {
14558 throw Error(
14559 "Expected ngOptions in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
14560 " but got '" + optionsExp + "'.");
14561 }
14562
14563 var displayFn = $parse(match[2] || match[1]),
14564 valueName = match[4] || match[6],
14565 keyName = match[5],
14566 groupByFn = $parse(match[3] || ''),
14567 valueFn = $parse(match[2] ? match[1] : valueName),
14568 valuesFn = $parse(match[7]),
14569 // This is an array of array of existing option groups in DOM. We try to reuse these if possible
14570 // optionGroupsCache[0] is the options with no option group
14571 // optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
14572 optionGroupsCache = [[{element: selectElement, label:''}]];
14573
14574 if (nullOption) {
14575 // compile the element since there might be bindings in it
14576 $compile(nullOption)(scope);
14577
14578 // remove the class, which is added automatically because we recompile the element and it
14579 // becomes the compilation root
14580 nullOption.removeClass('ng-scope');
14581
14582 // we need to remove it before calling selectElement.html('') because otherwise IE will
14583 // remove the label from the element. wtf?
14584 nullOption.remove();
14585 }
14586
14587 // clear contents, we'll add what's needed based on the model
14588 selectElement.html('');
14589
14590 selectElement.bind('change', function() {
14591 scope.$apply(function() {
14592 var optionGroup,
14593 collection = valuesFn(scope) || [],
14594 locals = {},
14595 key, value, optionElement, index, groupIndex, length, groupLength;
14596
14597 if (multiple) {
14598 value = [];
14599 for (groupIndex = 0, groupLength = optionGroupsCache.length;
14600 groupIndex < groupLength;
14601 groupIndex++) {
14602 // list of options for that group. (first item has the parent)
14603 optionGroup = optionGroupsCache[groupIndex];
14604
14605 for(index = 1, length = optionGroup.length; index < length; index++) {
14606 if ((optionElement = optionGroup[index].element)[0].selected) {
14607 key = optionElement.val();
14608 if (keyName) locals[keyName] = key;
14609 locals[valueName] = collection[key];
14610 value.push(valueFn(scope, locals));
14611 }

Callers 1

angular.jsFile · 0.85

Calls 4

valueFnFunction · 0.85
removeMethod · 0.65
ErrorFunction · 0.50
matchMethod · 0.45

Tested by

no test coverage detected