kai-jacobsen/kontentblocks

View on GitHub
js/src/fields/controls/subarea/ModuleBrowser.js

Summary

Maintainability
A
0 mins
Test Coverage
var ModuleBrowser = require('shared/ModuleBrowser/ModuleBrowserController');
var Checks = require('common/Checks');
var Config = require('common/Config');
var Notice = require('common/Notice');
var Ajax = require('common/Ajax');
module.exports = ModuleBrowser.extend({
  initialize: function(options){
      ModuleBrowser.prototype.initialize.apply(this,arguments);
      this.subarea = options.subarea;
      this.isSubarea = true;
  },
  createModule: function (module) {
    var Area, data;
    // check if capability is right for this action
    if (Checks.userCan('create_kontentblocks')) {
    } else {
      Notice.notice('You\'re not allowed to do this', 'error');
    }

    // prepare data to send
    data = {
      action: 'createNewModule',
      'class': module.get('settings').class,
      globalModule: module.get('globalModule'),
      parentObject: module.get('parentObject'),
      parentObjectId: module.get('parentObjectId'),
      areaContext: this.subarea.model.get('context'),
      area: this.subarea.model.get('id'),
      _ajax_nonce: Config.getNonce('create'),
      frontend: KB.appData.config.frontend,
      submodule: true
    };

    if (this.area.model.get('parent_id')) {
      data.postId = this.area.model.get('parent_id');
    }
    Ajax.send(data, this.success, this);
  },
  success: function (res) {
    this.trigger('browser.module.created', {res: res});
    this.close();

  }

});