Update newsletter saving to reflect code review comments
- Switch to using full segment objects when saving newsletters - Fix stale comment in newsletter editor's Newsletter model - Fix typo in newsletter editor tests
This commit is contained in:
@@ -122,9 +122,10 @@ function(
|
||||
} else {
|
||||
value = e.target.value;
|
||||
}
|
||||
var transformedValue = this.transformChangedValue(value);
|
||||
this.props.onValueChange({
|
||||
target: {
|
||||
value: value,
|
||||
value: transformedValue,
|
||||
name: this.props.field.name
|
||||
}
|
||||
});
|
||||
@@ -148,6 +149,16 @@ function(
|
||||
}
|
||||
return item.id;
|
||||
},
|
||||
// When it's impossible to represent the desired value in DOM,
|
||||
// this function may be used to transform the placeholder value into
|
||||
// desired value.
|
||||
transformChangedValue: function(value) {
|
||||
if(typeof this.props.field['transformChangedValue'] === 'function') {
|
||||
return this.props.field.transformChangedValue.call(this, value);
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
},
|
||||
render: function() {
|
||||
const options = this.state.items.map((item, index) => {
|
||||
let label = this.getLabel(item);
|
||||
|
@@ -18,7 +18,8 @@ define([
|
||||
});
|
||||
},
|
||||
toJSON: function() {
|
||||
// Remove stale attributes from resulting JSON object
|
||||
// Use only whitelisted properties to ensure properties editor
|
||||
// doesn't control don't change.
|
||||
return _.pick(SuperModel.prototype.toJSON.call(this), this.whitelisted);
|
||||
},
|
||||
});
|
||||
|
@@ -1,11 +1,13 @@
|
||||
define(
|
||||
[
|
||||
'mailpoet',
|
||||
'newsletters/types/notification/scheduling.jsx'
|
||||
'newsletters/types/notification/scheduling.jsx',
|
||||
'underscore'
|
||||
],
|
||||
function(
|
||||
MailPoet,
|
||||
Scheduling
|
||||
Scheduling,
|
||||
_
|
||||
) {
|
||||
|
||||
var settings = window.mailpoet_settings || {};
|
||||
@@ -42,6 +44,14 @@ define(
|
||||
getLabel: function(segment) {
|
||||
return segment.name + ' (' + parseInt(segment.subscribers).toLocaleString() + ')';
|
||||
},
|
||||
transformChangedValue: function(segment_ids) {
|
||||
var all_segments = this.state.items;
|
||||
return _.map(segment_ids, function(id) {
|
||||
return _.find(all_segments, function(segment) {
|
||||
return segment.id === id;
|
||||
});
|
||||
});
|
||||
},
|
||||
validation: {
|
||||
'data-parsley-required': true,
|
||||
'data-parsley-required-message': MailPoet.I18n.t('noSegmentsSelectedError')
|
||||
|
@@ -348,6 +348,14 @@ define(
|
||||
getLabel: function(segment) {
|
||||
return segment.name + ' (' + parseInt(segment.subscribers).toLocaleString() + ')';
|
||||
},
|
||||
transformChangedValue: function(segment_ids) {
|
||||
var all_segments = this.state.items;
|
||||
return _.map(segment_ids, function(id) {
|
||||
return _.find(all_segments, function(segment) {
|
||||
return segment.id === id;
|
||||
});
|
||||
});
|
||||
},
|
||||
validation: {
|
||||
'data-parsley-required': true,
|
||||
'data-parsley-required-message': MailPoet.I18n.t('noSegmentsSelectedError')
|
||||
|
Reference in New Issue
Block a user