partial #2429 - window manager - auto refresh timer

This commit is contained in:
Daniel Camargo 2014-02-27 09:46:35 -03:00
parent 8227383fd1
commit 4fe20219bd
4 changed files with 93 additions and 27 deletions

View File

@ -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;

View File

@ -10,35 +10,48 @@
<div class="table-header">
<div class="row-fluid">
<div class="span1">
<div class="span2">
<br/>
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Status: <?php echo $this->status; ?> <span class="caret"></span></button>
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Status: <?php echo $this->status; ?> <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=all')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=open')">Open</a></li>
<li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=closed')">Closed</a></li>
<li><a href="#" onclick="load('/support/plus/content?autoRefresh=<?php echo $this->autoRefresh; ?>&type=<?php echo $this->type; ?>&status=all')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?autoRefresh=<?php echo $this->autoRefresh; ?>&type=<?php echo $this->type; ?>&status=open')">Open</a></li>
<li><a href="#" onclick="load('/support/plus/content?autoRefresh=<?php echo $this->autoRefresh; ?>&type=<?php echo $this->type; ?>&status=closed')">Closed</a></li>
</ul>
</div>
</div>
<div class="span1">
<div class="span2">
<br/>
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Type: <?php echo $this->type; ?> <span class="caret"></span></button>
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Type: <?php echo $this->type; ?> <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" onclick="load('/support/plus/content?status=<?php echo $this->status; ?>&type=all')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?status=<?php echo $this->status; ?>&type=support')">Support</a></li>
<li><a href="#" onclick="load('/support/plus/content?status=<?php echo $this->status; ?>&type=warning')">Warning</a></li>
<li><a href="#" onclick="load('/support/plus/content?autoRefresh=<?php echo $this->autoRefresh; ?>&status=<?php echo $this->status; ?>&type=all')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?autoRefresh=<?php echo $this->autoRefresh; ?>&status=<?php echo $this->status; ?>&type=support')">Support</a></li>
<li><a href="#" onclick="load('/support/plus/content?autoRefresh=<?php echo $this->autoRefresh; ?>&status=<?php echo $this->status; ?>&type=warning')">Warning</a></li>
</ul>
</div>
</div>
<div class="span9">
<br/>
<button onclick="load('/support/plus/content?type=<?php echo $this->type ?>&status=<?php echo $this->status ?>&page=<?php echo $this->page; ?>')" class="btn btn-default"><i class="icon-refresh"></i> Refresh</button>
<div class="span2">
<br/>
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Auto refresh: <?php echo $this->autoRefresh; ?> <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&autoRefresh=on&status=all')">On</a></li>
<li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&autoRefresh=off&status=open')">Off</a></li>
</ul>
</div>
</div>
<div class="span1" id="warning-loaded" style="display:none;">
<div class="span4">
<br/>
<span style="float:right;" class="label label-blue"><i class="icon-ok-sign"></i> Loaded</span>
<button onclick="load('/support/plus/content?autoRefresh=<?php echo $this->autoRefresh; ?>&type=<?php echo $this->type ?>&status=<?php echo $this->status ?>&page=<?php echo $this->page; ?>')" class="btn btn-default"><i class="icon-refresh"></i> Refresh</button>
</div>
<div class="span2" style="text-align:right;">
<br/>
<div style="height:25px">
<span id="warning-loaded" style="display:none;" class="label label-blue"><i class="icon-ok-sign"></i> Loaded</span>
</div>
<span id="auto-refresh-timer" style="display:none;" ><i class="icon-clock"></i> Refresh in <span id="auto-refresh-timer-counter"></span></span>
</div>
</div>
</div>
@ -181,6 +194,28 @@
$( '#warning-loaded' ).fadeIn();
setTimeout( function(){
$( '#warning-loaded' ).fadeOut();
}, 100 );
}, 700 );
}, 500 );
}, 100 );
<?php if( $this->autoRefresh == 'on' ) { ?>
var timeToWait = 30;
var autoRefresh = '<?php echo $this->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=<?php echo $this->autoRefresh; ?>&type=<?php echo $this->type ?>&status=<?php echo $this->status ?>&page=<?php echo $this->page; ?>');
}
}
};
$( '#auto-refresh-timer-counter' ).html( autoRefreshTimerCount );
$( '#auto-refresh-timer' ).show();
autoRefreshCounter();
<?php } ?>
</script>

View File

@ -82,7 +82,7 @@ $(function() {
.chat-title{
cursor: pointer;
}
.chat-cointainer{
.chat-container{
position:fixed;
height:344px;
width:250px;

View File

@ -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 '<div class="chat-cointainer" style="right:' + positionRight + 'px" id="chat-cointainer-' + id_support + '">' + content + '</div>';
return positionRight;
},
container : function( id_support, content ){
return '<div class="chat-container" style="right:' + SupportChats.nextPosition() + 'px" id="chat-container-' + id_support + '">' + content + '</div>';
},
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( {