From 55d634d78e0331e9b96c9b1a46c5369d812759db Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 12 Dec 2014 23:15:58 +0100 Subject: [PATCH] Make use of WCF.Template (JavaScript) --- file/js/be.bastelstu.Chat.litcoffee | 56 ++++++++++- file/lib/data/user/UserAction.class.php | 12 ++- template/chat.tpl | 4 +- template/userInviteDialog.tpl | 119 +++++++----------------- 4 files changed, 98 insertions(+), 93 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index 27368ab..a5468c7 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -84,7 +84,7 @@ exposed by a function if necessary. Initialize **Tims Chat**. Bind needed DOM events and initialize data structures. initialized = false - init = (roomID, config, titleTemplate, messageTemplate, userTemplate, userMenuTemplate) -> + init = (roomID, config, titleTemplate, messageTemplate, userTemplate, userMenuTemplate, userInviteDialogTemplate) -> return false if initialized initialized = true @@ -95,6 +95,17 @@ Initialize **Tims Chat**. Bind needed DOM events and initialize data structures. v.messageTemplate = messageTemplate v.userTemplate = userTemplate v.userMenuTemplate = userMenuTemplate + v.userInviteDialogTemplate = userInviteDialogTemplate + v.userInviteDialogUserListEntryTemplate = new WCF.Template """ +
+
+
+ +
+
+ """ 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 nextSpace = toComplete.indexOf ' ' if nextSpace is -1 - afterComplete = ''; + afterComplete = '' else afterComplete = toComplete.substring nextSpace + 1 toComplete = toComplete.substring 0, nextSpace @@ -361,12 +372,47 @@ Show invite dialog. data: actionName: 'prepareInvite' className: 'chat\\data\\user\\UserAction' - showLoadingOverlay: true - suppressErrors: false success: (data) -> $('
').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' diff --git a/file/lib/data/user/UserAction.class.php b/file/lib/data/user/UserAction.class.php index 7153c1d..ad7b847 100644 --- a/file/lib/data/user/UserAction.class.php +++ b/file/lib/data/user/UserAction.class.php @@ -33,12 +33,16 @@ public function prepareInvite() { $followingList->readObjects(); $users = $followingList->getObjects(); - WCF::getTPL()->assign(array( - 'users' => $users - )); + $json = array(); + foreach ($users as $user) { + $json[] = array( + 'userID' => $user->userID, + 'username' => $user->username + ); + } return array( - 'template' => WCF::getTPL()->fetch('userInviteDialog', 'chat') + 'users' => $json ); } diff --git a/template/chat.tpl b/template/chat.tpl index d87d259..0d8e9c9 100644 --- a/template/chat.tpl +++ b/template/chat.tpl @@ -52,6 +52,7 @@ {capture assign='messageTemplate'}{include application='chat' file='message'}{/capture} {capture assign='userTemplate'}{include application='chat' file='userListUser'}{/capture} {capture assign='userMenuTemplate'}{include application='chat' file='userListUserMenu'}{/capture} + {capture assign='userInviteDialogTemplate'}{include application='chat' file='userInviteDialog'}{/capture} var config = { 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('{@$messageTemplate|encodeJS}'), new WCF.Template('{@$userTemplate|encodeJS}'), - new WCF.Template('{@$userMenuTemplate|encodeJS}') + new WCF.Template('{@$userMenuTemplate|encodeJS}'), + new WCF.Template('{@$userInviteDialogTemplate|encodeJS}') ); {event name='afterInit'} diff --git a/template/userInviteDialog.tpl b/template/userInviteDialog.tpl index 4e7e9d3..e373984 100644 --- a/template/userInviteDialog.tpl +++ b/template/userInviteDialog.tpl @@ -1,86 +1,39 @@ -
-
- {lang}wcf.user.access.following{/lang} +{literal} +
+
+ {lang}wcf.user.access.following{/lang} + + {if $users.length === 0} +

{lang}chat.global.invite.noFollowing{/lang}

+ {else} +
+
+ {foreach from=$users item="user"} +
+
+ {/foreach} +
+
+ {/if} +
- {if $users|count === 0} -

{lang}chat.global.invite.noFollowing{/lang}

- {/if} - -
-
- {foreach from=$users item=$user} -
-
- {/foreach} +
+ {lang}chat.user.search{/lang} + +
+ +
+
+
+ + + +
-
- -
- -
-
- -
- {lang}chat.user.search{/lang} - -
-
-
- - - -
-
-
-
- - \ No newline at end of file +
+ +
+ + +{/literal} \ No newline at end of file