Initial commit
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
var CoreView = require('backbone/core-view');
|
||||
var template = require('./editor-visualization-warning.tpl');
|
||||
var VisDefinitionModel = require('builder/data/vis-definition-model');
|
||||
var renderLoading = require('builder/components/loading/render-loading');
|
||||
var ErrorView = require('builder/components/error/error-view');
|
||||
var errorParser = require('builder/helpers/error-parser');
|
||||
var VIS_VERSION = 3;
|
||||
|
||||
/**
|
||||
* Confirmation modal dialog
|
||||
*/
|
||||
|
||||
module.exports = CoreView.extend({
|
||||
className: 'Dialog-content',
|
||||
|
||||
events: {
|
||||
'click .js-open': '_onOpen',
|
||||
'click .js-duplicate': '_onDuplicate',
|
||||
'click .js-cancel': '_onCancel'
|
||||
},
|
||||
|
||||
initialize: function (opts) {
|
||||
if (!opts.visDefinitionModel) throw new Error('visDefinitionModel is required');
|
||||
if (!opts.modalModel) throw new Error('modalModel is required');
|
||||
|
||||
this._visDefinitionModel = opts.visDefinitionModel;
|
||||
this._modalModel = opts.modalModel;
|
||||
|
||||
this._initBinds();
|
||||
},
|
||||
|
||||
render: function () {
|
||||
this.clearSubViews();
|
||||
|
||||
this.$el.html(template());
|
||||
return this;
|
||||
},
|
||||
|
||||
_initBinds: function () {
|
||||
this._modalModel.bind('change:show', this._goToDashboard, this);
|
||||
this.add_related_model(this._modalModel);
|
||||
},
|
||||
|
||||
_disableBinds: function () {
|
||||
this._modalModel.unbind('change:show', this._goToDashboard, this);
|
||||
},
|
||||
|
||||
_onOpen: function () {
|
||||
this._disableBinds();
|
||||
this._renderLoading('open');
|
||||
|
||||
this._visDefinitionModel.save({
|
||||
version: VIS_VERSION
|
||||
}, {
|
||||
wait: true,
|
||||
success: function () {
|
||||
this._modalModel.destroy();
|
||||
}.bind(this),
|
||||
error: function (mdl, e) {
|
||||
this._renderError(errorParser(e));
|
||||
}.bind(this)
|
||||
});
|
||||
},
|
||||
|
||||
_onDuplicate: function () {
|
||||
this._renderLoading('duplicate');
|
||||
|
||||
var newVisModel = new VisDefinitionModel({
|
||||
name: this._visDefinitionModel.get('name')
|
||||
}, {
|
||||
configModel: this._visDefinitionModel._configModel
|
||||
});
|
||||
|
||||
newVisModel.save({
|
||||
source_visualization_id: this._visDefinitionModel.get('id')
|
||||
}, {
|
||||
success: function (visModel) {
|
||||
this._redirectToBuilder(visModel.builderURL());
|
||||
}.bind(this),
|
||||
error: function (mdl, e) {
|
||||
this._renderError(errorParser(e));
|
||||
}.bind(this)
|
||||
});
|
||||
},
|
||||
|
||||
_redirectToBuilder: function (redirect) {
|
||||
window.location = redirect;
|
||||
},
|
||||
|
||||
_renderLoading: function (renderOption) {
|
||||
var mapName = this._visDefinitionModel.get('name');
|
||||
var titleText = '';
|
||||
|
||||
if (renderOption === 'duplicate') {
|
||||
titleText = _t('editor.maps.duplicate.loading', { name: mapName });
|
||||
} else if (renderOption === 'open') {
|
||||
titleText = _t('components.modals.editor-vis-warning.opening-title', { name: mapName });
|
||||
}
|
||||
|
||||
this.$el.html(
|
||||
renderLoading({
|
||||
title: titleText
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
_renderError: function (errorMessage) {
|
||||
var mapName = this._visDefinitionModel.get('name');
|
||||
var errorView = new ErrorView({
|
||||
title: _t('editor.maps.duplicate.error', { name: mapName }),
|
||||
desc: errorMessage
|
||||
});
|
||||
this.$el.html(errorView.render().el);
|
||||
this.addView(errorView);
|
||||
},
|
||||
|
||||
_goToDashboard: function (redirect) {
|
||||
window.location = redirect;
|
||||
},
|
||||
|
||||
_onCancel: function () {
|
||||
this._goToDashboard(this._visDefinitionModel._configModel.get('base_url'));
|
||||
},
|
||||
|
||||
clean: function () {
|
||||
this._disableBinds();
|
||||
CoreView.prototype.clean.apply(this);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
<div class="u-flex u-justifyCenter">
|
||||
<div class="Modal-inner Modal-inner--medium u-flex u-justifyCenter">
|
||||
<div class="Modal-icon">
|
||||
<svg width="32px" height="32px" viewbox="459 348 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="Editor-vis-warning" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" transform="translate(459.000000, 348.000000)">
|
||||
<path d="M15.081,7.19c0.472,0.473,1.1,0.732,1.768,0.732c0.667,0,1.295-0.26,1.768-0.732s0.732-1.101,0.732-1.768
|
||||
c0-0.668-0.26-1.296-0.732-1.768c-0.945-0.946-2.592-0.944-3.536,0c-0.472,0.472-0.732,1.1-0.732,1.768S14.608,6.719,15.081,7.19z
|
||||
M15.788,4.362c0.283-0.283,0.66-0.439,1.061-0.439c0.4,0,0.777,0.156,1.061,0.439c0.284,0.283,0.439,0.659,0.439,1.061
|
||||
c0,0.4-0.156,0.777-0.439,1.061c-0.567,0.566-1.556,0.566-2.122,0c-0.283-0.283-0.439-0.659-0.439-1.061S15.504,4.646,15.788,4.362
|
||||
z" fill="#FFA500"/>
|
||||
<path d="M13.676,12.131c0.094-0.094,0.146-0.221,0.146-0.354s-0.053-0.26-0.146-0.354l-2.829-2.828
|
||||
c-0.195-0.195-0.512-0.195-0.707,0l-2.828,2.828c-0.195,0.195-0.195,0.512,0,0.707l2.828,2.828
|
||||
c0.098,0.098,0.226,0.146,0.354,0.146s0.256-0.049,0.354-0.146L13.676,12.131z M8.373,11.777l2.121-2.121l2.122,2.121l-2.122,2.121
|
||||
L8.373,11.777z" fill="#FFA500"/>
|
||||
<path d="M23.375,17.965c-0.182-0.205-0.499-0.227-0.706-0.044c-2.704,2.385-6.065,3.678-8.77,3.367
|
||||
c-1.699-0.194-3.106-0.991-4.199-2.354l0.989-0.989c0.087,0.331,0.252,0.646,0.511,0.904c0.39,0.39,0.902,0.584,1.414,0.584
|
||||
c0.512,0,1.024-0.194,1.415-0.584l2.122-2.122c0.081-0.08,0.139-0.175,0.213-0.26c0.05-0.023,0.099-0.052,0.14-0.093l4.596-4.597
|
||||
c0.755-0.755,1.171-1.76,1.171-2.828c0-0.983-0.367-1.904-1.012-2.635c0.059-0.29,0.089-0.588,0.089-0.892
|
||||
c0-1.202-0.468-2.332-1.318-3.183c-0.85-0.85-1.98-1.317-3.182-1.317c-0.304,0-0.602,0.03-0.893,0.089
|
||||
c-1.569-1.381-3.963-1.339-5.462,0.159L5.897,5.768C5.856,5.809,5.829,5.856,5.806,5.906C5.72,5.98,5.625,6.04,5.544,6.121
|
||||
L3.423,8.242c-0.78,0.779-0.78,2.049,0,2.828c0.255,0.255,0.576,0.416,0.915,0.499l-3.744,3.743
|
||||
c-0.377,0.378-0.585,0.88-0.585,1.414c0,0.535,0.208,1.037,0.585,1.414c0.756,0.756,2.073,0.756,2.829,0l3.182-3.182
|
||||
c0.196-0.195,0.513-0.194,0.708,0c0.195,0.195,0.195,0.513,0,0.708L4.13,18.849c-0.378,0.377-0.586,0.879-0.586,1.414
|
||||
S3.752,21.3,4.13,21.677c0.39,0.39,0.902,0.585,1.414,0.585s1.025-0.195,1.415-0.585l2.032-2.032
|
||||
c1.244,1.506,2.888,2.419,4.796,2.637c0.298,0.034,0.603,0.051,0.914,0.051c2.789,0,6.012-1.352,8.63-3.661
|
||||
C23.538,18.488,23.558,18.172,23.375,17.965z M21.272,8.949c0,0.802-0.312,1.555-0.878,2.121l-2.85,2.85
|
||||
c0.035-0.24,0.071-0.48,0.071-0.729c0-1.24-0.466-2.402-1.287-3.319c0.173,0.021,0.344,0.051,0.521,0.051
|
||||
c1.202,0,2.332-0.468,3.182-1.318c0.345-0.345,0.608-0.743,0.821-1.166C21.119,7.894,21.272,8.407,21.272,8.949z M19.323,2.947
|
||||
c0.661,0.661,1.025,1.54,1.025,2.476c0,0.935-0.364,1.813-1.025,2.475c-1.294,1.292-3.521,1.312-4.855,0.076l-0.176-0.176
|
||||
c-1.273-1.37-1.252-3.517,0.082-4.851c0.661-0.661,1.54-1.024,2.475-1.024C17.783,1.923,18.662,2.286,19.323,2.947z M11.201,1.878
|
||||
c0.984-0.982,2.482-1.128,3.631-0.458c-0.422,0.213-0.821,0.477-1.165,0.82c-1.01,1.011-1.419,2.385-1.266,3.704
|
||||
c-0.918-0.822-2.079-1.288-3.321-1.288c-0.248,0-0.488,0.036-0.728,0.071L11.201,1.878z M6.251,20.97
|
||||
c-0.391,0.391-1.025,0.39-1.415,0c-0.188-0.188-0.292-0.439-0.292-0.707s0.104-0.519,0.293-0.707l3.183-3.182
|
||||
c0.584-0.586,0.584-1.538,0-2.122c-0.585-0.586-1.537-0.586-2.122,0l-3.182,3.182c-0.378,0.378-1.037,0.376-1.415,0
|
||||
c-0.189-0.188-0.292-0.439-0.292-0.707c0-0.267,0.104-0.519,0.292-0.707l5.186-5.185l0.472-0.472l0,0L9.08,8.242
|
||||
c0.195-0.195,0.195-0.512,0-0.707s-0.512-0.195-0.707,0L5.78,10.128l-0.236,0.235c-0.378,0.379-1.036,0.377-1.414,0
|
||||
c-0.39-0.39-0.39-1.024,0-1.414l2.121-2.121c1.511-1.512,4.146-1.512,5.657,0l1.677,1.677c0.03,0.031,0.051,0.068,0.082,0.1
|
||||
c0.032,0.032,0.071,0.054,0.103,0.085l1.674,1.674c0.755,0.756,1.171,1.76,1.171,2.828s-0.416,2.073-1.171,2.828l-2.121,2.122
|
||||
c-0.39,0.389-1.024,0.389-1.415,0c-0.189-0.189-0.293-0.44-0.293-0.708c0-0.267,0.104-0.518,0.292-0.707l2.829-2.828
|
||||
c0.195-0.195,0.195-0.512,0-0.707s-0.512-0.195-0.707,0l-2.121,2.121l0,0l-0.707,0.707c0,0,0,0.001-0.001,0.001L6.251,20.97z" fill="#FFA500"/>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2 class="Dialog-headerTitle--warning CDB-Text CDB-Size-huge is-light u-bSpace--m"><%- _t('components.modals.editor-vis-warning.title') %></h2>
|
||||
<p class="CDB-Text CDB-Size-medium u-secondaryTextColor u-bSpace--xl"><%- _t('components.modals.editor-vis-warning.explanation') %></p>
|
||||
<p class="CDB-Text CDB-Size-medium is-semibold u-secondaryTextColor"><%- _t('components.modals.editor-vis-warning.question') %></p>
|
||||
|
||||
<ul class="Modal-listActions u-flex u-alignCenter">
|
||||
<li class="Modal-listActionsitem">
|
||||
<button class="CDB-Button CDB-Button--secondary CDB-Button--big js-cancel">
|
||||
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">
|
||||
<%- _t('components.modals.editor-vis-warning.go-back') %>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
<li class="Modal-listActionsitem">
|
||||
<button class="CDB-Button CDB-Button--primary CDB-Button--big js-open">
|
||||
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">
|
||||
<%- _t('components.modals.editor-vis-warning.open') %>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p class="CDB-Text CDB-Size-medium u-secondaryTextColor u-tSpace-xl">or <button class="CDB-Text is-semibold u-actionTextColor js-duplicate"><%- _t('components.modals.editor-vis-warning.duplicate') %></button>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user