Commit c4b48d70 authored by JC Brand's avatar JC Brand

bookmark-views: Changes templates to lit-html

parent d310f1e3
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
*/ */
import "@converse/headless/converse-muc"; import "@converse/headless/converse-muc";
import { Model } from 'skeletor.js/src/model.js'; import { Model } from 'skeletor.js/src/model.js';
import { HTMLView } from 'skeletor.js/src/htmlview.js';
import { __ } from '@converse/headless/i18n';
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
import tpl_bookmarks_list from "templates/bookmarks_list.html" import tpl_bookmarks_list from "templates/bookmarks_list.js"
import tpl_chatroom_bookmark_form from "templates/chatroom_bookmark_form.html"; import tpl_muc_bookmark_form from "templates/muc_bookmark_form.js";
import tpl_chatroom_bookmark_toggle from "templates/chatroom_bookmark_toggle.html"; import tpl_chatroom_bookmark_toggle from "templates/chatroom_bookmark_toggle.html";
const { Backbone, Strophe, _ } = converse.env; const { Backbone, Strophe, _ } = converse.env;
...@@ -54,8 +56,7 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -54,8 +56,7 @@ converse.plugins.add('converse-bookmark-views', {
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
const { _converse } = this, const { _converse } = this;
{ __ } = _converse;
// Configuration values for this plugin // Configuration values for this plugin
// ==================================== // ====================================
...@@ -98,9 +99,6 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -98,9 +99,6 @@ converse.plugins.add('converse-bookmark-views', {
if (this.el.querySelector('.chat-head .toggle-bookmark')) { if (this.el.querySelector('.chat-head .toggle-bookmark')) {
return; return;
} }
const { _converse } = this.__super__,
{ __ } = _converse;
const bookmark_button = tpl_chatroom_bookmark_toggle( const bookmark_button = tpl_chatroom_bookmark_toggle(
_.assignIn(this.model.toJSON(), { _.assignIn(this.model.toJSON(), {
'info_toggle_bookmark': this.model.get('bookmarked') ? 'info_toggle_bookmark': this.model.get('bookmarked') ?
...@@ -118,9 +116,11 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -118,9 +116,11 @@ converse.plugins.add('converse-bookmark-views', {
} }
}, },
/**
* Set whether the groupchat is bookmarked or not.
* @private
*/
setBookmarkState () { setBookmarkState () {
/* Set whether the groupchat is bookmarked or not.
*/
if (_converse.bookmarks !== undefined) { if (_converse.bookmarks !== undefined) {
const models = _converse.bookmarks.where({'jid': this.model.get('jid')}); const models = _converse.bookmarks.where({'jid': this.model.get('jid')});
if (!models.length) { if (!models.length) {
...@@ -160,13 +160,8 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -160,13 +160,8 @@ converse.plugins.add('converse-bookmark-views', {
Object.assign(_converse.ChatRoomView.prototype, bookmarkableChatRoomView); Object.assign(_converse.ChatRoomView.prototype, bookmarkableChatRoomView);
_converse.MUCBookmarkForm = Backbone.VDOMView.extend({ _converse.MUCBookmarkForm = HTMLView.extend({
className: 'muc-bookmark-form', className: 'muc-bookmark-form chatroom-form-container',
events: {
'submit form': 'onBookmarkFormSubmitted',
'click .button-cancel': 'closeBookmarkForm'
},
initialize (attrs) { initialize (attrs) {
this.chatroomview = attrs.chatroomview; this.chatroomview = attrs.chatroomview;
...@@ -174,16 +169,12 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -174,16 +169,12 @@ converse.plugins.add('converse-bookmark-views', {
}, },
toHTML () { toHTML () {
return tpl_chatroom_bookmark_form({ return tpl_muc_bookmark_form(Object.assign(
'default_nick': this.model.get('nick'), this.model.toJSON(), {
'heading': __('Bookmark this groupchat'), 'onCancel': ev => this.closeBookmarkForm(ev),
'label_autojoin': __('Would you like this groupchat to be automatically joined upon startup?'), 'onSubmit': ev => this.onBookmarkFormSubmitted(ev)
'label_cancel': __('Cancel'), }
'label_name': __('The name for this bookmark:'), ));
'label_nick': __('What should your nickname for this groupchat be?'),
'label_submit': __('Save'),
'name': this.model.get('name')
});
}, },
onBookmarkFormSubmitted (ev) { onBookmarkFormSubmitted (ev) {
...@@ -204,9 +195,8 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -204,9 +195,8 @@ converse.plugins.add('converse-bookmark-views', {
}); });
_converse.BookmarksView = Backbone.VDOMView.extend({ _converse.BookmarksView = HTMLView.extend({
tagName: 'div', tagName: 'span',
className: 'bookmarks-list list-container rooms-list-container',
events: { events: {
'click .add-bookmark': 'addBookmark', 'click .add-bookmark': 'addBookmark',
'click .bookmarks-toggle': 'toggleBookmarksList', 'click .bookmarks-toggle': 'toggleBookmarksList',
...@@ -236,13 +226,6 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -236,13 +226,6 @@ converse.plugins.add('converse-bookmark-views', {
return tpl_bookmarks_list({ return tpl_bookmarks_list({
'_converse': _converse, '_converse': _converse,
'bookmarks': this.model, 'bookmarks': this.model,
'desc_bookmarks': __('Click to toggle the bookmarks list'),
'info_leave_room': __('Leave this groupchat'),
'info_remove': __('Remove this bookmark'),
'info_remove_bookmark': __('Unbookmark this groupchat'),
'info_title': __('Show more information on this groupchat'),
'label_bookmarks': __('Bookmarks'),
'open_title': __('Click to open this groupchat'),
'toggle_state': this.list_model.get('toggle-state'), 'toggle_state': this.list_model.get('toggle-state'),
'is_bookmark_hidden': b => { 'is_bookmark_hidden': b => {
return !!(_converse.hide_open_bookmarks && _converse.chatboxes.get(b.get('jid'))) return !!(_converse.hide_open_bookmarks && _converse.chatboxes.get(b.get('jid')))
......
<div class="list-container list-container--bookmarks {{{ !o.hidden && 'hidden' || '' }}}">
<a href="#" class="list-toggle bookmarks-toggle controlbox-padded" title="{{{o.desc_bookmarks}}}">
<span class="fa {[ if (o.toggle_state === o._converse.OPENED) { ]} fa-caret-down {[ } else { ]} fa-caret-right {[ } ]}">
</span> {{{o.label_bookmarks}}}</a>
<div class="items-list bookmarks rooms-list {[ if (o.toggle_state !== o._converse.OPENED) { ]} hidden {[ } ]}">
{[o.bookmarks.forEach(function (bm) { ]}
<div class="list-item controlbox-padded room-item available-chatroom d-flex flex-row {[ if (o.is_bookmark_hidden(bm)) { ]} hidden {[ } ]}" data-room-jid="{{{bm.get('jid')}}}">
<a class="list-item-link open-room w-100" data-room-jid="{{{bm.get('jid')}}}" title="{{{o.open_title}}}" href="#">{{{bm.getDisplayName()}}}</a>
<a class="list-item-action remove-bookmark fa fa-bookmark align-self-center {[ if (bm.get('bookmarked')) { ]} button-on {[ } ]}"
data-room-jid="{{{bm.get('jid')}}}" data-bookmark-name="{{{bm.getDisplayName()}}}"
title="{{{o.info_remove_bookmark}}}" href="#"></a>
</div>
{[ }) ]}
</div>
</div>
import { html } from "lit-html";
import { __ } from '@converse/headless/i18n';
const desc_bookmarks = __('Click to toggle the bookmarks list');
const info_remove_bookmark = __('Unbookmark this groupchat');
const label_bookmarks = __('Bookmarks');
const open_title = __('Click to open this groupchat');
const bookmark_item = (o) => html`
<div class="list-item controlbox-padded room-item available-chatroom d-flex flex-row ${ (o.is_bookmark_hidden(o.bm)) ? 'hidden' : ''}" data-room-jid="${o.bm.get('jid')}">
<a class="list-item-link open-room w-100" data-room-jid="${o.bm.get('jid')}" title="${open_title}" href="#">${o.bm.getDisplayName()}</a>
<a class="list-item-action remove-bookmark fa fa-bookmark align-self-center ${ o.bm.get('bookmarked') ? 'button-on' : '' }"
data-room-jid="${o.bm.get('jid')}" data-bookmark-name="${o.bm.getDisplayName()}"
title="${info_remove_bookmark}" href="#"></a>
</div>
`;
export default (o) => html`
<div class="list-container list-container--bookmarks ${ !o.hidden && 'hidden' || '' }">
<a href="#" class="list-toggle bookmarks-toggle controlbox-padded" title="${desc_bookmarks}">
<span class="fa ${(o.toggle_state === o._converse.OPENED) ? 'fa-caret-down' : 'fa-caret-right' }">
</span> ${label_bookmarks}</a>
<div class="items-list bookmarks rooms-list ${ (o.toggle_state !== o._converse.OPENED) ? 'hidden' : '' }">
${ o.bookmarks.map(bm => bookmark_item(Object.assign({bm}, o))) }
</div>
</div>
`;
<div class="chatroom-form-container muc-bookmark-form"> import { html } from "lit-html";
<form class="converse-form chatroom-form"> import { __ } from '@converse/headless/i18n';
<legend>{{{o.heading}}}</legend>
const i18n_heading = __('Bookmark this groupchat');
const i18n_autojoin = __('Would you like this groupchat to be automatically joined upon startup?');
const i18n_cancel = __('Cancel');
const i18n_name = __('The name for this bookmark:');
const i18n_nick = __('What should your nickname for this groupchat be?');
const i18n_submit = __('Save');
export default (o) => html`
<form class="converse-form chatroom-form" @submit=${o.onSubmit}>
<legend>${i18n_heading}</legend>
<fieldset class="form-group"> <fieldset class="form-group">
<label for="converse_muc_bookmark_name">{{{o.label_name}}}</label> <label for="converse_muc_bookmark_name">${i18n_name}</label>
<input class="form-control" type="text" value="{{{o.name}}}" name="name" required="required" id="converse_muc_bookmark_name"/> <input class="form-control" type="text" value="${o.name}" name="name" required="required" id="converse_muc_bookmark_name"/>
</fieldset> </fieldset>
<fieldset class="form-group"> <fieldset class="form-group">
<label for="converse_muc_bookmark_nick">{{{o.label_nick}}}</label> <label for="converse_muc_bookmark_nick">${i18n_nick}</label>
<input class="form-control" type="text" name="nick" value="{{{o.default_nick}}}" id="converse_muc_bookmark_nick"/> <input class="form-control" type="text" name="nick" value="${o.nick}" id="converse_muc_bookmark_nick"/>
</fieldset> </fieldset>
<fieldset class="form-group form-check"> <fieldset class="form-group form-check">
<input class="form-check-input" id="converse_muc_bookmark_autojoin" type="checkbox" name="autojoin"/> <input class="form-check-input" id="converse_muc_bookmark_autojoin" type="checkbox" name="autojoin"/>
<label class="form-check-label" for="converse_muc_bookmark_autojoin">{{{o.label_autojoin}}}</label> <label class="form-check-label" for="converse_muc_bookmark_autojoin">${i18n_autojoin}</label>
</fieldset> </fieldset>
<fieldset class="form-group"> <fieldset class="form-group">
<input class="btn btn-primary" type="submit" value="{{{o.label_submit}}}"/> <input class="btn btn-primary" type="submit" value="${i18n_submit}">
<input class="btn btn-secondary button-cancel" type="button" value="{{{o.label_cancel}}}"/> <input class="btn btn-secondary button-cancel" type="button" value="${i18n_cancel}" @click=${o.onCancel}>
</fieldset> </fieldset>
</form> </form>
</div> `;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment