1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Make use of WCF.Template (JavaScript)

This commit is contained in:
Maximilian Mader 2014-12-12 23:15:58 +01:00
parent 430c0e4ad1
commit 55d634d78e
4 changed files with 98 additions and 93 deletions

View File

@ -84,7 +84,7 @@ exposed by a function if necessary.
Initialize **Tims Chat**. Bind needed DOM events and initialize data structures. Initialize **Tims Chat**. Bind needed DOM events and initialize data structures.
initialized = false initialized = false
init = (roomID, config, titleTemplate, messageTemplate, userTemplate, userMenuTemplate) -> init = (roomID, config, titleTemplate, messageTemplate, userTemplate, userMenuTemplate, userInviteDialogTemplate) ->
return false if initialized return false if initialized
initialized = true initialized = true
@ -95,6 +95,17 @@ Initialize **Tims Chat**. Bind needed DOM events and initialize data structures.
v.messageTemplate = messageTemplate v.messageTemplate = messageTemplate
v.userTemplate = userTemplate v.userTemplate = userTemplate
v.userMenuTemplate = userMenuTemplate v.userMenuTemplate = userMenuTemplate
v.userInviteDialogTemplate = userInviteDialogTemplate
v.userInviteDialogUserListEntryTemplate = new WCF.Template """
<dl>
<dt></dt>
<dd>
<label>
<input type="checkbox" id="userInviteDialogUserID-{$user.objectID}" value="{$user.objectID}" checked="checked" /> {$user.label}
</label>
</dd>
</dl>
"""
console.log 'Initializing' console.log 'Initializing'
@ -246,7 +257,7 @@ The the word the caret is in will be passed to `autocomplete` and replaced if a
toComplete = autocomplete.value.substring lastSpace + 1 toComplete = autocomplete.value.substring lastSpace + 1
nextSpace = toComplete.indexOf ' ' nextSpace = toComplete.indexOf ' '
if nextSpace is -1 if nextSpace is -1
afterComplete = ''; afterComplete = ''
else else
afterComplete = toComplete.substring nextSpace + 1 afterComplete = toComplete.substring nextSpace + 1
toComplete = toComplete.substring 0, nextSpace toComplete = toComplete.substring 0, nextSpace
@ -361,12 +372,47 @@ Show invite dialog.
data: data:
actionName: 'prepareInvite' actionName: 'prepareInvite'
className: 'chat\\data\\user\\UserAction' className: 'chat\\data\\user\\UserAction'
showLoadingOverlay: true
suppressErrors: false
success: (data) -> success: (data) ->
$('<div id="timsChatInviteDialog"></div>').appendTo 'body' unless $.wcfIsset 'timsChatInviteDialog' $('<div id="timsChatInviteDialog"></div>').appendTo 'body' unless $.wcfIsset 'timsChatInviteDialog'
$('#timsChatInviteDialog').html(data.returnValues.template).wcfDialog timsChatInviteDialog = $ '#timsChatInviteDialog'
# Remove old event listeners
do timsChatInviteDialog.find('#userInviteDialogUsernameInput').off().remove
timsChatInviteDialog.html v.userInviteDialogTemplate.fetch
users: data.returnValues.users
new WCF.Search.User '#userInviteDialogUsernameInput', (user) ->
if $.wcfIsset "userInviteDialogUserID-#{user.objectID}"
$("#userInviteDialogUserID-#{user.objectID}").prop 'checked', true
else
$('#userInviteDialogUserList').append v.userInviteDialogUserListEntryTemplate.fetch
user: user
$('#userInviteDialogUsernameInput').val ""
, false, [ WCF.User.username ], false
$('#userInviteDialogFormSubmit').on 'click', (event) ->
checked = $ '#userInviteDialogUserList input[type=checkbox]:checked, #userInviteDialogFollowingList input[type=checkbox]:checked'
inviteUserList = [ ]
checked.each (k, v) -> inviteUserList.push do $(v).val
if inviteUserList.length
new WCF.Action.Proxy
autoSend: true
data:
actionName: 'invite'
className: 'chat\\data\\user\\UserAction'
parameters:
recipients: inviteUserList
success: (data) ->
do new WCF.System.Notification(WCF.Language.get 'wcf.global.success').show
$('#timsChatInviteDialog').wcfDialog 'close'
timsChatInviteDialog.wcfDialog
title: WCF.Language.get 'chat.global.invite' title: WCF.Language.get 'chat.global.invite'

View File

@ -33,12 +33,16 @@ public function prepareInvite() {
$followingList->readObjects(); $followingList->readObjects();
$users = $followingList->getObjects(); $users = $followingList->getObjects();
WCF::getTPL()->assign(array( $json = array();
'users' => $users foreach ($users as $user) {
)); $json[] = array(
'userID' => $user->userID,
'username' => $user->username
);
}
return array( return array(
'template' => WCF::getTPL()->fetch('userInviteDialog', 'chat') 'users' => $json
); );
} }

View File

