/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

var core_cu = function () {


    var datepicker = function () {
        $('.datepickertoday').datepicker('setDate', '+0');
        $(".datepicker").datepicker({
            todayBtn: "linked",
            autoclose: true,
            todayHighlight: true,
            format: 'dd/mm/yy',
            isRTL: true
        });


    };


    var handleDatePickers = function () {
        if (jQuery().datepicker) {
            $('.date-picker').datepicker({rtl: Metronic.isRTL(), orientation: "left", autoclose: true});
        }
    }
    var handleTimePickers = function () {
        if (jQuery().timepicker) {
            $('.timepicker-default').timepicker({autoclose: true, showSeconds: true, minuteStep: 1});
            $('.timepicker-no-seconds').timepicker({autoclose: true, minuteStep: 5});
            $('.timepicker-24').timepicker({autoclose: true, minuteStep: 5, showSeconds: false, showMeridian: false});
            $('.timepicker').parent('.input-group').on('click', '.input-group-btn', function (e) {
                e.preventDefault();
                $(this).parent('.input-group').find('.timepicker').timepicker('showWidget');
            });
        }
    }
    /*
     var handleDateRangePickers = function () {
     if (!jQuery().daterangepicker) {
     return;
     }
     $('#defaultrange').daterangepicker({opens: (Metronic.isRTL() ? 'left' : 'right'), format: 'dd/mm/yy', separator: ' to ', startDate: moment().subtract('days', 29), endDate: moment(), minDate: '01/01/2012', maxDate: '12/31/2018', }, function (start, end) {
     $('#defaultrange input').val(start.format('MMMM D, yy') + ' - ' + end.format('MMMM D, yy'));
     });
     $('#defaultrange_modal').daterangepicker({opens: (Metronic.isRTL() ? 'left' : 'right'), format: 'dd/mm/yy', separator: ' to ', startDate: moment().subtract('days', 29), endDate: moment(), minDate: '01/01/2012', maxDate: '12/31/2018', }, function (start, end) {
     $('#defaultrange_modal input').val(start.format('MMMM D, yy') + ' - ' + end.format('MMMM D, yy'));
     });
     $('#defaultrange_modal').on('click', function () {
     if ($('#daterangepicker_modal').is(":visible") && $('body').hasClass("modal-open") == false) {
     $('body').addClass("modal-open");
     }
     });
     $('#reportrange').daterangepicker({opens: (Metronic.isRTL() ? 'left' : 'right'), startDate: moment().subtract('days', 29), endDate: moment(), minDate: '01/01/2012', maxDate: '12/31/2014', dateLimit: {days: 60}, showDropdowns: true, showWeekNumbers: true, timePicker: false, timePickerIncrement: 1, timePicker12Hour: true, ranges: {'Today': [moment(), moment()], 'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)], 'Last 7 Days': [moment().subtract('days', 6), moment()], 'Last 30 Days': [moment().subtract('days', 29), moment()], 'This Month': [moment().startOf('month'), moment().endOf('month')], 'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]}, buttonClasses: ['btn'], applyClass: 'green', cancelClass: 'default', format: 'dd/mm/yy', separator: ' to ', locale: {applyLabel: 'Apply', fromLabel: 'From', toLabel: 'To', customRangeLabel: 'Custom Range', daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], firstDay: 1}}, function (start, end) {
     $('#reportrange span').html(start.format('MMMM D, yy') + ' - ' + end.format('MMMM D, yy'));
     });
     $('#reportrange span').html(moment().subtract('days', 29).format('MMMM D, yy') + ' - ' + moment().format('MMMM D, yy'));
     }
     */
    var handleDatetimePicker = function () {
        if (!jQuery().datetimepicker) {
            return;
        }
        $(".form_datetime").datetimepicker({autoclose: true, isRTL: Metronic.isRTL(), format: "dd MM yy - hh:ii", pickerPosition: (Metronic.isRTL() ? "bottom-right" : "bottom-left")});
        $(".form_advance_datetime").datetimepicker({
            isRTL: Metronic.isRTL(),
            format: "dd MM yy - hh:ii",
            autoclose: true,
            todayBtn: true,
            startDate: "2013-02-14 10:00",
            pickerPosition: (Metronic.isRTL() ? "bottom-right" : "bottom-left"),
            minuteStep: 10
        });
        $(".form_meridian_datetime").datetimepicker({
            isRTL: Metronic.isRTL(),
            format: "dd MM yy - HH:ii P",
            showMeridian: true,
            autoclose: true,
            pickerPosition: (Metronic.isRTL() ? "bottom-right" : "bottom-left"),
            todayBtn: true
        });
        $('body').removeClass("modal-open");
    }
    var handleClockfaceTimePickers = function () {
        if (!jQuery().clockface) {
            return;
        }
        $('.clockface_1').clockface();
        $('#clockface_2').clockface({format: 'HH:mm', trigger: 'manual'});
        $('#clockface_2_toggle').click(function (e) {
            e.stopPropagation();
            $('#clockface_2').clockface('toggle');
        });
        $('#clockface_2_modal').clockface({format: 'HH:mm', trigger: 'manual'});
        $('#clockface_2_modal_toggle').click(function (e) {
            e.stopPropagation();
            $('#clockface_2_modal').clockface('toggle');
        });
        $('.clockface_3').clockface({format: 'H:mm'}).clockface('show', '14:30');
    }
    var handleColorPicker = function () {
        if (!jQuery().colorpicker) {
            return;
        }
        $('.colorpicker-default').colorpicker({format: 'hex'});
        $('.colorpicker-rgba').colorpicker();
    }


    $('#print1').live('click', function () {
        $.print("#prin2");
    });


    return {
        //main function to initiate the module
        init: function () {
            datepicker();
            handleDatePickers();
            handleTimePickers();
            handleDatetimePicker();
            //handleDateRangePickers();
            handleClockfaceTimePickers();
            handleColorPicker();

        }

    };
}();

