/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = "./src/email.coffee");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./src/email.coffee":
/*!**************************!*\
  !*** ./src/email.coffee ***!
  \**************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n// DOCUMENT READY ENTRY POINT\nvar EmailController;\n\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n  var controller;\n  console.debug(\"*** SENAITE.IMPRESS::DOMContentLoaded: --> Loading Email Controller\");\n  controller = new EmailController();\n  return controller.initialize();\n});\n\nEmailController = function () {\n  function EmailController() {\n    _classCallCheck(this, EmailController);\n\n    this.bind_eventhandler = this.bind_eventhandler.bind(this);\n    this.is_visible = this.is_visible.bind(this);\n    this.toggle_attachments_container = this.toggle_attachments_container.bind(this);\n    this.update_size_info = this.update_size_info.bind(this);\n    this.on_add_attachments_click = this.on_add_attachments_click.bind(this);\n    this.on_attachments_select = this.on_attachments_select.bind(this);\n    this.bind_eventhandler();\n    return this;\n  }\n\n  _createClass(EmailController, [{\n    key: \"initialize\",\n    value: function initialize() {\n      console.debug(\"senaite.impress:Email::initialize\");\n      // Initialize overlays\n      return this.init_overlays();\n    }\n  }, {\n    key: \"init_overlays\",\n    value: function init_overlays() {\n      /*\n       * Initialize all overlays for later loading\n       *\n       */\n      console.debug(\"senaite.impress:Email::init_overlays\");\n      return $(\"a.attachment-link,a.report-link\").prepOverlay({\n        subtype: \"iframe\",\n        config: {\n          closeOnClick: true,\n          closeOnEsc: true,\n          onLoad: function onLoad(event) {\n            var iframe, overlay;\n            overlay = this.getOverlay();\n            iframe = overlay.find(\"iframe\");\n            return iframe.css({\n              \"background\": \"white\"\n            });\n          }\n        }\n      });\n    }\n  }, {\n    key: \"bind_eventhandler\",\n    value: function bind_eventhandler() {\n      /*\n       * Binds callbacks on elements\n       *\n       * N.B. We attach all the events to the body and refine the selector to\n       * delegate the event: https://learn.jquery.com/events/event-delegation/\n       *\n       */\n      console.debug(\"senaite.impress::bind_eventhandler\");\n      // Toggle additional attachments visibility\n      $(\"body\").on(\"click\", \"#add-attachments\", this.on_add_attachments_click);\n      // Select/deselect additional attachments\n      return $(\"body\").on(\"change\", \".attachments input[type='checkbox']\", this.on_attachments_select);\n    }\n  }, {\n    key: \"get_base_url\",\n    value: function get_base_url() {\n      /*\n       * Calculate the current base url\n       */\n      return document.URL.split(\"?\")[0];\n    }\n  }, {\n    key: \"get_api_url\",\n    value: function get_api_url(endpoint) {\n      /*\n       * Build API URL for the given endpoint\n       * @param {string} endpoint\n       * @returns {string}\n       */\n      var base_url;\n      base_url = this.get_base_url();\n      return base_url + \"/\" + endpoint;\n    }\n  }, {\n    key: \"ajax_fetch\",\n    value: function ajax_fetch(endpoint, init) {\n      /*\n       * Call resource on the server\n       * @param {string} endpoint\n       * @param {object} options\n       * @returns {Promise}\n       */\n      var request, url;\n      url = this.get_api_url(endpoint);\n      if (init == null) {\n        init = {};\n      }\n      if (init.method == null) {\n        init.method = \"POST\";\n      }\n      if (init.credentials == null) {\n        init.credentials = \"include\";\n      }\n      if (init.body == null) {\n        init.body = null;\n      }\n      if (init.header == null) {\n        init.header = null;\n      }\n      console.info(\"Email::fetch:endpoint=\" + endpoint + \" init=\", init);\n      request = new Request(url, init);\n      return fetch(request).then(function (response) {\n        return response.json();\n      });\n    }\n  }, {\n    key: \"is_visible\",\n    value: function is_visible(element) {\n      /*\n       * Checks if the element is visible\n       */\n      if ($(element).css(\"display\") === \"none\") {\n        return false;\n      }\n      return true;\n    }\n  }, {\n    key: \"toggle_attachments_container\",\n    value: function toggle_attachments_container() {\n      var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n\n      /*\n       * Toggle the visibility of the attachments container\n       */\n      var button, container, visible;\n      button = $(\"#add-attachments\");\n      container = $(\"#additional-attachments-container\");\n      visible = this.is_visible(container);\n      if (toggle !== null) {\n        visible = toggle ? false : true;\n      }\n      if (visible === true) {\n        container.hide();\n        return button.text(\"+\");\n      } else {\n        container.show();\n        return button.text(\"-\");\n      }\n    }\n  }, {\n    key: \"update_size_info\",\n    value: function update_size_info(data) {\n      var unit;\n      /*\n       * Update the total size of the selected attachments\n       */\n      if (!data) {\n        console.warn(\"No valid size information: \", data);\n        return null;\n      }\n      unit = \"kB\";\n      $(\"#attachment-files\").text(\"\" + data.files);\n      if (data.limit_exceeded) {\n        $(\"#email-size\").addClass(\"text-danger\");\n        $(\"#email-size\").text(data.size + \" \" + unit + \" > \" + data.limit + \" \" + unit);\n        return $(\"input[name='send']\").prop(\"disabled\", true);\n      } else {\n        $(\"#email-size\").removeClass(\"text-danger\");\n        $(\"#email-size\").text(data.size + \" \" + unit);\n        return $(\"input[name='send']\").prop(\"disabled\", false);\n      }\n    }\n  }, {\n    key: \"on_add_attachments_click\",\n    value: function on_add_attachments_click(event) {\n      console.debug(\"°°° Email::on_add_attachments_click\");\n      event.preventDefault();\n      return this.toggle_attachments_container();\n    }\n  }, {\n    key: \"on_attachments_select\",\n    value: function on_attachments_select(event) {\n      var _this = this;\n\n      var form, form_data, init;\n      console.debug(\"°°° Email::on_attachments_select\");\n      // extract the form data\n      form = $(\"#send_email_form\");\n      // form.serialize does not include file attachments\n      // form_data = form.serialize()\n      form_data = new FormData(form[0]);\n      init = {\n        body: form_data\n      };\n      return this.ajax_fetch(\"recalculate_size\", init).then(function (data) {\n        return _this.update_size_info(data);\n      });\n    }\n  }]);\n\n  return EmailController;\n}();//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64, \n//# sourceURL=webpack-internal:///./src/email.coffee\n");

/***/ })

/******/ });