-
Notifications
You must be signed in to change notification settings - Fork 820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AddToCampaign dialog box functionality #5368
Merged
tractorcow
merged 1 commit into
silverstripe:master
from
open-sausages:pulls/4.0/add-to-campaign
Apr 26, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
(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" class="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').indexOf('text/plain') === 0) { | ||
var container = $('<div class="add-to-campaign__response add-to-campaign__response--good"><span></span></div>'); | ||
container.find('span').text(data); | ||
dialog.append(container); | ||
} else { | ||
dialog.html(data); | ||
} | ||
}, | ||
error: function error(xhr, status) { | ||
var error = xhr.responseText || "Something went wrong. Please try again in a few minutes."; | ||
var container = $('<div class="add-to-campaign__response add-to-campaign__response--error"><span></span></div>'); | ||
container.find('span').text(error); | ||
dialog.append(container); | ||
} | ||
}); | ||
|
||
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: '' }); | ||
} | ||
}); | ||
}); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
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" class="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').indexOf('text/plain') === 0) { | ||
var container = $('<div class="add-to-campaign__response add-to-campaign__response--good"><span></span></div>'); | ||
container.find('span').text(data); | ||
dialog.append(container); | ||
} else { | ||
dialog.html(data); | ||
} | ||
}, | ||
error: function(xhr, status) { | ||
var error = xhr.responseText || "Something went wrong. Please try again in a few minutes."; | ||
var container = $('<div class="add-to-campaign__response add-to-campaign__response--error"><span></span></div>'); | ||
container.find('span').text(error); | ||
dialog.append(container); | ||
} | ||
}); | ||
|
||
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: ''}); | ||
} | ||
}); | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we shouldn't rely on IDs for styles. I thought it was bad practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this in the BEM style guides somewhere? If there's only ever one of anything I don't see the problem (given it's attached to body and never removed, we want there to only be one, not an ever-increasing number). But if it's against style, sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't use id's, we will be using the Airbnb css guides to get going and it also states in there don't use ids https://github.com/airbnb/css and also in BEM docs http://getbem.com/naming/