Skip to content

Commit

Permalink
Add AddToCampaign dialog box functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
scott1702 authored and Hamish Friedlander committed Apr 25, 2016
1 parent 525e3d0 commit a4437fa
Show file tree
Hide file tree
Showing 11 changed files with 568 additions and 36 deletions.
105 changes: 105 additions & 0 deletions admin/client/dist/js/AddToCampaignForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define('ss.AddToCampaignForm', ['jQuery', 'i18n'], factory);
} else if (typeof exports !== "undefined") {
factory(require('jQuery'), require('i18n'));
} else {
var mod = {
exports: {}
};
factory(global.jQuery, global.i18n);
global.ssAddToCampaignForm = mod.exports;
}
})(this, function (_jQuery, _i18n) {
'use strict';

var _jQuery2 = _interopRequireDefault(_jQuery);

var _i18n2 = _interopRequireDefault(_i18n);

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}

_jQuery2.default.entwine('ss', function ($) {
$('.add-to-campaign-action, #add-to-campaign__action').entwine({
onclick: function onclick() {
var dialog = $('#add-to-campaign__dialog');

if (dialog.length) {
dialog.open();
} else {
dialog = $('<div id="add-to-campaign__dialog" />');
$('body').append(dialog);
}

if (dialog.children().length == 0) dialog.addClass('loading');

var form = this.closest('form');
var button = this;

var formData = form.serializeArray();
formData.push({ name: button.attr('name'), value: '1' });

$.ajax({
url: form.attr('action'),
data: formData,
type: 'POST',
global: false,
complete: function complete() {
dialog.removeClass('loading');
},
success: function success(data, status, xhr) {
if (xhr.getResponseHeader('Content-Type') == 'text/plain') {
dialog.append('<div class="add-to-campaign__response add-to-campaign__response--good"><span>' + data + '</span></div>');
} else {
dialog.html(data);
}
},
error: function error(xhr, status) {
var error = xhr.responseText || "Something went wrong. Please try again in a few minutes.";
dialog.append('<div class="add-to-campaign__response add-to-campaign__response--error"><span>' + error + '</span></div>');
}
});

return false;
}
}), $('#add-to-campaign__dialog').entwine({
onadd: function onadd() {
if (!this.is('.ui-dialog-content')) {
this.ssdialog({
autoOpen: true,
minHeight: 200,
maxHeight: 200,
minWidth: 200,
maxWidth: 500
});
}

this._super();
},

open: function open() {
this.ssdialog('open');
},

close: function close() {
this.ssdialog('close');
},

'onssdialogclose': function onssdialogclose() {
this.empty();
},

'onchosen:showing_dropdown': function onchosenShowing_dropdown() {
this.css({ overflow: 'visible' });
},

'onchosen:hiding_dropdown': function onchosenHiding_dropdown() {
this.css({ overflow: '' });
}
});
});
});
4 changes: 2 additions & 2 deletions admin/client/dist/js/bundle-framework.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions admin/client/dist/js/bundle-legacy.js

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions admin/client/dist/js/bundle-lib.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions admin/client/dist/styles/bundle.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions admin/client/src/bundles/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ require('../legacy/LeftAndMain.BatchActions.js');
require('../legacy/LeftAndMain.FieldHelp.js');
require('../legacy/LeftAndMain.FieldDescriptionToggle.js');
require('../legacy/LeftAndMain.TreeDropdownField.js');
require('../legacy/AddToCampaignForm.js');

1 change: 1 addition & 0 deletions admin/client/src/bundles/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ require('../../../../client/src/legacy/HtmlEditorField.js');
require('../../../../client/src/legacy/TabSet.js');
require('../legacy/ssui.core.js');
require('../../../../client/src/legacy/GridField.js');
require('json-js');
87 changes: 87 additions & 0 deletions admin/client/src/legacy/AddToCampaignForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import $ from 'jQuery';
import i18n from 'i18n';

