2016-03-17 02:50:54 +01:00
|
|
|
(function (global, factory) {
|
2016-05-01 22:51:31 +02:00
|
|
|
if (typeof define === "function" && define.amd) {
|
2016-08-25 00:15:28 +02:00
|
|
|
define('ss.AddToCampaignForm', ['jQuery', 'i18n', 'react', 'react-dom', 'react-redux', 'components/FormBuilderModal/FormBuilderModal'], factory);
|
2016-05-01 22:51:31 +02:00
|
|
|
} else if (typeof exports !== "undefined") {
|
2016-08-25 00:15:28 +02:00
|
|
|
factory(require('jQuery'), require('i18n'), require('react'), require('react-dom'), require('react-redux'), require('components/FormBuilderModal/FormBuilderModal'));
|
2016-05-01 22:51:31 +02:00
|
|
|
} else {
|
|
|
|
var mod = {
|
|
|
|
exports: {}
|
|
|
|
};
|
2016-08-25 00:15:28 +02:00
|
|
|
factory(global.jQuery, global.i18n, global.react, global.reactDom, global.reactRedux, global.FormBuilderModal);
|
2016-05-01 22:51:31 +02:00
|
|
|
global.ssAddToCampaignForm = mod.exports;
|
|
|
|
}
|
2016-08-25 00:15:28 +02:00
|
|
|
})(this, function (_jQuery, _i18n, _react, _reactDom, _reactRedux, _FormBuilderModal) {
|
2016-05-01 22:51:31 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _jQuery2 = _interopRequireDefault(_jQuery);
|
|
|
|
|
2016-08-25 00:15:28 +02:00
|
|
|
var _i18n2 = _interopRequireDefault(_i18n);
|
|
|
|
|
|
|
|
var _react2 = _interopRequireDefault(_react);
|
|
|
|
|
|
|
|
var _reactDom2 = _interopRequireDefault(_reactDom);
|
|
|
|
|
|
|
|
var _FormBuilderModal2 = _interopRequireDefault(_FormBuilderModal);
|
|
|
|
|
2016-05-01 22:51:31 +02:00
|
|
|
function _interopRequireDefault(obj) {
|
|
|
|
return obj && obj.__esModule ? obj : {
|
|
|
|
default: obj
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_jQuery2.default.entwine('ss', function ($) {
|
2016-08-25 00:15:28 +02:00
|
|
|
$('.cms-content-actions .add-to-campaign-action,' + '#add-to-campaign__action').entwine({
|
2016-05-01 22:51:31 +02:00
|
|
|
onclick: function onclick() {
|
2016-08-25 00:15:28 +02:00
|
|
|
var dialog = $('#add-to-campaign__dialog-wrapper');
|
2016-05-01 22:51:31 +02:00
|
|
|
|
2016-08-25 00:15:28 +02:00
|
|
|
if (!dialog.length) {
|
|
|
|
dialog = $('<div id="add-to-campaign__dialog-wrapper" />');
|
2016-05-01 22:51:31 +02:00
|
|
|
$('body').append(dialog);
|
|
|
|
}
|
|
|
|
|
2016-08-25 00:15:28 +02:00
|
|
|
dialog.open();
|
2016-03-17 02:50:54 +01:00
|
|
|
|
2016-05-01 22:51:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-03-17 02:50:54 +01:00
|
|
|
|
2016-08-25 00:15:28 +02:00
|
|
|
$('#add-to-campaign__dialog-wrapper').entwine({
|
2016-05-01 22:51:31 +02:00
|
|
|
open: function open() {
|
2016-08-25 00:15:28 +02:00
|
|
|
this._renderModal();
|
2016-05-01 22:51:31 +02:00
|
|
|
},
|
|
|
|
close: function close() {
|
2016-08-25 00:15:28 +02:00
|
|
|
this._clearModal();
|
2016-05-01 22:51:31 +02:00
|
|
|
},
|
2016-08-25 00:15:28 +02:00
|
|
|
_renderModal: function _renderModal() {
|
|
|
|
var _this = this;
|
2016-05-01 22:51:31 +02:00
|
|
|
|
2016-08-25 00:15:28 +02:00
|
|
|
var handleHide = function handleHide() {
|
|
|
|
return _this._clearModal();
|
|
|
|
};
|
|
|
|
var handleSubmit = function handleSubmit() {
|
|
|
|
return _this._handleSubmitModal.apply(_this, arguments);
|
|
|
|
};
|
|
|
|
var id = $('form.cms-edit-form :input[name=ID]').val();
|
|
|
|
var store = window.ss.store;
|
|
|
|
var sectionConfig = store.getState().config.sections['SilverStripe\\CMS\\Controllers\\CMSPageEditController'];
|
|
|
|
var modalSchemaUrl = sectionConfig.form.AddToCampaignForm.schemaUrl + '/' + id;
|
2016-05-01 22:51:31 +02:00
|
|
|
|
2016-08-25 00:15:28 +02:00
|
|
|
_reactDom2.default.render(_react2.default.createElement(
|
|
|
|
_reactRedux.Provider,
|
|
|
|
{ store: store },
|
|
|
|
_react2.default.createElement(_FormBuilderModal2.default, {
|
|
|
|
show: true,
|
|
|
|
handleSubmit: handleSubmit,
|
|
|
|
handleHide: handleHide,
|
|
|
|
schemaUrl: modalSchemaUrl,
|
|
|
|
bodyClassName: 'add-to-campaign__dialog',
|
|
|
|
responseClassBad: 'add-to-campaign__response add-to-campaign__response--error',
|
|
|
|
responseClassGood: 'add-to-campaign__response add-to-campaign__response--good'
|
|
|
|
})
|
|
|
|
), this[0]);
|
|
|
|
},
|
|
|
|
_clearModal: function _clearModal() {
|
|
|
|
_reactDom2.default.unmountComponentAtNode(this[0]);
|
2016-05-01 22:51:31 +02:00
|
|
|
},
|
2016-08-25 00:15:28 +02:00
|
|
|
_handleSubmitModal: function _handleSubmitModal(event, fieldValues, submitFn) {
|
|
|
|
event.preventDefault();
|
2016-03-17 02:50:54 +01:00
|
|
|
|
2016-08-25 00:15:28 +02:00
|
|
|
if (!fieldValues.Campaign) {
|
|
|
|
alert(_i18n2.default._t('AddToCampaigns.ErrorCampaignNotSelected', 'There was no campaign selected to be added to'));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return submitFn();
|
2016-05-01 22:51:31 +02:00
|
|
|
}
|
2016-03-17 02:50:54 +01:00
|
|
|
});
|
2016-05-01 22:51:31 +02:00
|
|
|
});
|
2016-03-17 02:50:54 +01:00
|
|
|
});
|