var FormDropzone = function () {
    return {
        //main function to initiate the module
        init: function () {

            Dropzone.options.myDropzone = {
                // only upload video mp4
                acceptedMimeTypes: 'video/mp4',
                dictDefaultMessage: "",
                init: function () {
                    this.on("success", function (file, response) {

                        // Create the remove button
                        var removeButton = Dropzone.createElement("<a href='javascript:;'' class='btn red btn-sm btn-block remove_slider_item' data-id='" + response + "'>Remove</a>");

                        // Capture the Dropzone instance as closure.
                        var _this = this;

                        // Listen to the click event
                        // removeButton.addEventListener("click", function(e) {
                        //   // Make sure the button click doesn't submit the form:
                        //   e.preventDefault();
                        //   e.stopPropagation();
                        //
                        //   // Remove the file preview.
                        //   _this.removeFile(file);
                        //   // If you want to the delete the file on the server as well,
                        //   // you can do the AJAX request here.
                        // });

                        // Add the button to the file preview element.
                        file.previewElement.appendChild(removeButton);
                    });
                }
            }
        }
    };
}();

jQuery(document).ready(function () {
    FormDropzone.init();
    var hosturl = $('#hosturl').val();

    $('body').on('click', '.remove_slider_item', function () {
        var id = $(this).attr('data-id');
        var thisElem = $(this);

        $.post(hosturl + '/controllers/screen_orders.php?ac=removeSlider', {id: id}, function (data) {
            console.log(data)
            thisElem.parent().remove();
        });
    })


});

var UINestable = function () {

    var is_control = $('#is_control').val();
    var is_visits = $('#what_control').val();
    var t = function (t) {
        var e = t.length ? t : $(t.target),
            a = e.data("output");
        //console.log(window.JSON.stringify(e.nestable("serialize")))


        //window.JSON ? a.val(window.JSON.stringify(e.nestable("serialize"))) : a.val("JSON browser support required for this demo.")
        //alert(a.val(window.JSON.stringify(e.nestable("serialize"))))
    };
    return {
        init: function () {


            if (is_visits === 'visits') {
                $("#nestable_list_3").nestable({maxDepth: 1}).on("change", t), t($("#nestable_list_3").data("output", $("#nestable_list_3_output")));

            } else {


            }

        }
    };
}();
jQuery(document).ready(function () {
    UINestable.init();
    var is_visits = $('#what_control').val();
    var hosturl = $('#hosturl').val();

    if (is_visits === 'visits') {
        $('.dd').on('change', function () {
            console.log(window.JSON.stringify($('.dd').nestable('serialize')));
            $.post(hosturl + '/controllers/screen_orders.php?ac=orderVisit', {orderJson: window.JSON.stringify($('.dd').nestable('serialize'))}, function (rslt) {
            });
        });
    } else {

    }


});