diff --git a/ghost/admin/components/gh-role-selector.js b/ghost/admin/components/gh-role-selector.js new file mode 100644 index 0000000000..e08f94213f --- /dev/null +++ b/ghost/admin/components/gh-role-selector.js @@ -0,0 +1,13 @@ +import GhostSelect from 'ghost/components/gh-select'; + +var RolesSelector = GhostSelect.extend({ + roles: Ember.computed.alias('options'), + options: Ember.computed(function () { + var rolesPromise = this.store.find('role', { permissions: 'assign' }); + + return Ember.ArrayProxy.extend(Ember.PromiseProxyMixin) + .create({promise: rolesPromise}); + }) +}); + +export default RolesSelector; diff --git a/ghost/admin/components/gh-select.js b/ghost/admin/components/gh-select.js new file mode 100644 index 0000000000..c085adea89 --- /dev/null +++ b/ghost/admin/components/gh-select.js @@ -0,0 +1,69 @@ +//GhostSelect is a solution to Ember.Select being evil and worthless. +// (Namely, this solves problems with async data in Ember.Select) +//Inspired by (that is, totally ripped off from) this JSBin +//http://emberjs.jsbin.com/rwjblue/40/edit + +//Usage: +//Extend this component and create a template for your component. +//Your component must define the `options` property. +//Optionally use `initialValue` to set the object +// you want to have selected to start with. +//Both options and initalValue are promise safe. +//Set onChange in your template to be the name +// of the action you want called in your +//For an example, see gh-roles-selector + +var GhostSelect = Ember.Component.extend({ + tagName: 'span', + classNames: ['gh-select'], + + options: null, + initialValue: null, + + resolvedOptions: null, + resolvedInitialValue: null, + + //Convert promises to their values + init: function () { + var self = this; + this._super.apply(this, arguments); + + Ember.RSVP.hash({ + resolvedOptions: this.get('options'), + resolvedInitialValue: this.get('initialValue') + }).then(function (resolvedHash) { + self.setProperties(resolvedHash); + + //Run after render to ensure the