$.entwine('ss', function($){
$('.add-to-campaign-action, #add-to-campaign__action').entwine({
onclick: function() {
var dialog = $('#add-to-campaign__dialog');

if (dialog.length) {
dialog.open();
} else {
dialog = $('<div id="add-to-campaign__dialog" />');
$('body').append(dialog);
}

if (dialog.children().length == 0) dialog.addClass('loading');

var form = this.closest('form');
var button = this;

var formData = form.serializeArray();
formData.push({name: button.attr('name'), value:'1'});

$.ajax({
url: form.attr('action'),
data: formData,
type: 'POST',
global: false,
complete: function() {
dialog.removeClass('loading');
},
success: function(data, status, xhr) {
if (xhr.getResponseHeader('Content-Type') == 'text/plain') {
dialog.append('<div class="add-to-campaign__response add-to-campaign__response--good"><span>'+data+'</span></div>');
}
else {
dialog.html(data);
}
},
error: function(xhr, status) {
var error = xhr.responseText || "Something went wrong. Please try again in a few minutes.";
dialog.append('<div class="add-to-campaign__response add-to-campaign__response--error"><span>'+error+'</span></div>');
}
});

return false;
}
}),

$('#add-to-campaign__dialog').entwine({
onadd: function() {
// Create jQuery dialog
if (!this.is('.ui-dialog-content')) {
this.ssdialog({
autoOpen: true,
minHeight: 200,
maxHeight: 200,
minWidth: 200,
maxWidth: 500
});
}

this._super();
},

open: function() {
this.ssdialog('open');
},

close: function() {
this.ssdialog('close');
},

'onssdialogclose': function() {
this.empty();
},

'onchosen:showing_dropdown': function() {
this.css({overflow: 'visible'});
},

'onchosen:hiding_dropdown': function() {
this.css({overflow: ''});
}
});

})
104 changes: 104 additions & 0 deletions admin/client/src/styles/legacy/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,110 @@ body.cms-dialog {
}
}

/** --------------------------------------------
* Add to campaign dialog
* -------------------------------------------- */

#add-to-campaign__dialog {
padding: 0;
overflow: hidden;

.add-to-campaign__header {
@extend .cms-content-header;

padding: 12px 16px;
width: 100%;
height: 52px;
margin: 0;
border: 0;

h3 {
margin: 0;
line-height: 28px;
}
}

.add-to-campaign__content {
padding: 12px 16px;
margin: 0;
border: 0;
}

.add-to-campaign__action {
@extend .ss-ui-action-constructive;
}

.Actions {
padding: 0 16px;
}

.chosen-results > li {
padding: $spacer-y/1.5 $spacer-x;
}

.disabled-result {
font-style: italic;

&::after {
font-style: normal;
content: 'Already contains item';
color: $color-text-blue-link;
margin-left: $spacer-x;
float: right;
}
}

@keyframes add-to-campaign--slideup {
from {
bottom: -100%
}
to {
bottom: 0
}
}

.add-to-campaign__response {
position: absolute;
bottom: 0;
height: 100%;
left: 0;
width: 100%;
animation:add-to-campaign--slideup 2s 1;
background: white;

display: table;

span {
display: table-cell;
text-align: center;
vertical-align: middle;
padding-bottom: $spacer-y;

&::before {
font-size: 48px; line-height: 40px;
display: block;
padding-bottom: $spacer-y;
}
}
}

.add-to-campaign__response--good {
span::before {
content: "";
color: $brand-success;
}
}

.add-to-campaign__response--error {
span::before {
/* This is a sad face emoticon. Some fonts don't carry it. @todo: replace or test in all browsers */
content: "";
color: $brand-danger;
}
}
}


/** --------------------------------------------
* Search forms (used in AssetAdmin, ModelAdmin, etc)
* -------------------------------------------- */
Expand Down
Loading

0 comments on commit a4437fa

Please sign in to comment.