Change Driver Week #3084

changed the cockpit pages to start the schedule week on Friday
This commit is contained in:
Daniel Camargo 2014-05-27 13:03:04 -03:00
parent 8c07b99d93
commit 5b48b9d801
9 changed files with 202 additions and 160 deletions

View File

@ -77,49 +77,44 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
$admin = Admin::o( c::admin()->id_admin );
// Start week on Friday #3084
if( c::getPagePiece( 4 ) && c::getPagePiece( 5 ) ){
$year = c::getPagePiece( 4 );
$week = c::getPagePiece( 5 );
$firstDay = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 5 ) ), new DateTimeZone( c::config()->timezone ) );
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
if( $now->format( 'l' ) == 'Friday' ){
$friday = $now;
} else {
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
if( $now->format( 'l' ) == 'Friday' ){
$friday = $now;
} else {
$friday = new DateTime( 'last friday', new DateTimeZone( c::config()->timezone ) );
}
$year = $friday->format( 'Y' );
$week = $friday->format( 'W' );
$firstDay = $friday;
$friday = new DateTime( 'last friday', new DateTimeZone( c::config()->timezone ) );
}
$year = ( c::getPagePiece( 4 ) != '' ? c::getPagePiece( 4 ) : $friday->format( 'Y' ) );
$month = ( c::getPagePiece( 5 ) != '' ? c::getPagePiece( 5 ) : $friday->format( 'm' ) );
$day = ( c::getPagePiece( 6 ) != '' ? c::getPagePiece( 6 ) : $friday->format( 'd' ) );
// Start week on friday
$firstDay = new DateTime( $year . '-' . $month . '-' . $day, new DateTimeZone( c::config()->timezone ) );
$first_day_year = $firstDay->format( 'Y' );
$first_day_week = $firstDay->format( 'W' );
$days = [];
for( $i = 0; $i <= 6; $i++ ){
$days[] = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
$firstDay->modify( '+ 1 day' );
}
if( $week <= 1 ){
$weekPrev = ( $year - 1 ) . '/52';
} else {
$weekPrev = ( $year ) . '/' . ( $week - 1 );
}
if( $week >= 52 ){
$weekNext = ( $year + 1 ) . '/01';
} else {
$weekNext = ( $year ) . '/' . ( $week + 1 );
}
// prev/next links
$firstDay->modify( '- 2 week' );
$link_prev_day = $firstDay->format( 'Y/m/d' );
$firstDay->modify( '+ 2 week' );
$link_next_day = $firstDay->format( 'Y/m/d' );
c::view()->weekPrev = $weekPrev;
c::view()->weekNext = $weekNext;
c::view()->week = $week;
c::view()->year = $year;
c::view()->status = Crunchbutton_Admin_Shift_Status::getByAdminWeekYear( $admin->id_admin, $week, $year );
c::view()->week = $first_day_week;
c::view()->year = $first_day_year;
c::view()->link_prev = $link_prev_day;
c::view()->link_next = $link_next_day;
c::view()->status = Crunchbutton_Admin_Shift_Status::getByAdminWeekYear( $admin->id_admin, $first_day_week, $first_day_year );
c::view()->days = $days;
c::view()->from = new DateTime( $days[ 0 ]->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
c::view()->to = new DateTime( $days[ 6 ]->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
c::view()->from = $days[ 0 ];
c::view()->to = $days[ 6 ];
c::view()->communities = $admin->communitiesHeDeliveriesFor();
c::view()->display( 'drivers/shift/schedule/driver' );
}
@ -171,10 +166,12 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
$friday = new DateTime( 'last friday', new DateTimeZone( c::config()->timezone ) );
}
$year = ( c::getPagePiece( 3 ) ) ? c::getPagePiece( 3 ) : $friday->format( 'Y' );
$week = ( c::getPagePiece( 4 ) ) ? c::getPagePiece( 4 ) : $friday->format( 'W' );
$firstDay = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 5 ) ), new DateTimeZone( c::config()->timezone ) );
$year = ( c::getPagePiece( 3 ) != '' ? c::getPagePiece( 3 ) : $friday->format( 'Y' ) );
$month = ( c::getPagePiece( 4 ) != '' ? c::getPagePiece( 4 ) : $friday->format( 'm' ) );
$day = ( c::getPagePiece( 5 ) != '' ? c::getPagePiece( 5 ) : $friday->format( 'd' ) );
// Start week on friday
$firstDay = new DateTime( $year . '-' . $month . '-' . $day, new DateTimeZone( c::config()->timezone ) );
$days = [];
for( $i = 0; $i <= 6; $i++ ){
@ -182,23 +179,19 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
$firstDay->modify( '+ 1 day' );
}
// prev/next links
$firstDay->modify( '- 2 week' );
$link_prev_day = $firstDay->format( 'Y/m/d' );
$firstDay->modify( '+ 2 week' );
$link_next_day = $firstDay->format( 'Y/m/d' );
$firstDay->modify( '-1 day' );
c::view()->to = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
$firstDay->modify( '-6 day' );
c::view()->from = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
if( $week <= 1 ){
$weekPrev = ( $year - 1 ) . '/52';
} else {
$weekPrev = ( $year ) . '/' . ( $week - 1 );
}
if( $week >= 52 ){
$weekNext = ( $year + 1 ) . '/01';
} else {
$weekNext = ( $year ) . '/' . ( $week + 1 );
}
c::view()->weekPrev = $weekPrev;
c::view()->weekNext = $weekNext;
c::view()->link_prev = $link_prev_day;
c::view()->link_next = $link_next_day;
c::view()->days = $days;
c::view()->week = $week;
c::view()->year = $year;
@ -220,15 +213,22 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
$id_community = c::getPagePiece( 3 );
$year = ( c::getPagePiece( 4 ) != '' ? c::getPagePiece( 4 ) : false );
$week = ( c::getPagePiece( 5 ) != '' ? c::getPagePiece( 5 ) : false );
$month = ( c::getPagePiece( 5 ) != '' ? c::getPagePiece( 5 ) : false );
$day = ( c::getPagePiece( 6 ) != '' ? c::getPagePiece( 6 ) : false );
if( $id_community && $year && $week ){
if( intval( $week ) < 10 ){
$week = '0' . intval( $week );
}
if( $id_community && $year && $month && $day ){
// Start week on friday
$firstDay = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 5 ) ), new DateTimeZone( c::config()->timezone ) );
$firstDay = new DateTime( $year . '-' . $month . '-' . $day, new DateTimeZone( c::config()->timezone ) );
// prev/next links
$link_start_day = $firstDay->format( 'Y/m/d' );
$firstDay->modify( '- 1 week' );
$link_prev_day = $firstDay->format( 'Y/m/d' );
$firstDay->modify( '+ 2 week' );
$link_next_day = $firstDay->format( 'Y/m/d' );
$firstDay->modify( '- 1 week' );
$days = [];
for( $i = 0; $i <= 6; $i++ ){
@ -236,24 +236,16 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
$firstDay->modify( '+ 1 day' );
}
if( $week <= 1 ){
$weekPrev = ( $year - 1 ) . '/52';
} else {
$weekPrev = ( $year ) . '/' . ( $week - 1 );
}
if( $week >= 52 ){
$weekNext = ( $year + 1 ) . '/01';
} else {
$weekNext = ( $year ) . '/' . ( $week + 1 );
}
c::view()->weekPrev = $weekPrev;
c::view()->weekNext = $weekNext;
c::view()->start_date = $start_date;
c::view()->link_prev = $link_prev_day;
c::view()->link_next = $link_next_day;
c::view()->days = $days;
$firstDay->modify( '-1 day' );
c::view()->to = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
$firstDay->modify( '-6 day' );
c::view()->from = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
c::view()->id_community = $id_community;
} else {
@ -264,14 +256,12 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
} else {
$friday = new DateTime( 'last friday', new DateTimeZone( c::config()->timezone ) );
}
$year = $friday->format( 'Y' );
$week = $friday->format( 'W' );
$start_date = $friday->format( 'Y/m/d' );
$day = $friday;
}
c::view()->week = $week;
c::view()->year = $year;
c::view()->start_date = $start_date;
if( $_REQUEST[ 'ajax' ] ){
c::view()->ajax = true;
c::view()->layout( 'layout/ajax' );
@ -284,39 +274,37 @@ class Controller_drivers_shift extends Crunchbutton_Controller_Account {
// Start week on Friday #3084
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
if( $now->format( 'l' ) == 'Friday' ){
$day = $now;
$friday = $now;
} else {
$day = new DateTime( 'last friday', new DateTimeZone( c::config()->timezone ) );
$friday = new DateTime( 'last friday', new DateTimeZone( c::config()->timezone ) );
}
$year = ( c::getPagePiece( 4 ) ) ? c::getPagePiece( 4 ) : $day->format( 'Y' );
$week = ( c::getPagePiece( 5 ) ) ? c::getPagePiece( 5 ) : $day->format( 'W' );
$year = ( c::getPagePiece( 4 ) != '' ? c::getPagePiece( 4 ) : $friday->format( 'Y' ) );
$month = ( c::getPagePiece( 5 ) != '' ? c::getPagePiece( 5 ) : $friday->format( 'm' ) );
$day = ( c::getPagePiece( 6 ) != '' ? c::getPagePiece( 6 ) : $friday->format( 'd' ) );
$day = new DateTime( date( 'Y-m-d', strtotime( $year . 'W' . $week . 5 ) ), new DateTimeZone( c::config()->timezone ) );
$from = new DateTime( $day->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
$day->modify( '+6 day' );
$to = new DateTime( $day->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
// Start week on friday
$firstDay = new DateTime( $year . '-' . $month . '-' . $day, new DateTimeZone( c::config()->timezone ) );
c::view()->week = $firstDay->format( 'W' );
c::view()->year = $firstDay->format( 'Y' );
$from = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
$firstDay->modify( '+6 day' );
$to = new DateTime( $firstDay->format( 'Y-m-d' ), new DateTimeZone( c::config()->timezone ) );
$firstDay->modify( '- 6 days' );
$communities = Crunchbutton_Community_Shift::communitiesWithDeliveryService();
if( $week <= 1 ){
$weekPrev = ( $year - 1 ) . '/52';
} else {
$weekPrev = ( $year ) . '/' . ( $week - 1 );
}
if( $week >= 52 ){
$weekNext = ( $year + 1 ) . '/01';
} else {
$weekNext = ( $year ) . '/' . ( $week + 1 );
}
// prev/next links
$firstDay->modify( '- 1 week' );
$link_prev_day = $firstDay->format( 'Y/m/d' );
$firstDay->modify( '+ 2 week' );
$link_next_day = $firstDay->format( 'Y/m/d' );
c::view()->weekPrev = $weekPrev;
c::view()->weekNext = $weekNext;
c::view()->year = $year;
c::view()->week = $week;
c::view()->link_prev = $link_prev_day;
c::view()->link_next = $link_next_day;
c::view()->to = $to;
c::view()->from = $from;
c::view()->communities = $communities;

View File

@ -1,6 +1,7 @@
<?php
class Crunchbutton_Community_Shift extends Cana_Table {
public function __construct($id = null) {
parent::__construct();
$this

View File

@ -171,11 +171,10 @@ $( document ).ready( function(){
} else {
$friday = new DateTime( 'last friday', new DateTimeZone( c::config()->timezone ) );
}
$year = $friday->format( 'Y' );
$week = $friday->format( 'W' );
$start_date = $friday->format( 'Y/m/d' );
?>
community.shifts( '/drivers/shift/community/<?php echo $community[ 'community' ]->id_community; ?>/<?php echo $year; ?>/<?php echo $week; ?>?ajax=1' );
community.shifts( '/drivers/shift/community/<?php echo $community[ 'community' ]->id_community; ?>/<?php echo $start_date; ?>?ajax=1' );
<?php } ?>
} );

View File

@ -41,37 +41,43 @@
<?php if( !$ajax ) { ?>
<div class="box">
<div class="box-header">
<div class="row-fluid">
<div class="span12 padded" style="text-align:center;">
<strong>Shifts for week <?php echo $this->week; ?> / <?php echo $this->year; ?></strong>
<div class="row-fluid">
<div class="span2 padded">
<br/>
<a class="shift-previous" href="/drivers/shift/community/<?php echo $id_community ?>/<?php echo $this->link_prev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a>
</div>
<div class="span8 padded" style="text-align:center;">
<h5>
From <?php echo $this->from->format('M jS Y') ?> to <?php echo $this->to->format('M jS Y'); ?>
</h5>
</div>
<div class="span2 padded" style="text-align:right;">
<br/>
<a class="shift-next" href="/drivers/shift/community/<?php echo $id_community ?>/<?php echo $this->link_next; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="box-content">
<div>
<div class="row-fluid">
<div class="span2 padded">
<br/>
<a class="shift-previous" href="/drivers/shift/community/<?php echo $id_community ?>/<?php echo $this->weekPrev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a>
</div>
<div class="span8 padded" style="text-align:center;">
<h4>
From <?php echo $this->from->format('M jS Y') ?> to <?php echo $this->to->format('M jS Y'); ?>
</h4>
</div>
<div class="span2 padded" style="text-align:right;">
<br/>
<a class="shift-next" href="/drivers/shift/community/<?php echo $id_community ?>/<?php echo $this->weekNext; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a>
</div>
<?php if( $ajax ) { ?>
<div class="box">
<div class="box-header">
<div class="row-fluid">
<div style="text-align:center;">
<h5>
From <?php echo $this->from->format('M jS Y') ?> to <?php echo $this->to->format('M jS Y'); ?>
</h5>
</div>
</div>
<hr/>
</div>
<?php } ?>
<table width="100%">
<tr>
<?php foreach( $this->days as $day ) {
$dark = ( $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
$dark = ( $dark == '#F5F5F5' ) ? '' : '#F5F5F5';
?>
<th width="14%" style="background:<?php echo $dark; ?>">
<div class="row-fluid padded">
@ -85,9 +91,10 @@
</th>
<?php } ?>
</tr>
<?php $dark = ''; ?>
<tr>
<?php foreach( $this->days as $day ) {
$dark = ( $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
$dark = ( $dark == '#F5F5F5' ) ? '' : '#F5F5F5';
$segments = Crunchbutton_Community_Shift::shiftByCommunityDay( $id_community, $day->format( 'Y-m-d' ) );
?>
<td width="14%" style="background:<?php echo $dark; ?>" valign="top">
@ -157,8 +164,7 @@
<script type="text/javascript" src="/assets/js/admin.shift.js"></script>
<script type="text/javascript">
$( document ).ready( function(){
shift.community.year = '<?php echo $this->year; ?>';
shift.community.week = '<?php echo $this->week; ?>';
shift.community.start_date = '<?php echo $this->start_date; ?>';
<?php if( $ajax ) { ?>
shift.community.ajax = true;
shift.community.url = '/drivers/shift/community/<?php echo $id_community ?>/<?php echo $this->year; ?>/<?php echo $this->week; ?>?ajax=1';

View File

@ -8,8 +8,10 @@
$id_admin = c::admin()->id_admin;
$totalShifts = 0;
$current = date( 'YW', strtotime( '- 1 day' ) );
$editable = ( intval( $this->year . $this->week ) >= $current );
$current = date( 'Ymd' );
$first_day = $this->days[0]->format( 'Ymd' );
$last_day = $this->days[6]->format( 'Ymd' );
$editable = ( $last_day >= $current );
?>
<div class="container-fluid padded">
<div class="row-fluid">
@ -21,8 +23,8 @@
<div class="row-fluid">
<div class="span2 padded">
<br/><br/>
<?php if( intval( str_replace( '/' , '', $this->weekPrev ) ) >= $current ) { ?>
<a class="shift-previous" href="/drivers/shift/schedule/driver/<?php echo $this->weekPrev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a>
<?php if( $first_day > $current ) { ?>
<a class="shift-previous" href="/drivers/shift/schedule/driver/<?php echo $this->link_prev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a>
<?php } ?>
</div>
<div class="span8 padded" style="text-align:center;">
@ -32,7 +34,7 @@
</div>
<div class="span2 padded" style="text-align:right;">
<br/><br/>
<a class="shift-next" href="/drivers/shift/schedule/driver/<?php echo $this->weekNext; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a>
<a class="shift-next" href="/drivers/shift/schedule/driver/<?php echo $this->link_next; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a>
</div>
</div>
@ -182,7 +184,7 @@
</div>
<?php } ?>
<div class="row-fluid padded">
<a href="http://cbtn.io/shifts-list/mine"><i class="icon icon-angle-right">View your next shifts at <b>http://cbtn.io/</b></i></a>
<a href="http://cbtn.io/shifts-list/mine"><i class="icon icon-angle-right"> View your next shifts at <b>http://cbtn.io/</b></i></a>
</div>
<div class="divider"></div>
</div>

View File

@ -14,7 +14,6 @@
$hasDrivers = [];
?>
<div class="container-fluid padded">
<div class="row-fluid">
<div class="box">
@ -22,8 +21,8 @@
<span class="title">Shift status: <?php echo 'from ' . $from->format( 'M jS Y ' ) . ' to ' . $to->format( 'M jS Y ' ); ?></span>
<ul class="box-toolbar">
<li><a class="shift-previous" href="/drivers/shift/status/shift/<?php echo $this->weekPrev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a></li>
<li><a class="shift-next" href="/drivers/shift/status/shift/<?php echo $this->weekNext; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a></li>
<li><a class="shift-previous" href="/drivers/shift/status/shift/<?php echo $this->link_prev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a></li>
<li><a class="shift-next" href="/drivers/shift/status/shift/<?php echo $this->link_next; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a></li>
</ul>
</div> <div class="box-content">

View File

@ -5,7 +5,6 @@
$this->title2 = 'Summary';
$this->title2icon = 'time';
$this->titleLink = '/drivers/shift/summary/';
?>
<div class="container-fluid padded">
<div class="row-fluid">
@ -15,7 +14,7 @@
<div class="row-fluid">
<div class="span2 padded">
<br/>
<a class="shift-previous" href="/drivers/shift/summary/<?php echo $this->weekPrev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a>
<a class="shift-previous" href="/drivers/shift/summary/<?php echo $this->link_prev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a>
</div>
<div class="span8 padded" style="text-align:center;">
<h5>
@ -24,7 +23,7 @@
</div>
<div class="span2 padded" style="text-align:right;">
<br/>
<a class="shift-next" href="/drivers/shift/summary/<?php echo $this->weekNext; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a>
<a class="shift-next" href="/drivers/shift/summary/<?php echo $this->link_next; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a>
</div>
</div>
</div>
@ -34,7 +33,7 @@
<table width="100%">
<tr>
<?php foreach( $this->days as $day ) {
$dark = ( $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
$dark = ( $dark == '#F5F5F5' ) ? '' : '#F5F5F5';
?>
<th width="14%" style="background:<?php echo $dark; ?>">
<div class="row-fluid padded">
@ -48,9 +47,10 @@
</th>
<?php } ?>
</tr>
<?php $dark = ''; ?>
<tr>
<?php foreach( $this->days as $day ) {
$dark = ( $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
$dark = ( $dark == '#F5F5F5' ) ? '' : '#F5F5F5';
$segments = Crunchbutton_Community_Shift::shiftsByDay( $day->format( 'Y-m-d' ) );
?>
<td width="14%" style="background:<?php echo $dark; ?>" valign="top">

View File

@ -308,11 +308,11 @@ function _newNotificationFields() {
*
*/
function loadSavedData() {
/* special logic for the order notification methods cuz they were weird when i found them */
/* special logic for the order notification methods cuz they were weird when i found them */
var types = ['sms', 'email', 'phone', 'url', 'fax'];
for(var i in types) { $('div.check-content.'+types[i]).html(''); }
delete App.cached.Restaurant[App.restaurant];
delete App.cached.Restaurant[App.restaurant];
App.loadRestaurant();
}
@ -1849,21 +1849,21 @@ function create_support_from_order(id_order) {
function full_post(url, data){
$('body').append($('<form/>', {
id: 'jQueryPostItForm',
method: 'POST',
action: url
}));
$('body').append($('<form/>', {
id: 'jQueryPostItForm',
method: 'POST',
action: url
}));
for(var i in data){
$('#jQueryPostItForm').append($('<input/>', {
type: 'hidden',
name: i,
value: data[i]
}));
}
for(var i in data){
$('#jQueryPostItForm').append($('<input/>', {
type: 'hidden',
name: i,
value: data[i]
}));
}
$('#jQueryPostItForm').submit();
$('#jQueryPostItForm').submit();
}
App.giftcardsGroup = {
@ -2036,7 +2036,7 @@ hour_override.save = function(){
}
if( !/^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test( date_start_hour ) ){
alert( 'Please type a valid start hour! \nFormat hh:mm!' );
alert( 'Please type a valid start hour! \nFormat hh:mm!' );
$( '#hour_override_date_start_hour' ).focus();
return;
}
@ -2048,7 +2048,7 @@ hour_override.save = function(){
}
if( !/^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test( date_end_hour ) ){
alert( 'Please type a valid end hour! \nFormat hh:mm!' );
alert( 'Please type a valid end hour! \nFormat hh:mm!' );
$( '#hour_override_date_end_hour' ).focus();
return;
}
@ -2172,4 +2172,15 @@ App.phone = {
return false;
}
};
function compareArrays(a, b) {
var i = a.length;
if (i != b.length) return false;
while (i--) {
if (a[i] !== b[i]) return false;
}
return true;
};

View File

@ -8,7 +8,7 @@ shift.community.init = function(){
$( '#community-id' ).change( function( event ) {
if( $.trim( $( '#community-id' ).val() ) != '' ){
document.location.href = '/drivers/shift/community/' + $( '#community-id' ).val() + '/' + shift.community.year + '/' + shift.community.week;
document.location.href = '/drivers/shift/community/' + $( '#community-id' ).val() + '/' + shift.community.start_date;
}
} );
@ -51,7 +51,6 @@ shift.community.toggleTimezone = function(){
};
shift.community.reload = function(){
console.log('shift.community.ajax',shift.community.ajax);
if( shift.community.ajax ){
$( '#modal-hours' ).modal( 'hide' );
community.shifts( shift.community.url );
@ -221,7 +220,7 @@ shift.drivers.init = function(){
$( '.complete-shift-driver' ).click( function() {
shift.drivers.update( true );
} );
$( '.available, .wantwork, .dontwantwork' ).sortable( {
'connectWith': '.connected',
'forcePlaceholderSize': true,
@ -233,6 +232,41 @@ shift.drivers.init = function(){
shift.drivers.update();
}, 500 );
} );
// sometimes the sortupdate event is not fired!
shift.drivers.last_list = { wantWorkItems: [], dontWantWorkItems: [] };
$('ul.wantwork li').each( function() {
shift.drivers.last_list.wantWorkItems.push( $( this ).attr( 'id' ) );
} );
$('ul.dontwantwork li').each( function() {
shift.drivers.last_list.dontWantWorkItems.push( $( this ).attr( 'id' ) );
} );
shift.drivers.watchChanges();
}
shift.drivers.watchChanges = function(){
var wantWorkItems = [];
var dontWantWorkItems = []
$('ul.wantwork li').each( function() {
wantWorkItems.push( $( this ).attr( 'id' ) );
} );
$('ul.dontwantwork li').each( function() {
dontWantWorkItems.push( $( this ).attr( 'id' ) );
} );
if( !compareArrays( wantWorkItems, shift.drivers.last_list.wantWorkItems ) || !compareArrays( dontWantWorkItems, shift.drivers.last_list.dontWantWorkItems ) ){
shift.drivers.update();
}
setTimeout( function(){
shift.drivers.watchChanges()
}, 1000 );
}
shift.drivers.order = function(){
@ -285,6 +319,9 @@ shift.drivers.update = function( completed ){
allItems.push( $( this ).attr( 'id' ) );
} );
shift.drivers.last_list = { 'wantWorkItems' : wantWorkItems, 'dontWantWorkItems' : dontWantWorkItems };
var year = shift.drivers.year;
var week = shift.drivers.week;
@ -387,7 +424,6 @@ shift.status.init = function(){
$( '#saved-' + id_admin ).fadeTo( 'fast' , 1, function() {
$( '#saved-' + id_admin ).fadeTo( 'fast', 0 );
} );
console.log( 'saved!' );
} else {
alert( 'Oops, error! ' + data.error );
}