2014-03-17 21:23:30 -04:00
'use strict' ;
2014-03-28 13:02:13 -04:00
/* globals define, app, translator, ajaxify, socket, bootbox */
2014-03-17 21:23:30 -04:00
define ( [ 'forum/topic/fork' , 'forum/topic/move' ] , function ( fork , move ) {
var ThreadTools = { } ;
ThreadTools . init = function ( tid , threadState ) {
2014-03-28 13:02:13 -04:00
if ( ajaxify . variables . get ( 'expose_tools' ) === '1' ) {
2014-03-17 21:23:30 -04:00
2014-03-18 16:46:07 -04:00
$ ( '.thread-tools' ) . removeClass ( 'hide' ) ;
2014-03-17 21:23:30 -04:00
2014-03-18 16:46:07 -04:00
$ ( '.delete_thread' ) . on ( 'click' , function ( e ) {
var command = threadState . deleted !== '1' ? 'delete' : 'restore' ;
2014-04-02 10:29:42 -04:00
translator . translate ( '[[topic:thread_tools.' + command + '_confirm]]' , function ( msg ) {
bootbox . confirm ( msg , function ( confirm ) {
if ( confirm ) {
2014-04-17 20:07:23 -04:00
socket . emit ( 'topics.' + command , [ tid ] ) ;
2014-04-02 10:29:42 -04:00
}
} ) ;
2014-03-18 16:46:07 -04:00
} ) ;
2014-04-02 10:29:42 -04:00
2014-03-18 16:46:07 -04:00
return false ;
2014-03-17 21:23:30 -04:00
} ) ;
2014-03-18 16:46:07 -04:00
$ ( '.lock_thread' ) . on ( 'click' , function ( e ) {
2014-04-17 20:07:23 -04:00
socket . emit ( threadState . locked !== '1' ? 'topics.lock' : 'topics.unlock' , [ tid ] ) ;
2014-03-18 16:46:07 -04:00
return false ;
} ) ;
2014-03-17 21:23:30 -04:00
2014-03-18 16:46:07 -04:00
$ ( '.pin_thread' ) . on ( 'click' , function ( e ) {
2014-04-17 20:07:23 -04:00
socket . emit ( threadState . pinned !== '1' ? 'topics.pin' : 'topics.unpin' , [ tid ] ) ;
2014-03-18 16:46:07 -04:00
return false ;
} ) ;
$ ( '.markAsUnreadForAll' ) . on ( 'click' , function ( ) {
var btn = $ ( this ) ;
2014-04-17 20:07:23 -04:00
socket . emit ( 'topics.markAsUnreadForAll' , [ tid ] , function ( err ) {
2014-03-18 16:46:07 -04:00
if ( err ) {
return app . alertError ( err . message ) ;
}
app . alertSuccess ( '[[topic:markAsUnreadForAll.success]]' ) ;
btn . parents ( '.thread-tools.open' ) . find ( '.dropdown-toggle' ) . trigger ( 'click' ) ;
} ) ;
return false ;
} ) ;
2014-04-17 20:07:23 -04:00
$ ( '.move_thread' ) . on ( 'click' , function ( e ) {
move . init ( [ tid ] , ajaxify . variables . get ( 'category_id' ) ) ;
return false ;
} ) ;
2014-03-18 16:46:07 -04:00
fork . init ( ) ;
}
socket . emit ( 'topics.followCheck' , tid , function ( err , state ) {
setFollowState ( state , false ) ;
2014-03-17 21:23:30 -04:00
} ) ;
2014-03-18 16:46:07 -04:00
$ ( '.posts' ) . on ( 'click' , '.follow' , function ( ) {
socket . emit ( 'topics.follow' , tid , function ( err , state ) {
2014-03-17 21:23:30 -04:00
if ( err ) {
2014-03-18 16:46:07 -04:00
return app . alert ( {
type : 'danger' ,
alert _id : 'topic_follow' ,
title : '[[global:please_log_in]]' ,
message : '[[topic:login_to_subscribe]]' ,
timeout : 5000
} ) ;
2014-03-17 21:23:30 -04:00
}
2014-03-18 16:46:07 -04:00
setFollowState ( state , true ) ;
2014-03-17 21:23:30 -04:00
} ) ;
2014-03-18 16:46:07 -04:00
2014-03-17 21:23:30 -04:00
return false ;
} ) ;
} ;
2014-03-18 16:46:07 -04:00
function setFollowState ( state , alert ) {
$ ( '.posts .follow' ) . toggleClass ( 'btn-success' , state ) . attr ( 'title' , state ? 'You are currently receiving updates to this topic' : 'Be notified of new replies in this topic' ) ;
if ( alert ) {
2014-04-19 12:02:33 +01:00
app . alertSuccess ( state ? '[[topic:following_topic.message]]' : '[[topic:not_following_topic.message]]' ) ;
2014-03-18 16:46:07 -04:00
}
}
2014-03-17 21:23:30 -04:00
return ThreadTools ;
2014-04-10 20:31:57 +01:00
} ) ;