-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
175 additions
and
5 deletions.
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
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,63 @@ | ||
import _ from 'lodash'; | ||
|
||
import { NamedPage } from 'vj/misc/PageLoader'; | ||
import Notification from 'vj/components/notification'; | ||
import { ConfirmDialog } from 'vj/components/dialog'; | ||
|
||
import request from 'vj/utils/request'; | ||
import tpl from 'vj/utils/tpl'; | ||
import delay from 'vj/utils/delay'; | ||
import i18n from 'vj/utils/i18n'; | ||
|
||
const page = new NamedPage('admin_mail', () => { | ||
function ensureAndGetSelectedUsers() { | ||
const users = _.map( | ||
$('.admin_user_list tbody [type="checkbox"]:checked'), | ||
ch => $(ch).closest('tr').attr('data-uid'), | ||
); | ||
if (users.length === 0) { | ||
Notification.error(i18n('Please select at least one user to perform this operation.')); | ||
return null; | ||
} | ||
return users; | ||
} | ||
|
||
async function sendMail(uid, title, content){ | ||
try { | ||
await request.post('', { | ||
operation: 'send_mail', | ||
uid: uid, | ||
title: title, | ||
content: content | ||
}); | ||
Notification.success(i18n('Mail successfully sent to uid:{0}.', uid)); | ||
} catch (error) { | ||
Notification.error(`Error uid:${uid} ${error.message}`); | ||
} | ||
} | ||
|
||
async function handleClickSend() { | ||
const selectedUsers = ensureAndGetSelectedUsers(); | ||
if (selectedUsers === null) { | ||
return; | ||
} | ||
const action = await new ConfirmDialog({ | ||
$body: tpl` | ||
<div class="typo"> | ||
<p>${i18n('Confirm sending Email to selected users?')}</p> | ||
</div>`, | ||
}).open(); | ||
if (action !== 'yes') { | ||
return; | ||
} | ||
const mail_content_container = $("#mail_content_container"); | ||
const mail_title = mail_content_container.find('[name="title"]').val(); | ||
const mail_content = mail_content_container.find('[name="content"]').val(); | ||
_.map(selectedUsers, async ch => { await sendMail(ch, mail_title, mail_content)}); | ||
} | ||
|
||
|
||
$('[name="btn_send_mail"]').click(() => handleClickSend()); | ||
}); | ||
|
||
export default page; |
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,9 @@ | ||
.page--admin_mail | ||
.col--checkbox | ||
width: 60px | ||
|
||
.col--uid | ||
width: 100px | ||
|
||
.col--role | ||
width: 160px |
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,63 @@ | ||
{% extends "admin_base.html" %} | ||
{% block admin_content %} | ||
<div class="section"> | ||
<div class="section__header"> | ||
<h1 class="section__title">{{ _('Send mail to selected users') }}</h1> | ||
</div> | ||
{{ noscript_note.render() }} | ||
<div class="section__body no-padding admin_user_list"> | ||
<table class="data-table"> | ||
<colgroup> | ||
<col class="col--checkbox"> | ||
<col class="col--uid"> | ||
<col class="col--user"> | ||
</colgroup> | ||
<thead> | ||
<tr> | ||
<th class="col--checkbox"> | ||
<label class="compact checkbox"> | ||
<input type="checkbox" name="select_all" data-checkbox-toggle="user"> | ||
</label> | ||
</th> | ||
<th class="col--uid">{{ _('User ID') }}</th> | ||
<th class="col--user">{{ _('Username') }}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for udoc in udocs %} | ||
<tr data-uid="{{ udoc['_id'] }}" data-badge="{%if udoc['tags'] %}{{ ' '.join(udoc['tags']) }}{% endif %}"> | ||
<td class="col--checkbox"> | ||
<label class="compact checkbox"> | ||
<input type="checkbox" data-checkbox-group="user"> | ||
</label> | ||
</td> | ||
<td class="col--uid"> | ||
{{ udoc['_id'] }} | ||
</td> | ||
<td class="col--user"> | ||
{{ user.render_inline(udoc) }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<div class="section"> | ||
<div class="section__header"> | ||
<h1 class="section__title">{{ _('Mail Content') }}</h1> | ||
</div> | ||
<div class="section__body" id="mail_content_container"> | ||
{% include "partials/admin_send_mail_form.html" %} | ||
<div class="row"><div class="columns"> | ||
<button type="submit" name="btn_send_mail" class="rounded primary button"> | ||
{{ _('Send') }} | ||
</button> | ||
<button type="button" class="rounded button" onclick="window.history.go(-1)"> | ||
{{ _('Cancel') }} | ||
</button> | ||
</div></div> | ||
</div> | ||
</div> | ||
{% endblock %} |
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,9 @@ | ||
{% extends "layout/mail.html" %} | ||
{% block title %}{{ mail_title }}{% endblock %} | ||
{% block content %} | ||
{{ mail_content|safe }} | ||
<br /> | ||
<br /> | ||
<br /> | ||
<i>This is a broadcast email. Do not reply.</i> | ||
{% endblock %} |
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,3 @@ | ||
{% import "components/form.html" as form with context %} | ||
{{ form.form_text(label='Title', name='title', autofocus=true, required=true) }} | ||
{{ form.form_textarea(columns=20, label='Content', name='content', hotkeys='ctrl+enter:submit', required=true) }} |