diff --git a/include/controllers/default/cockpit/support/plus/content.php b/include/controllers/default/cockpit/support/plus/content.php index 561264ffe..bd8dfc610 100644 --- a/include/controllers/default/cockpit/support/plus/content.php +++ b/include/controllers/default/cockpit/support/plus/content.php @@ -13,8 +13,9 @@ class Controller_Support_Plus_Content extends Crunchbutton_Controller_Account { $page = ( $_REQUEST[ 'page' ] ) ? $_REQUEST[ 'page' ] : 1; $status = ( $_REQUEST[ 'status' ] ) ? $_REQUEST[ 'status' ] : 'all'; $type = ( $_REQUEST[ 'type' ] ) ? $_REQUEST[ 'type' ] : 'all'; + $autoRefresh = ( $_REQUEST[ 'autoRefresh' ] ) ? $_REQUEST[ 'autoRefresh' ] : 'on'; - $paginationLink = '/support/plus/content?'; + $paginationLink = '/support/plus/content?autoRefresh=' . $autoRefresh; $limit = ( $page == 1 ? 0 : ( ( ( $page - 1 ) * $resultsPerPage ) + 1 ) ) . ',' . $resultsPerPage; @@ -57,6 +58,7 @@ class Controller_Support_Plus_Content extends Crunchbutton_Controller_Account { c::view()->total = $total; c::view()->type = $type; c::view()->page = $page; + c::view()->autoRefresh = $autoRefresh; c::view()->status = ( $status == '' ) ? 'all' : $status; c::view()->startingAt = $startingAt; c::view()->endingAt = $endingAt; diff --git a/include/views/default/cockpit/support/plus/content.phtml b/include/views/default/cockpit/support/plus/content.phtml index 17aaf0bbc..1b746e8b8 100644 --- a/include/views/default/cockpit/support/plus/content.phtml +++ b/include/views/default/cockpit/support/plus/content.phtml @@ -10,35 +10,48 @@
-
+

- +
-
+

- +
-
-
- +
+
+
+ + +
-
@@ -181,6 +194,28 @@ $( '#warning-loaded' ).fadeIn(); setTimeout( function(){ $( '#warning-loaded' ).fadeOut(); - }, 100 ); - }, 700 ); + }, 500 ); + }, 100 ); + autoRefresh == 'on' ) { ?> + var timeToWait = 30; + var autoRefresh = 'autoRefresh; ?>'; + var autoRefreshTimerCount = timeToWait; + var autoRefreshTimer = null; + function autoRefreshCounter(){ + $( '#auto-refresh-timer-counter' ).html( autoRefreshTimerCount ); + autoRefreshTimerCount--; + autoRefreshTimer = setTimeout( function(){ + clearTimeout( autoRefreshTimer ); + autoRefreshCounter(); + }, 1000 ); + if( autoRefreshTimerCount == 0 ){ + if( autoRefresh == 'on' ){ + load('/support/plus/content?autoRefresh=autoRefresh; ?>&type=type ?>&status=status ?>&page=page; ?>'); + } + } + }; + $( '#auto-refresh-timer-counter' ).html( autoRefreshTimerCount ); + $( '#auto-refresh-timer' ).show(); + autoRefreshCounter(); + \ No newline at end of file diff --git a/include/views/default/cockpit/support/plus/index.phtml b/include/views/default/cockpit/support/plus/index.phtml index bc5dba0ca..404dd6e1e 100644 --- a/include/views/default/cockpit/support/plus/index.phtml +++ b/include/views/default/cockpit/support/plus/index.phtml @@ -82,7 +82,7 @@ $(function() { .chat-title{ cursor: pointer; } - .chat-cointainer{ + .chat-container{ position:fixed; height:344px; width:250px; diff --git a/www/assets/js/admin.support.js b/www/assets/js/admin.support.js index 707ba03c6..3da483c3d 100644 --- a/www/assets/js/admin.support.js +++ b/www/assets/js/admin.support.js @@ -52,14 +52,11 @@ var SupportChatInterface = { }, container : function(){ var self = this; - return $( '#chat-cointainer-' + self.id_support ); + return $( '#chat-container-' + self.id_support ); }, close : function(){ var self = this; - var container = self.container(); - container.html( '' ); - container.remove(); - delete SupportChats.chats[ self.id_support ] + SupportChats.close( self.id_support ); self = null; }, toggle : function(){ @@ -145,14 +142,46 @@ var SupportChat = function( id_support ) { var SupportChats = { chats : {}, count : function(){ - return Object.keys( SupportChats.chats ).length; + var chats = 0; + for( x in SupportChats.chats ){ + if( SupportChats.chats[ x ] && SupportChats.chats[ x ].id_support ){ + chats++; + } + } + return chats; }, - container : function( id_support, content ){ + close : function( id_support ){ + var container = SupportChats.chats[ id_support ].container(); + container.html( '' ); + container.remove(); + delete SupportChats.chats[ id_support ]; + SupportChats.reorderWindows(); + }, + nextPosition : function(){ var totalChats = SupportChats.count(); var positionRight = 10 + parseInt( ( totalChats ) * 260 ); - return '
' + content + '
'; + return positionRight; + }, + container : function( id_support, content ){ + return '
' + content + '
'; + }, + reorderWindows : function(){ + var chats = 0; + for( x in SupportChats.chats ){ + if( SupportChats.chats[ x ] ){ + var container = SupportChats.chats[ x ].container(); + console.log('container',container); + var positionRight = 10 + parseInt( ( chats ) * 260 ); + container.css( 'right', positionRight ); + chats++; + } + } }, createChat : function( id_support ){ + if( ( SupportChats.nextPosition() + 260 ) > $( window ).width() ){ + alert( 'It seems you have too many chat windows opened, please close one before open another.' ); + return; + } if( !SupportChats.chats[ id_support ] ){ var url = '/support/plus/chat/' + id_support; $.ajax( {