/* =========================================================== * CapacityPlanning.js v0.0.1 * =========================================================== * Copyright 2015 Prevu * ========================================================== */ (function ($) { "use strict"; // jshint ;_; /* CapacityPlanning CLASS DEFINITION * ====================== */ var CapacityPlanning = function (element, options) { this.init(element, options); }; CapacityPlanning.prototype = { constructor: CapacityPlanning, init: function (element, options) { var plugin = this; this.options = options; this.$container = $(element); this.$dataset = {}; this.$dataset.data = []; this.$dataLoaded = false; this.$controls = {}; this.$maxDate = this.getUtcFromText("1/1/2100"); this.$allCatgoriesIndex = null; if (!this.options.teamId) { throw "Team Id must be set"; } // Init filter elements: datepickers and select2 this.$container.find('[data-capacity-planning="filterDates"]').datepicker(this.options.datePickerOptions); this.$controls.categoriesFilter = this.$container.find('[data-capacity-planning="filterCategories"]').select2(); // Attach event receivers to controls this.$controls.isPermanentFilter = this.$container.find('[data-capacity-planning="filterIsPermanent"]'); this.$controls.isPermanentFilter.on("click", function () { plugin.switchPermanent(this); }); this.$container.find('[data-capacity-planning="filterIncreaseCapacity"]').on("click", function () { plugin.increaseCapacity(); }); this.$container.find('[data-capacity-planning="filterDecreaseCapacity"]').on("click", function () { plugin.decreaseCapacity(); }); this.$container.find('[data-capacity-planning="filterResetCapacity"]').on("click", function () { plugin.resetCapacity(); }); this.$container.find('[data-capacity-planning="filterResetEntireCapacity"]').on("click", function () { plugin.resetEntireCapacity(this); }); this.$container.find('[data-capacity-planning="formDecreaseSubmitBtn"]').on("click", function () { plugin.fillDecreaseSubmit(this); }); // Caching other controls this.$controls.dataTable = this.$container.find('[data-capacity-planning="dataTable"]'); this.$controls.endDateFilter = this.$container.find('[data-capacity-planning="filterEndDate"]'); this.$controls.startDateFilter = this.$container.find('[data-capacity-planning="filterStartDate"]'); this.$controls.amountFilter = this.$container.find('[data-capacity-planning="filterAmount"]'); // Public initial ecpenditure categories list this.initCategoriesFilter(); this.createCategoriesIndex(); if (this.options.data) { this.setData(this.options.data); } if (this.options.initCallback && (typeof this.options.initCallback === 'function')) { this.options.initCallback(this.$dataset); } }, initCategoriesFilter: function () { var expCatDropDown = this.$controls.categoriesFilter; expCatDropDown.empty(); var selInPlanHtml = $('').prop('label', "Categories in Plan").appendTo(expCatDropDown); var selAddHtml = $('').prop('label', "Add Category").appendTo(expCatDropDown); if (!this.options.expenditureCategories || (this.options.expenditureCategories.length < 1)) return; $.each(this.options.expenditureCategories, function () { $("