How to use the ember-metal/mixin.create function in ember-metal

To help you get started, we’ve selected a few ember-metal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TryGhost / Ghost-Admin / app / mixins / ed-editor-shortcuts.js View on Github external
replacement.text = selection.text.toLocaleUpperCase();
        return replacement;
    },

    lowercase(replacement, selection) {
        replacement.text = selection.text.toLocaleLowerCase();
        return replacement;
    },

    titlecase(replacement, selection) {
        replacement.text = titleize(selection.text);
        return replacement;
    }
};

export default Mixin.create({
    shortcut(type) {
        let selection = this.getSelection();
        let replacement = {
            start: selection.start,
            end: selection.end,
            position: 'collapseToEnd'
        };

        switch (type) {
            // This shortcut is special as it needs to send an action
            case 'copyHTML':
                shortcuts.copyHTML(this, selection);
                break;
            case 'cycleHeaderLevel':
                replacement = shortcuts.cycleHeaderLevel(replacement, this.getLine());
                break;
github hummingbird-me / hummingbird-client / app / mixins / routes / pagination.js View on Github external
import Mixin from 'ember-metal/mixin';
import get from 'ember-metal/get';
import set from 'ember-metal/set';
import { typeOf } from 'ember-utils';

export default Mixin.create({
  actions: {
    updateNextPage(property, records, links) {
      if (typeOf(property) !== 'string') {
        property = 'model'; // eslint-disable-line no-param-reassign
        records = property; // eslint-disable-line no-param-reassign
        links = records;  // eslint-disable-line no-param-reassign
      }
      const controller = this.controllerFor(get(this, 'routeName'));
      if (controller === undefined) {
        return;
      }
      const content = get(controller, property).toArray();
      content.addObjects(records);
      set(controller, property, content);
      set(controller, `${property}.links`, links);
      set(controller, `${property}.meta`, get(records, 'meta'));
github hummingbird-me / hummingbird-client / app / mixins / pagination.js View on Github external
import Mixin from 'ember-metal/mixin';
import get from 'ember-metal/get';
import computed from 'ember-computed';
import service from 'ember-service/inject';
import { task } from 'ember-concurrency';
import { invokeAction } from 'ember-invoke-action';

/**
 * Pagination based on JSON-API's top level links object.
 */
export default Mixin.create({
  store: service(),

  /**
   * Grabs the latest `next` URL from the `links` object
   */
  nextLink: computed('model.links', function() {
    const model = get(this, 'model') || {};
    const links = get(model, 'links') || {};
    return get(links, 'next') || undefined;
  }),

  /**
   * Droppable task that queries the next set of data and sends an action
   * up to the owner.
   */
  getNextData: task(function* () {
github hummingbird-me / hummingbird-client / app / mixins / is-owner.js View on Github external
import Mixin from 'ember-metal/mixin';
import computed from 'ember-computed';
import get from 'ember-metal/get';

/**
 * Returns true if the session is the same user as the `user` property
 * or if that user has specific privileges such as admin. (NYI)
 *
 * Requires the object to import both the `session` service and an
 * instance of `user`.
 */
export default Mixin.create({
  isOwner: computed('user', 'session.account', {
    get() {
      const user = get(this, 'user');
      return get(this, 'session').isCurrentUser(user);
    }
  })
});
github IvyApp / ivy-tree / addon / mixins / tree-node.js View on Github external
import Mixin from 'ember-metal/mixin';
import computed from 'ember-computed';

export default Mixin.create({
  treeNodeAfter(newChild) {
    const treeNodeNextSibling = this.get('treeNodeNextSibling');

    if (treeNodeNextSibling) {
      treeNodeNextSibling.set('treeNodePreviousSibling', newChild);
    }

    const treeNodeParent = this.get('treeNodeParent');

    if (treeNodeParent && treeNodeParent.get('treeNodeLastChild') === this) {
      treeNodeParent.set('treeNodeLastChild', newChild);
    }

    newChild.set('treeNodeParent', treeNodeParent);
    newChild.set('treeNodePreviousSibling', this);
    newChild.set('treeNodeNextSibling', treeNodeNextSibling);
github elwayman02 / ember-unauthorized / addon / mixins / access.js View on Github external
import Mixin from 'ember-metal/mixin';
import { isPresent } from 'ember-utils';

/**
 * Mixin to detect and handle attempts to access unauthorized content
 * @module access
 */
export default Mixin.create({
  /**
   * Name of the key used to access feature flags
   * @type {string}
   * @default
   */
  featuresKey: 'features',

  /**
   * List of features required to be active for this route to be accessed
   * @type {Array}
   * @default
   */
  requiredFeatures: [],

  /**
   * Optional method to perform additional authorization, such as user access control
github hummingbird-me / hummingbird-client / app / mixins / routes / library-entry.js View on Github external
import Mixin from 'ember-metal/mixin';
import get from 'ember-metal/get';
import service from 'ember-service/inject';
import { capitalize } from 'ember-string';

export default Mixin.create({
  session: service(),

  _getLibraryEntry(media) {
    if (get(this, 'session.isAuthenticated') === false) {
      return;
    }

    return get(this, 'store').query('library-entry', {
      filter: {
        user_id: get(this, 'session.account.id'),
        media_type: capitalize(media.constructor.modelName),
        media_id: get(media, 'id')
      }
    });
  }
});
github TryGhost / Ghost-Admin / app / mixins / ed-editor-scroll.js View on Github external
import Mixin from 'ember-metal/mixin';
import run from 'ember-runloop';
import {invokeAction} from 'ember-invoke-action';

export default Mixin.create({
    /**
     * Determine if the cursor is at the end of the textarea
     */
    isCursorAtEnd() {
        let selection = this.$().getSelection();
        let value = this.getValue();
        let linesAtEnd = 3;
        let match,
            stringAfterCursor;

        stringAfterCursor = value.substring(selection.end);
        match = stringAfterCursor.match(/\n/g);

        if (!match || match.length < linesAtEnd) {
            return true;
        }
github TryGhost / Ghost-Admin / app / mixins / 404-handler.js View on Github external
import Mixin from 'ember-metal/mixin';

export default Mixin.create({
    actions: {
        error(error, transition) {
            if (error.errors && error.errors[0].errorType === 'NotFoundError') {
                transition.abort();

                let routeInfo = transition.handlerInfos[transition.handlerInfos.length - 1];
                let router = this.get('router');
                let params = [];

                for (let key of Object.keys(routeInfo.params)) {
                    params.push(routeInfo.params[key]);
                }

                return this.transitionTo('error404', router.generate(routeInfo.name, ...params).replace('/ghost/', '').replace(/^\//g, ''));
            }
github hummingbird-me / hummingbird-client / app / mixins / routes / data-error.js View on Github external
import Mixin from 'ember-metal/mixin';
import get from 'ember-metal/get';

export default Mixin.create({
  actions: {
    error(reason) {
      const status = get(reason, 'errors.firstObject.status');
      if (status === '500') {
        this.transitionTo('server-error');
      } else {
        this.transitionTo('/404');
      }
    }
  }
});