/**=========================================================
* Module: calendar-ui.js
* This script handle the calendar demo with draggable
* events and events creations
=========================================================*/
(function($, window, document){
'use strict';
if(!$.fn.fullCalendar) return;
// global shared var to know what we are dragging
var draggingEvent = null;
/**
* ExternalEvent object
* @param jQuery Object elements Set of element as jQuery objects
*/
var ExternalEvent = function (elements) {
if (!elements) return;
elements.each(function() {
var $this = $(this);
// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
// it doesn't need to have a start or end
var calendarEventObject = {
title: $.trim($this.text()) // use the element's text as the event title
};
// store the Event Object in the DOM element so we can get to it later
$this.data('calendarEventObject', calendarEventObject);
// make the event draggable using jQuery UI
$this.draggable({
zIndex: 1070,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
};
/**
* Invoke full calendar plugin and attach behavior
* @param jQuery [calElement] The calendar dom element wrapped into jQuery
* @param EventObject [events] An object with the event list to load when the calendar displays
*/
function initCalendar(calElement, events) {
// check to remove elements from the list
var removeAfterDrop = $('#remove-after-drop');
calElement.fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
buttonIcons: { // note the space at the beginning
prev: ' fa fa-caret-left',
next: ' fa fa-caret-right'
},
buttonText: {
today: 'today',
month: 'month',
week: 'week',
day: 'day'
},
editable: true,
droppable: true, // this allows things to be dropped onto the calendar
drop: function(date, allDay) { // this function is called when something is dropped
var $this = $(this),
// retrieve the dropped element's stored Event Object
originalEventObject = $this.data('calendarEventObject');
// if something went wrong, abort
if(!originalEventObject) return;
// clone the object to avoid multiple events with reference to the same object
var clonedEventObject = $.extend({}, originalEventObject);
// assign the reported date
clonedEventObject.start = date;
clonedEventObject.allDay = allDay;
clonedEventObject.backgroundColor = $this.css('background-color');
clonedEventObject.borderColor = $this.css('border-color');
// render the event on the calendar
// the last `true` argument determines if the event "sticks"
// (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
calElement.fullCalendar('renderEvent', clonedEventObject, true);
// if necessary remove the element from the list
if(removeAfterDrop.is(':checked')) {
$this.remove();
}
},
eventDragStart: function (event, js, ui) {
draggingEvent = event;
},
// This array is the events sources
events: events
});
}
/**
* Inits the external events panel
* @param jQuery [calElement] The calendar dom element wrapped into jQuery
*/
function initExternalEvents(calElement){
// Panel with the external events list
var externalEvents = $('.external-events');
// init the external events in the panel
new ExternalEvent(externalEvents.children('div'));
// External event color is danger-red by default
var currColor = '#f6504d';
// Color selector button
var eventAddBtn = $('.external-event-add-btn');
// New external event name input
var eventNameInput = $('.external-event-name');
// Color switchers
var eventColorSelector = $('.external-event-color-selector .circle');
// Trash events Droparea
$('.external-events-trash').droppable({
accept: '.fc-event',
activeClass: 'active',
hoverClass: 'hovered',
tolerance: 'touch',
drop: function(event, ui) {
// You can use this function to send an ajax request
// to remove the event from the repository
if(draggingEvent) {
var eid = draggingEvent.id || draggingEvent._id;
// Remove the event
calElement.fullCalendar('removeEvents', eid);
// Remove the dom element
ui.draggable.remove();
// clear
draggingEvent = null;
}
}
});
eventColorSelector.click(function(e) {
e.preventDefault();
var $this = $(this);
// Save color
currColor = $this.css('background-color');
// De-select all and select the current one
eventColorSelector.removeClass('selected');
$this.addClass('selected');
});
eventAddBtn.click(function(e) {
e.preventDefault();
// Get event name from input
var val = eventNameInput.val();
// Dont allow empty values
if ($.trim(val) === '') return;
// Create new event element
var newEvent = $('
').css({
'background-color': currColor,
'border-color': currColor,
'color': '#fff'
})
.html(val);
// Prepends to the external events list
externalEvents.prepend(newEvent);
// Initialize the new event element
new ExternalEvent(newEvent);
// Clear input
eventNameInput.val('');
});
}
/**
* Creates an array of events to display in the first load of the calendar
* Wrap into this function a request to a source to get via ajax the stored events
* @return Array The array with the events
*/
function createDemoEvents() {
// Date for the calendar events (dummy data)
var date = new Date();
var d = date.getDate(),
m = date.getMonth(),
y = date.getFullYear();
return [
{
title: 'All Day Event',
start: new Date(y, m, 1),
backgroundColor: '#f56954', //red
borderColor: '#f56954' //red
},
{
title: 'Long Event',
start: new Date(y, m, d - 5),
end: new Date(y, m, d - 2),
backgroundColor: '#f39c12', //yellow
borderColor: '#f39c12' //yellow
},
{
title: 'Meeting',
start: new Date(y, m, d, 10, 30),
allDay: false,
backgroundColor: '#0073b7', //Blue
borderColor: '#0073b7' //Blue
},
{
title: 'Lunch',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false,
backgroundColor: '#00c0ef', //Info (aqua)
borderColor: '#00c0ef' //Info (aqua)
},
{
title: 'Birthday Party',
start: new Date(y, m, d + 1, 19, 0),
end: new Date(y, m, d + 1, 22, 30),
allDay: false,
backgroundColor: '#00a65a', //Success (green)
borderColor: '#00a65a' //Success (green)
},
{
title: 'Open Google',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
url: 'http://google.com/',
backgroundColor: '#3c8dbc', //Primary (light-blue)
borderColor: '#3c8dbc' //Primary (light-blue)
}
];
}
// When dom ready, init calendar and events
$(function() {
// The element that will display the calendar
var calendar = $('#calendar');
var demoEvents = createDemoEvents();
initExternalEvents(calendar);
initCalendar(calendar, demoEvents);
});
}(jQuery, window, document));
/**=========================================================
* Module: clear-storage.js
* Removes a key from the browser storage via element click
=========================================================*/
(function($, window, document){
'use strict';
if( !store || !store.enabled ) return;
var Selector = '[data-toggle="reset"]';
$(document).on('click', Selector, function (e) {
e.preventDefault();
var key = $(this).data('key');
if(key) {
store.remove(key);
// reload the page
window.location.reload();
}
else {
$.error('No storage key specified for reset.');
}
});
}(jQuery, window, document));
/**=========================================================
* Module: datepicker,js
* DateTime Picker init
=========================================================*/
(function($, window, document){
'use strict';
$(function(){
if ( ! $.fn.dataTable ) return;
//
// Zero configuration
//
$('#datatable1').dataTable({
'paging': true, // Table pagination
'ordering': true, // Column ordering
'info': true, // Bottom left status text
// Text translation options
// Note the required keywords between underscores (e.g _MENU_)
oLanguage: {
sSearch: 'Search all columns:',
sLengthMenu: '_MENU_ records per page',
info: 'Showing page _PAGE_ of _PAGES_',
zeroRecords: 'Nothing found - sorry',
infoEmpty: 'No records available',
infoFiltered: '(filtered from _MAX_ total records)'
}
});
//
// Filtering by Columns
//
var dtInstance2 = $('#datatable2').dataTable({
'paging': true, // Table pagination
'ordering': true, // Column ordering
'info': true, // Bottom left status text
// Text translation options
// Note the required keywords between underscores (e.g _MENU_)
oLanguage: {
sSearch: 'Search all columns:',
sLengthMenu: '_MENU_ records per page',
info: 'Showing page _PAGE_ of _PAGES_',
zeroRecords: 'Nothing found - sorry',
infoEmpty: 'No records available',
infoFiltered: '(filtered from _MAX_ total records)'
}
});
var inputSearchClass = 'datatable_input_col_search';
var columnInputs = $('tfoot .'+inputSearchClass);
// On input keyup trigger filtering
columnInputs
.keyup(function () {
dtInstance2.fnFilter(this.value, columnInputs.index(this));
});
//
// Column Visibilty Extension
//
$('#datatable3').dataTable({
'paging': true, // Table pagination
'ordering': true, // Column ordering
'info': true, // Bottom left status text
// Text translation options
// Note the required keywords between underscores (e.g _MENU_)
oLanguage: {
sSearch: 'Search all columns:',
sLengthMenu: '_MENU_ records per page',
info: 'Showing page _PAGE_ of _PAGES_',
zeroRecords: 'Nothing found - sorry',
infoEmpty: 'No records available',
infoFiltered: '(filtered from _MAX_ total records)'
},
sDom: 'C<"clear">lfrtip',
colVis: {
order: 'alfa',
'buttonText': 'Show/Hide Columns'
}
});
});
}(jQuery, window, document));
/**=========================================================
* Module: datepicker,js
* DateTime Picker init
=========================================================*/
(function($, window, document){
'use strict';
var Selector = '.datetimepicker';
$(Selector).each(function() {
var $this = $(this),
options = $this.data(); // allow to set options via data-* attributes
$this.datetimepicker($.extend(
options,
{ // support for FontAwesome icons
icons: {
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
up: 'fa fa-arrow-up',
down: 'fa fa-arrow-down'
}
}));
// Force a dropdown hide when click out of the input
$(document).on('click', function(){
$this.data('DateTimePicker').hide();
});
});
}(jQuery, window, document));
/**=========================================================
* Module: dropdown-animate.js
* Animated transition for dropdown open state
* Animation name placed in [data-play="animationName"] (http://daneden.github.io/animate.css/)
* Optionally add [data-duration=seconds]
*
* Requires animo.js
=========================================================*/
(function($, window, document){
'use strict';
$(function() {
var Selector = '.dropdown-toggle[data-play]',
parent = $(Selector).parent(); /* From BS-Doc: All dropdown events are fired at the .dropdown-menu's parent element. */
parent.on('show.bs.dropdown', function () {
//e.preventDefault();
var $this = $(this),
toggle = $this.children('.dropdown-toggle'),
animation = toggle.data('play'),
duration = toggle.data('duration') || 0.5,
target = $this.children('.dropdown-menu');
if(!target || !target.length)
$.error('No target for play-animation');
else
if( $.fn.animo && animation)
target.animo( { animation: animation, duration: duration} );
});
});
}(jQuery, window, document));
/**=========================================================
* Module: flot-chart.js
* Initializes the flot chart plugin and attaches the
* plugin to elements according to its type
=========================================================*/
(function($, window, document){
'use strict';
/**
* Global object to load data for charts using ajax
* Request the chart data from the server via post
* Expects a response in JSON format to init the plugin
* Usage
* chart = new floatChart('#id', 'server/chart-data.php')
* ...
* chart.requestData(options);
*
* @param Chart element placeholder or selector
* @param Url to get the data via post. Response in JSON format
*/
window.FlotChart = function (element, url) {
// Properties
this.element = $(element);
this.url = url;
// Public method
this.requestData = function (option, method, callback) {
var self = this;
// support params (option), (option, method, callback) or (option, callback)
callback = (method && $.isFunction(method)) ? method : callback;
method = (method && typeof method == 'string') ? method : 'POST';
self.option = option; // save options
$.ajax({
url: self.url,
cache: false,
type: method,
dataType: 'json'
}).done(function (data) {
$.plot( self.element, data, option );
if(callback) callback();
});
return this; // chain-ability
};
// Listen to refresh events
this.listen = function() {
var self = this,
chartPanel = this.element.parents('.panel').eq(0);
// attach custom event
chartPanel.on('panel-refresh', function(event, panel) {
// request data and remove spinner when done
self.requestData(self.option, function(){
panel.removeSpinner();
});
});
return this; // chain-ability
};
};
//
// Start of Demo Script
//
$(function () {
// Bar chart
(function () {
var Selector = '.chart-bar';
$(Selector).each(function() {
var source = $(this).data('source') || $.error('Bar: No source defined.');
var chart = new FlotChart(this, source),
//panel = $(Selector).parents('.panel'),
option = {
series: {
bars: {
align: 'center',
lineWidth: 0,
show: true,
barWidth: 0.6,
fill: 0.9
}
},
grid: {
borderColor: '#eee',
borderWidth: 1,
hoverable: true,
backgroundColor: '#fcfcfc'
},
tooltip: true,
tooltipOpts: {
content: '%x : %y'
},
xaxis: {
tickColor: '#fcfcfc',
mode: 'categories'
},
yaxis: {
tickColor: '#eee'
},
shadowSize: 0
};
// Send Request
chart.requestData(option);
});
})();
// Bar Stacked chart
(function () {
var Selector = '.chart-bar-stacked';
$(Selector).each(function() {
var source = $(this).data('source') || $.error('Bar Stacked: No source defined.');
var chart = new FlotChart(this, source),
option = {
series: {
stack: true,
bars: {
align: 'center',
lineWidth: 0,
show: true,
barWidth: 0.6,
fill: 0.9
}
},
grid: {
borderColor: '#eee',
borderWidth: 1,
hoverable: true,
backgroundColor: '#fcfcfc'
},
tooltip: true,
tooltipOpts: {
content: '%x : %y'
},
xaxis: {
tickColor: '#fcfcfc',
mode: 'categories'
},
yaxis: {
tickColor: '#eee'
},
shadowSize: 0
};
// Send Request
chart.requestData(option);
});
})();
// Area chart
(function () {
var Selector = '.chart-area';
$(Selector).each(function() {
var source = $(this).data('source') || $.error('Area: No source defined.');
var chart = new FlotChart(this, source),
option = {
series: {
lines: {
show: true,
fill: 0.8
},
points: {
show: true,
radius: 4
}
},
grid: {
borderColor: '#eee',
borderWidth: 1,
hoverable: true,
backgroundColor: '#fcfcfc'
},
tooltip: true,
tooltipOpts: {
content: '%x : %y'
},
xaxis: {
tickColor: '#fcfcfc',
mode: 'categories'
},
yaxis: {
tickColor: '#eee',
tickFormatter: function (v) {
return v + ' visitors';
}
},
shadowSize: 0
};
// Send Request and Listen for refresh events
chart.requestData(option).listen();
});
})();
// Line chart
(function () {
var Selector = '.chart-line';
$(Selector).each(function() {
var source = $(this).data('source') || $.error('Line: No source defined.');
var chart = new FlotChart(this, source),
option = {
series: {
lines: {
show: true,
fill: 0.01
},
points: {
show: true,
radius: 4
}
},
grid: {
borderColor: '#eee',
borderWidth: 1,
hoverable: true,
backgroundColor: '#fcfcfc'
},
tooltip: true,
tooltipOpts: {
content: '%x : %y'
},
xaxis: {
tickColor: '#eee',
mode: 'categories'
},
yaxis: {
tickColor: '#eee'
},
shadowSize: 0
};
// Send Request
chart.requestData(option);
});
})();
// Pïe
(function () {
var Selector = '.chart-pie';
$(Selector).each(function() {
var source = $(this).data('source') || $.error('Pie: No source defined.');
var chart = new FlotChart(this, source),
option = {
series: {
pie: {
show: true,
innerRadius: 0,
label: {
show: true,
radius: 0.8,
formatter: function (label, series) {
return '