setUnknownProperty: function(key, value){ var prop; var ckey; if(key.indexOf("textField") === 0) { if(Ember.isNone(this.get('textFieldOptions'))) { this.set('textFieldOptions',{}); } if(Ember.IS_BINDING.test(key)) { prop = key.substring(0,key.length-7); } else { prop = key.substring(0,key.length); } ckey = prop.substring(9); ckey = ckey.charAt(0).toLowerCase() + ckey.substr(1); if(Ember.isNone(this.get('textFieldOptions.'+prop))) { this.set('textFieldOptions.'+prop,ckey); Ember.defineProperty(this, prop, null, value); } } else { if(Ember.platform.hasPropertyAccessors) { Ember.defineProperty(this, key, null, value); } else { this[key] = value; } } }
init: function() { this._super(...arguments); Ember.assert(!Ember.isNone(this.get('propertyName')), 'propertyName is required.'); Ember.defineProperty(this, 'serversideErrors', Ember.computed.filter('model.errors', function(error, index, array) { var nameSplit = error.message.source.pointer.split('/'); var name = nameSplit[nameSplit.length - 1]; return name == this.get('propertyName'); })); Ember.defineProperty(this, 'errors', Ember.computed.union('serversideErrors', `model.validations.attrs.${this.get('propertyName')}.messages`)); },
applyBindings: (function() { var lookup, properties, styleBindingsstyleBindings, styleComputed, styles; if (!(styleBindingsstyleBindings = this.styleBindings)) { return; } lookup = {}; this.styleBindings.forEach(function(binding) { var propArr, property, style; propArr = binding.split(":"); property = propArr[0]; style = propArr[1]; return lookup[style || property] = property; }); styles = Ember.keys(lookup); properties = styles.map(function(style) { return lookup[style]; }); styleComputed = Ember.computed(function() { var styleString, styleTokens; styleTokens = styles.map((function(_this) { return function(style) { return _this.buildStyleString(style, lookup[style]); }; })(this)); styleString = styleTokens.join(""); if (styleString.length !== 0) { return styleString; } }); styleComputed.property.apply(styleComputed, properties); return Ember.defineProperty(this, "style", styleComputed); }).on('init')
applyStyleBindings: function() { var lookup, properties, styleBindings, styleComputed, styles; styleBindings = this.styleBindings; if (!styleBindings) { return; } // get properties from bindings e.g. ['width', 'top'] lookup = {}; styleBindings.forEach(function(binding) { var property, ref, style; ref = binding.split(':'), property = ref[0], style = ref[1]; return lookup[style || property] = property; }); styles = _.keys(lookup); properties = _.values(lookup); // create computed property styleComputed = Ember.computed((function(_this) { return function() { var styleString, styleTokens; styleTokens = styles.map(function(style) { return _this.createStyleString(style, lookup[style]); }); styleString = styleTokens.join(''); if (styleString.length !== 0) { return styleString; } }; })(this)); // add dependents to computed property styleComputed.property.apply(styleComputed, properties); // define style computed properties return Ember.defineProperty(this, 'style', styleComputed); },
objectOrAttrChanged: Ember.observer("object", "attr", function() { var errorsAttribute = "object.errors." + this.get("attr"); Ember.defineProperty(this, "errors", Ember.computed.reads(errorsAttribute)); var valueAttribute = "object." + this.get("attr"); Ember.defineProperty(this, "value", Ember.computed(valueAttribute, { get: function() { return this.get(valueAttribute); }, set: function(key, value) { this.set(valueAttribute, value); return value; } })); }),
Ember.observer('styleBindings', function() { var lookup, properties, styleBindings, styleComputed, styles, _this = this; styleBindings = this.get('styleBindings'); if (!styleBindings) { return; } lookup = {}; styleBindings.forEach(function(binding) { var property, style, tmp; tmp = binding.split(':'); property = tmp[0]; style = tmp[1]; lookup[style || property] = property; }); styles = Ember.keys(lookup); properties = styles.map(function(style) { return lookup[style]; }); styleComputed = Ember.computed(function() { var styleString, styleTokens; styleTokens = styles.map(function(style) { return _this.createStyleString(style, lookup[style]); }); styleString = styleTokens.join(''); if (styleString.length !== 0) { return styleString.htmlSafe().toString(); } }); styleComputed.property.apply(styleComputed, properties); return Ember.defineProperty(this, 'style', styleComputed); }))
labelPathDidChange: Ember.observer(function() { var labelPath, path; labelPath = this.get('labelPath'); path = labelPath ? "context." + labelPath : 'context'; Ember.defineProperty(this, 'label', Ember.computed.alias(path)); return this.notifyPropertyChange('label'); }, 'context', 'labelPath')
init: function() { this._super(...arguments); var valuePath = this.get('valuePath'); if (this.get('model')) { Ember.defineProperty(this, 'value', Ember.computed.alias(`model.${valuePath}`)); } },
bps.forEach((bp, i) => { Ember.defineProperty(this, `is${capitalize(bp.name)}`, computed('width', function() { let width = this.get('width'); let next = bps[i + 1]; if (next) { return width >= bp.begin && width < next.begin; } return width >= bp.begin; })); Ember.defineProperty(this, `isAtLeast${capitalize(bp.name)}`, computed('width', function() { let width = this.get('width'); return width >= bp.begin; })); });
init: function () { // Call the parent class method this._super.apply(this, arguments); // Dynamically create a computed property that resolves the record field Ember.defineProperty(this, 'recordValue', Ember.computed.oneWay('record.' + this.get('displayProperty'))); // Initialize the cell raw value this.setCellValue(); },
export function initialize(/* application */) { Ember.Component.reopen({ // Allows to dynamically define a computed property defineComputedProperty(name, watchProps, func) { Ember.defineProperty( this, name, Ember.computed(watchProps, function() { return func(this.get(watchProps)); }) ); } }); }
test("Forwards the t and exists methods", function(assert) { assert.expect(2, "Both functions are forwarded"); let service = this.subject(); let key = "testTranslationKey"; Ember.defineProperty(service, "translationService", Ember.computed(function() { return { t(k) { assert.equal(k, key, `The t method is called with the given key`); }, exists(k) { assert.equal(k, key, `The exists method is called with the given key`); } }; })); service.exists(key); service.t(key); });
labelPathDidChange: Ember.observer('parentView.optionLabelPath', function() { Ember.defineProperty(this, 'label', Ember.computed(function() { var email = Ember.get(this, 'content.email'); var pub = Ember.get(this,'content.publicValue'); if ( email && pub ) { return email + ' - ' + pub; } else if ( email ) { return email; } else if ( pub ) { return pub; } else { return '(' + Ember.get(this,'content.id') + ')'; } }).property('content.{email,publicValue}')); }),
*/ import Ember from 'ember'; export default Ember.Mixin.create({ remoteSession: Ember.inject.service('remote-session'), localClipboardContent: null, updateCloudClipboardOnTyping: function() { this.get('remoteSession').setCloudClipboard(this.get('connectionName'), this.get('cloudClipboardContent')); }.observes('cloudClipboardContent'), setupClipboardObservers() { var connectionName = this.get('connectionName'); Ember.defineProperty(this, 'localClipboardContent', Ember.computed.alias(`remoteSession.openedGuacSession.${connectionName}.localClipboard`)); Ember.defineProperty(this, 'cloudClipboardContent', Ember.computed.alias(`remoteSession.openedGuacSession.${connectionName}.cloudClipboard`)); }, actions: { savePasteToLocal() { this.get('remoteSession').setLocalClipboard(this.get('connectionName'), this.get('cloudClipboardContent')); this.toast.info('Clipboard copied!'); }, clearClipboard() { this.set('cloudClipboardContent', ''); } } });
for (path of Object.keys(onlyIf)) { args.push('form.'+root+'.'+path); } //define the computed function args.push(function () { let root, onlyIf, path, form, object, allPas; form = this.get('form'); object = this.get('object'); root = form.rootPath; onlyIf = Ember.get(object, 'only_if'); if (!onlyIf) { return true; } allPas = true; for (path of Object.keys(onlyIf)) { let rule, operator, value, op; rule = onlyIf[path]; [operator, value] = rule.split(':'); path = root+'.'+path; op = this.get('_operators.' + operator); allPas = allPas && op(Ember.get(form, path), value); } return allPas; }); Ember.defineProperty(this, 'ifIsTrue', Ember.computed.apply(null, args)); } });
optionLabelPathChanges: Ember.on('init', Ember.observer(function() { var labelPath, path; labelPath = this.get('optionLabelPath'); path = labelPath ? "selection." + labelPath : 'selection'; return Ember.defineProperty(this, 'selectedLabel', Ember.computed.alias(path)); }, 'selection', 'optionLabelPath')),
Ember.keys(options).forEach(function(key) { Ember.defineProperty(self, options[key], Ember.computed("parentView."+key, function(){ return self.get("parentView."+key); })); });
this.get("additionalAttributeNames").forEach((attributeName) => { Ember.defineProperty(proxy, attributeName, Ember.computed.alias(`content.${attributeName}`)); });
renderTooltip: on('didInsertElement', function(maybeTooltipComponent) { const componentWasPassed = Ember.typeOf(maybeTooltipComponent) === 'instance'; const component = componentWasPassed ? maybeTooltipComponent : Ember.Object.create({}); const renderContext = componentWasPassed ? component : this; let content = this.get('tooltipContent'); let tooltip, tooltipOptions; const keys = Object.keys(this); const hasTooltipContentProperty = (Ember.$.inArray('tooltipContent', keys) !== -1); if (componentWasPassed) { const componentContent = component.get('content'); if (componentContent) { content = componentContent; } else { content = component.get('element').innerHTML; } } if (!content && !hasTooltipContentProperty) { return; } tooltipOptions = { content }; this.get('tooltipSupportedProperties').forEach(function(property) { /* Ignore content because we dealt with it already */ if (property === 'content') { return; } const capitalizedProperty = Ember.String.capitalize(property); tooltipOptions[property] = component.get(property) || this.get(`tooltip${capitalizedProperty}`); }, this); tooltip = renderTooltip(this.get('element'), tooltipOptions, renderContext); this.set('tooltip', tooltip); /* Bind observer if tooltipContent changes */ this.addObserver('tooltipContent', this, this._tooltipContentDidChange); /* Bind observer if in manual-triggering mode */ if (tooltipOptions.event === 'manual' || tooltipOptions.event === 'none') { if (componentWasPassed) { /* Keep track of child tooltip component */ this.set('tooltipChildComponent', component); /* Turn 'tooltipVisibility' into a computed property, reading from child tooltip component's 'visibility' option */ Ember.defineProperty(this, 'tooltipVisibility', Ember.computed.reads('tooltipChildComponent.visibility')); } this.addObserver('tooltipVisibility', this, this._tooltipVisibilityDidChange); this._tooltipVisibilityDidChange(); } }),
this.createAndAddChildLayers(); }, willDestroyLayer() { this.removeAndDestroyChildLayers(); this._super(); }, createAndAddChildLayers() { const _childLayers = this._childLayers = Ember.A(), self = this; let layer; if(this._childLayerClasses === undefined) { this._childLayerClasses = get(this, 'childLayers') || []; } Ember.defineProperty(this, 'childLayers', Ember.computed(function() { return this._childLayers; })); this._childLayerClasses.forEach(function(layerClass, idx) { layer = self.createChildLayer(layerClass); self.addChildLayer(layer); _childLayers[idx] = layer; }, this); }, replace(idx, removedCount, addedLayers) { const addedCount = addedLayers ? get(addedLayers, 'length') : 0, self = this; this.arrayContentWillChange(idx, removedCount, addedCount); this.childLayersWillChange(this._childLayers, idx, removedCount);
return on('init', function() { Ember.defineProperty(this, key, computedPropertyFactory()); });
init: function() { this._super(...arguments); Ember.assert(!Ember.isNone(this.get('propertyName')), 'propertyName is required.'); Ember.defineProperty(this, 'errors', Ember.computed.alias((`model.errors.${this.get('propertyName')}`))); },
classNameBindings: ['extraClass', 'horiClassCalc'], text: null, extraClass: null, horiClass: 'col-sm-offset-2 col-sm-10', horiClassCalc: Ember.computed('form.isHorizontal', { get: function() { if (this.get('form.isHorizontal') && this.get('horiClass')) { return this.get('horiClass'); } } }), init() { this._super(...arguments); Ember.defineProperty(this, 'serversideErrors', Ember.computed.filter('mainComponent.model.errors', function(error, index, array) { var nameSplit = error.message.source.pointer.split('/'); var name = nameSplit[nameSplit.length - 1]; return name == this.get('mainComponent.propertyName'); })); Ember.defineProperty(this, 'errors', Ember.computed.union('serversideErrors', `mainComponent.model.validations.attrs.${this.get('mainComponent.propertyName')}.messages`)); }, helpText: Ember.computed('text', 'errors.firstObject', { get: function() { return this.get('errors.firstObject.message.detail') || this.get('errors.firstObject.message') || this.get('errors.firstObject') || this.get('text'); } }), hasHelp: Ember.computed('helpText', { get: function() { var helpText = this.get('helpText'); if (!helpText) {
WIDGET_ATTR_ALIASES.forEach(field => { Ember.defineProperty(this, field, alias('field.' + field)); });