<?php
/**
 * The calendar view of common module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      chujilu <chujilu@cnezsoft.com>
 * @package     common
 * @version     $Id: calendar.html.php 2508 2015-01-26 08:32:52Z chujilu $
 * @link        http://www.zdoo.com
 */
if($extView = $this->getExtViewFile(__FILE__)){include $extView; return helper::cd();}
$clientLang = $this->app->getClientLang();
$jsRoot     = $config->webRoot . "js/";
css::import($jsRoot . 'calendar/zui.calendar.min.css');
js::import($jsRoot  . 'calendar/zui.calendar.min.js');
?>
<style>
.calendar .calender-header {margin-bottom: 5px!important;}
.calendar .event {transition-property: background-color, opacity, visibility}
.calendar .event,
.calendar .event.drag-shadow {background: #2272eb!important; line-height: 20px!important; padding-left: 0!important;}
.calendar .event.finish,
.calendar .event.finish.drag-shadow {background: #12b550!important;}
.calendar .event.contact {background: #56c6ed!important;cursor: default;}
.calendar .event.contact:hover {background: #56c6ed!important;cursor: default;}
.calendar .event.contact.drag-from {background: #56c6ed!important;cursor: not-allowed;}
.calendar .event.contact.dragging {background: #56c6ed!important;cursor: not-allowed;}
.calendar .event > .title {font-size: 13px; display: block; overflow: hidden; white-space: nowrap; height: 20px; padding-left: 5px;}
.calendar .event > .title,
.calendar .event > .event-btn,
.calendar .event.has-time > .time {color: #fff!important; transition: visibility .1s, opacity .1s;}
.calendar .event.has-time.can-finish:hover > .time {visibility: hidden; opacity: 0;}
.calendar .event.can-finish > .event-btn {position: absolute; top: 0; right: 0; padding: 0 3px; cursor: pointer; visibility: hidden; opacity: 0; font-size: 13px; transition: visibility .1s, opacity .1s; background: rgba(0,0,0,.1);}
.calendar .event.can-finish:hover > .event-btn {opacity: 1; visibility: visible;}
.calendar .event > .event-btn:hover {background: rgba(0,0,0,.2);}
.calendar .event.wait:hover,
.calendar .event.has-time {padding-right: 35px!important;}
.calendar .event.with-action {position: relative; padding-right: 30px;}
.calendar .event.with-action .action {position: absolute; right: 0; top: 0;}
.calendar .event.with-action .action > a {display: inline-block; padding: 0 4px; color: #fff; background-color: rgba(0,0,0,0.25); line-height: 19px; padding: 0 6px;}
.calendar .event.with-action .action > a:hover {background-color: rgba(0,0,0,0.5)}
.calendar .day > .content {margin-left: -1px;}
.calendar .table .cell-day.past > .day > .content{opacity: 1;}
.calendar .table .day{opacity: 1;}
.calendar .cell-day.past .event{opacity: 1;}
.calendar .table>thead>tr>th {border: 2px solid #eee!important; padding: 0 5px!important;}
.calendar .table-fixed-header:before {content: ' '; display: block; position: absolute; left: 10px; right: 10px; bottom: 0; border-bottom: 1px solid #ddd;}
.calendar .event.drag-shadow {z-index: 1010;}
.calendar .calender-header .btn {line-height: 20px; padding: 1px 8px; margin-top: 0;}
.calendar .calender-header .btn-group {margin-top: 0;}
.calendar .calender-header .btn-group > .btn {padding: 1px 2px; min-width: 24px; margin-top: 0;}
.calendar .calender-header .btn-today {font-size: 13px;}
.calendar .calender-header .btn-today.disabled {color: #fff; cursor: pointer; pointer-events: auto; opacity: 1; -webkit-filter: none; filter: none;}
.calendar .weekends-empty .table > tbody > tr > td.weekend-day,
.calendar .weekends-empty .table > thead > tr > th.weekend-head {width: 80px; min-width: 80px;}
.calendar .label-rest { margin-top: 2px; display: inline-block; width: auto; height: 16px; line-height: 16px; border-radius: 8px; color: #60ae08; font-size: 13px ; text-align: center;}
.calendar .day > .heading {height: 24px}
.calendar .day > .heading > .month {float: left; margin: 3px 5px 0 0}
.calendar .day > .heading > .number {min-width: 14px; display: inline-block; float: left; text-align: left}
.calendar .day.trash {position: relative;}
.calendar {min-height: 300px; margin: 0;}
.calendar .cell-day.with-plus-sign .day>.heading:before {position: relative; top: -1px; left: auto;}
.calendar .calender-header .calendar-caption {line-height: 24px; font-size: 14px;}
.calendar .event.expired > .time {color: #fff}
</style>
<script>
$(function()
{
    $('.calendar').each(function()
    {
        var $calendarObj = $(this);
        var settings     = $.extend(
        {
            hideFirstDayNumber: true
        }, v.settings);

        /* Get setting from div. */
        var divData = $calendarObj.data();
        for(key in divData) settings[key] = divData[key];

        /* Get data from table. */
        var calendars = [];
        $calendarObj.find(".calendar-data .calendar-calendar").each(function()
        {
            var rowObj = $(this);
            var calendar = [];
            if(rowObj.find('.name').length)  calendar['name']  = rowObj.find('.name').text();
            if(rowObj.find('.title').length) calendar['title'] = rowObj.find('.title').text();
            if(rowObj.find('.desc').length)  calendar['desc']  = rowObj.find('.desc').text();
            if(rowObj.find('.color').length) calendar['color'] = rowObj.find('.color').text();
            calendars.push(calendar);
        });
        var events = [];
        $calendarObj.find(".calendar-data .calendar-row").each(function()
        {
            var $rowObj = $(this);
            var event = {};
            event['data'] = rowObj.data();
            $.each(['title', 'desc', 'allDay', 'start', 'end', 'calendar', 'click'], function(idx, colName)
            {
                var $cell = rowObj.find('.' + colName);
                if($cell.length) event[colName] = $cell[colName === 'click' ? 'data' : 'text']();
            });
            events.push(event);
        });
        if($calendarObj.find(".calendar-data").length) settings.data = {'calendars':calendars, 'events':events};
        $calendarObj.find(".calendar-data").remove();

        /* Add default click event. */
        settings.clickEvent = function(event)
        {
            if(event.event.click != undefined)
            {
                $.zui.modalTrigger.show($.extend({backdrop: 'static'},event.event.click));
            }
        }

        settings.dragThenDrop = {flex: false};

        /* init calendar. */
        $calendarObj.calendar(settings);
    });
});
</script>
