Skip to content
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

Mailing list configuration #7

Merged
merged 3 commits into from
Dec 1, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions components/MailingListAdminPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ var BSPanel = require("react-bootstrap/Panel");
var MKAlertTrigger = require("mykoop-core/components/AlertTrigger");
var MKIcon = require("mykoop-core/components/Icon");
var MKMailingListEditPanel = require("./MailingListEditPanel");
var MKMailingListConfig = require("./MailingListConfig")

var __ = require("language").__;
var _ = require("lodash");
var actions = require("actions");

var showPerRow = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe itemsPerRow?

var MailingListAdminPage = React.createClass({
getInitialState: function() {
return {
Expand Down Expand Up @@ -81,7 +83,7 @@ var MailingListAdminPage = React.createClass({
var self = this;
var mailingLists = _.map(this.state.mailingLists, function(mailingList, i) {
return (
<BSCol md={6} sm={12} key={i}>
<BSCol md={12/showPerRow} sm={12} key={i}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps round/floor it?

<MKMailingListEditPanel
idLink={self.makeValueLink(mailingList, "id")}
nameLink={self.makeValueLink(mailingList, "name")}
Expand All @@ -98,19 +100,46 @@ var MailingListAdminPage = React.createClass({
</BSCol>
);
});

mailingLists.push(
<BSCol md={12/showPerRow} sm={12} key="newMailingList">
<BSPanel className="mailingList-new-panel" onClick={this.createNewMailingList}>
<MKIcon glyph="plus-circle" className="mailingList-new" />
</BSPanel>
</BSCol>
);

if(showPerRow <= 1) {
mailingLists = (
<BSRow>
{mailingLists}
</BSRow>
);
} else {
var panels = mailingLists;
var curSlice = 0;
mailingLists = [];
while(!_.isEmpty(panels)) {
var rowContent = _.first(panels, showPerRow);
panels = _.rest(panels, showPerRow);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL!

mailingLists.push(
<BSRow key={curSlice}>
{rowContent}
</BSRow>
);
curSlice++;
}
}

return (
<BSCol>
<h1>
{__("mailinglist::adminEditWelcome")}
</h1>
<BSRow>
{mailingLists}
<BSCol md={6} sm={12} key="newMailingList">
<BSPanel className="mailingList-new-panel" onClick={this.createNewMailingList}>
<MKIcon glyph="plus-circle" className="mailingList-new" />
</BSPanel>
</BSCol>
<BSRow key="config">
<MKMailingListConfig />
</BSRow>
{mailingLists}
</BSCol>
);
}
Expand Down
74 changes: 74 additions & 0 deletions components/MailingListConfig.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
var React = require('react');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quotes.


var BSCol = require("react-bootstrap/Col");
var BSInput = require("react-bootstrap/Input");
var BSButton = require("react-bootstrap/Button");

var MKCollapsablePanel = require("mykoop-core/components/CollapsablePanel");
var MKFeedbacki18nMixin = require("mykoop-core/components/Feedbacki18nMixin");

var actions = require("actions");
var __ = require("language").__;

var MailingListConfig = React.createClass({
mixins: [React.addons.LinkedStateMixin, MKFeedbacki18nMixin],

getInitialState: function() {
return {
globalSender: ""
};
},

componentWillMount: function () {
var self = this;
actions.mailinglist.config.get({
i18nErrors: {}
},function(err, res) {
if(err) {
return self.setFeedback(err.i18n, "danger");
}
self.setState({
globalSender: res.globalSender
});
});
},

saveConfig: function() {
var self = this;
self.clearFeedback();
actions.mailinglist.config.set({
i18nErrors: {},
data: {
globalSender: this.state.globalSender
}
},function(err, res) {
if(err) {
return self.setFeedback(err.i18n, "danger");
}
self.setFeedback({key: "success"}, "success");
});
},

render: function () {
return (
<BSCol md={6}>
<MKCollapsablePanel header={__("mailinglist::config")}>
{this.renderFeedback()}
<BSInput
type="email"
label={__("mailinglist::globalEmail")}
valueLink={this.linkState("globalSender")}
/>
<BSButton
bsStyle="primary"
onClick={this.saveConfig}
>
{__("update")}
</BSButton>
</MKCollapsablePanel>
</BSCol>
);
}
});

module.exports = MailingListConfig;
29 changes: 29 additions & 0 deletions lib/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var _ = require("lodash");
// Controllers.
function attachControllers(binder) {
var mailingList = binder.moduleInstance;
// Add new Mailing list
binder.attach({
endPoint: endpoints.mailinglist.add,
validation: validation.mailingListDefinition
Expand All @@ -15,6 +16,7 @@ function attachControllers(binder) {
};
return params;
}));
// Update Mailing list
binder.attach({
endPoint: endpoints.mailinglist.update,
validation: validation.mailingListDefinition
Expand All @@ -27,6 +29,7 @@ function attachControllers(binder) {
};
return params;
}));
// Delete Mailing list
binder.attach({
endPoint: endpoints.mailinglist.delete,
validation: validation.mailinglistId
Expand All @@ -36,12 +39,15 @@ function attachControllers(binder) {
};
return params;
}));
// Get all mailing lists
binder.attach({ endPoint: endpoints.mailinglist.list }, binder.makeSimpleController(mailingList.getMailingLists));
// Get mailing for registration only
binder.attach({ endPoint: endpoints.mailinglist.registration }, binder.makeSimpleController(mailingList.getMailingLists, function () {
return {
inRegistration: true
};
}));
// Register a user to multiple mailing lists
binder.attach({
endPoint: endpoints.user.mailinglist.register
}, binder.makeSimpleController(mailingList.registerToMailingLists, function (req) {
Expand All @@ -53,6 +59,7 @@ function attachControllers(binder) {
};
return params;
}));
// Unregister a user to multiple mailing lists
binder.attach({
endPoint: endpoints.user.mailinglist.unregister
}, binder.makeSimpleController(mailingList.unregisterToMailingLists, function (req) {
Expand All @@ -64,6 +71,7 @@ function attachControllers(binder) {
};
return params;
}));
// Get mailing list the user is registered to
binder.attach({
endPoint: endpoints.user.mailinglist.list,
validation: validation.mailinglistId
Expand All @@ -73,5 +81,26 @@ function attachControllers(binder) {
};
return params;
}));
// Set mailing list configuration
binder.attach({
endPoint: endpoints.mailinglist.config.set
}, binder.makeSimpleController(mailingList.setConfigurations, function (req) {
return {
globalSender: req.param("globalSender", "")
};
}));
// Get mailing list configuration
binder.attach({
endPoint: endpoints.mailinglist.config.get
}, binder.makeSimpleController(mailingList.getConfigurations));
// Send email to the mailing list
binder.attach({
endPoint: endpoints.mailinglist.send
}, binder.makeSimpleController(mailingList.sendEmail, function (req) {
return {
id: parseInt(req.param("id")) || 0,
content: req.param("content", "")
};
}));
}
exports.attachControllers = attachControllers;
50 changes: 50 additions & 0 deletions lib/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export function attachControllers(
binder: utils.ModuleControllersBinder<mkmailinglist.Module>
) {
var mailingList = binder.moduleInstance;

// Add new Mailing list
binder.attach(
{
endPoint: endpoints.mailinglist.add,
Expand All @@ -25,6 +27,7 @@ export function attachControllers(
})
);

// Update Mailing list
binder.attach(
{
endPoint: endpoints.mailinglist.update,
Expand All @@ -41,6 +44,7 @@ export function attachControllers(
})
);

// Delete Mailing list
binder.attach(
{
endPoint: endpoints.mailinglist.delete,
Expand All @@ -54,11 +58,13 @@ export function attachControllers(
})
);

// Get all mailing lists
binder.attach(
{endPoint: endpoints.mailinglist.list},
binder.makeSimpleController(mailingList.getMailingLists)
);

// Get mailing for registration only
binder.attach(
{endPoint: endpoints.mailinglist.registration},
binder.makeSimpleController<MailingList.GetMailingList.Params>(
Expand All @@ -71,6 +77,7 @@ export function attachControllers(
)
);

// Register a user to multiple mailing lists
binder.attach(
{
endPoint: endpoints.user.mailinglist.register
Expand All @@ -86,6 +93,7 @@ export function attachControllers(
})
);

// Unregister a user to multiple mailing lists
binder.attach(
{
endPoint: endpoints.user.mailinglist.unregister
Expand All @@ -101,6 +109,7 @@ export function attachControllers(
})
);

// Get mailing list the user is registered to
binder.attach(
{
endPoint: endpoints.user.mailinglist.list,
Expand All @@ -113,4 +122,45 @@ export function attachControllers(
return params;
})
);

// Set mailing list configuration
binder.attach(
{
endPoint: endpoints.mailinglist.config.set
},
binder.makeSimpleController<MailingList.SetConfigurations.Params>(
mailingList.setConfigurations,
function(req) {
return {
globalSender: req.param("globalSender", "")
}
}
)
);

// Get mailing list configuration
binder.attach(
{
endPoint: endpoints.mailinglist.config.get
},
binder.makeSimpleController<MailingList.GetConfigurations.Params>(
mailingList.getConfigurations
)
);

// Send email to the mailing list
binder.attach(
{
endPoint: endpoints.mailinglist.send
},
binder.makeSimpleController<MailingList.SendEmail.Params>(
mailingList.sendEmail,
function(req) {
return {
id: parseInt(req.param("id")) || 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req.param("id", 0)

content: req.param("content","")
}
}
)
);
}
Loading