@ -52,6 +52,7 @@
{capture assign='messageTemplate'}{include application='chat' file='message'}{/capture} {capture assign='messageTemplate'}{include application='chat' file='message'}{/capture}
{capture assign='userTemplate'}{include application='chat' file='userListUser'}{/capture} {capture assign='userTemplate'}{include application='chat' file='userListUser'}{/capture}
{capture assign='userMenuTemplate'}{include application='chat' file='userListUserMenu'}{/capture} {capture assign='userMenuTemplate'}{include application='chat' file='userListUserMenu'}{/capture}
{capture assign='userInviteDialogTemplate'}{include application='chat' file='userInviteDialog'}{/capture}
var config = { var config = {
reloadTime: {@CHAT_RELOADTIME}, reloadTime: {@CHAT_RELOADTIME},
@ -68,7 +69,8 @@
new WCF.Template('{literal}{if $newMessageCount}({#$newMessageCount}) {/if}{$title} - {/literal}{"chat.global.title"|language|encodeJS} - {PAGE_TITLE|language|encodeJS}'), new WCF.Template('{literal}{if $newMessageCount}({#$newMessageCount}) {/if}{$title} - {/literal}{"chat.global.title"|language|encodeJS} - {PAGE_TITLE|language|encodeJS}'),
new WCF.Template('{@$messageTemplate|encodeJS}'), new WCF.Template('{@$messageTemplate|encodeJS}'),
new WCF.Template('{@$userTemplate|encodeJS}'), new WCF.Template('{@$userTemplate|encodeJS}'),
new WCF.Template('{@$userMenuTemplate|encodeJS}') new WCF.Template('{@$userMenuTemplate|encodeJS}'),
new WCF.Template('{@$userInviteDialogTemplate|encodeJS}')
); );
{event name='afterInit'} {event name='afterInit'}

View File

@ -1,86 +1,39 @@
<div id="userInviteDialogContainer"> {literal}
<fieldset> <div id="userInviteDialogContainer">
<legend>{lang}wcf.user.access.following{/lang}</legend> <fieldset>
<legend>{lang}wcf.user.access.following{/lang}</legend>
{if $users|count === 0} {if $users.length === 0}
<p class="noFollowing">{lang}chat.global.invite.noFollowing{/lang}</p> <p class="info">{lang}chat.global.invite.noFollowing{/lang}</p>
{/if} {else}
<div id="userInviteDialogFollowingList">
<dl>
{foreach from=$users item="user"}
<dt></dt>
<dd><label><input type="checkbox" id="userInviteDialogUserID-{$user.userID}" value="{$user.userID}" /> {$user.username}</label></dd>
{/foreach}
</dl>
</div>
{/if}
</fieldset>
<div id="userInviteDialogUserlist"> <fieldset>
<dl> <legend>{lang}chat.user.search{/lang}</legend>
{foreach from=$users item=$user}
<dt></dt> <div id="userInviteDialogUserList"></div>
<dd><label><input type="checkbox" id="userInviteDialogUserID-{$user->userID}" data-user-id="{$user->userID}" /> {$user->username}</label></dd>
{/foreach} <dl class="marginTop">
<dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
<dd>
<span>
<input autocomplete="off" id="userInviteDialogUsernameInput" name="username" class="medium" value="" type="text" />
</span>
</dd>
</dl> </dl>
</div>
<div class="formSubmit"> <div class="formSubmit">
<input id="userInviteDialogFormSubmit" type="submit" value="{lang}wcf.global.button.submit{/lang}" /> <input id="userInviteDialogFormSubmit" type="submit" value="{lang}wcf.global.button.submit{/lang}" />
</div> </div>
</fieldset> </fieldset>
</div>
<fieldset> {/literal}
<legend>{lang}chat.user.search{/lang}</legend>
<dl>
<dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
<dd>
<span>
<input autocomplete="off" id="userInviteDialogUsernameInput" name="username" class="medium" value="" type="text" />
</span>
</dd>
</dl>
</fieldset>
</div>
<script>
(function() {
new WCF.Search.User('#userInviteDialogUsernameInput', function(user) {
if (!$.wcfIsset('userInviteDialogUserID-' + user.objectID)) {
$('.noFollowing').hide();
$('#userInviteDialogUserlist').append('<dl>\
<dt></dt>\
<dd>\
<label>\
<input type="checkbox" id="userInviteDialogUserID-' + user.objectID + '" data-user-id="' + user.objectID + '" checked="checked" /> ' + user.label + '\
</label>\
</dd>\
</dl>');
}
else {
$('#userInviteDialogUserID-' + user.objectID).prop('checked', true);
}
$('#userInviteDialogUsernameInput').val('');
}, false, ['{$__wcf->getUser()->username|encodeJS}'], false);
$('#userInviteDialogFormSubmit').on('click', function(event) {
var checked = $('#userInviteDialogUserlist input[type=checkbox]:checked');
var userList = [];
checked.each(function(k, v) {
userList.push($(v).data('userID'));
});
if (userList.length) {
new WCF.Action.Proxy({
autoSend: true,
data: {
actionName: 'invite',
className: 'chat\\data\\user\\UserAction',
parameters: {
recipients: userList
}
},
success: function (data) {
new WCF.System.Notification('{lang}wcf.global.success{/lang}').show();
}
});
}
$('#timsChatInviteDialog').wcfDialog('close');
});
})();
</script>