From e0c804b3265d6be3a5c281e50c68fa800a677ef8 Mon Sep 17 00:00:00 2001 From: Pieter Maene Date: Fri, 1 Feb 2019 18:24:14 +0100 Subject: [PATCH 1/8] Started work on using webpack for asset management --- .gitignore | 3 + assets/CommonBundle/common/common.js | 8 + .../CommonBundle/common/js/permanentModal.js | 41 + .../common/js/resizableColumns.js | 177 + assets/CommonBundle/common/js/serialize.js | 121 + assets/CommonBundle/common/js/socket.js | 88 + .../CommonBundle/common/js/typeaheadRemote.js | 246 + assets/CommonBundle/common/js/unserialize.js | 171 + .../CudiBundle}/sale/js/barcodeControl.js | 0 .../CudiBundle}/sale/js/calculateChange.js | 0 .../CudiBundle}/sale/js/collect.js | 0 .../CudiBundle}/sale/js/queue.js | 0 .../CudiBundle}/sale/js/sale.js | 6 +- .../CudiBundle}/sale/js/saleApp.js | 2 +- .../CudiBundle}/sale/js/saleInterface.js | 4 +- .../CudiBundle}/sale/js/shortKey.js | 0 assets/CudiBundle/sale/less/base.less | 18 + assets/CudiBundle/sale/less/companies.less | 16 + assets/CudiBundle/sale/less/layout.less | 84 + assets/CudiBundle/sale/less/sale.less | 152 + assets/CudiBundle/sale/less/variables.less | 17 + assets/CudiBundle/sale/sale.js | 18 + assets/CudiBundle/sale/sale.scss | 6 + assets/CudiBundle/sale/scss/_variables.scss | 2 + .../Component/Version/Version.php | 2 +- .../Resources/config/module.config.php | 2 +- .../Resources/config/assetic.config.php | 56 +- .../Resources/layouts/sale/base.twig | 90 +- package.json | 16 + postcss.config.js | 5 + public/.htaccess | 20 - webpack.config.js | 31 + yarn.lock | 7170 +++++++++++++++++ 33 files changed, 8473 insertions(+), 99 deletions(-) create mode 100644 assets/CommonBundle/common/common.js create mode 100644 assets/CommonBundle/common/js/permanentModal.js create mode 100644 assets/CommonBundle/common/js/resizableColumns.js create mode 100644 assets/CommonBundle/common/js/serialize.js create mode 100644 assets/CommonBundle/common/js/socket.js create mode 100644 assets/CommonBundle/common/js/typeaheadRemote.js create mode 100644 assets/CommonBundle/common/js/unserialize.js rename {module/CudiBundle/Resources/assets => assets/CudiBundle}/sale/js/barcodeControl.js (100%) rename {module/CudiBundle/Resources/assets => assets/CudiBundle}/sale/js/calculateChange.js (100%) rename {module/CudiBundle/Resources/assets => assets/CudiBundle}/sale/js/collect.js (100%) rename {module/CudiBundle/Resources/assets => assets/CudiBundle}/sale/js/queue.js (100%) rename {module/CudiBundle/Resources/assets => assets/CudiBundle}/sale/js/sale.js (97%) rename {module/CudiBundle/Resources/assets => assets/CudiBundle}/sale/js/saleApp.js (98%) rename {module/CudiBundle/Resources/assets => assets/CudiBundle}/sale/js/saleInterface.js (99%) rename {module/CudiBundle/Resources/assets => assets/CudiBundle}/sale/js/shortKey.js (100%) create mode 100644 assets/CudiBundle/sale/less/base.less create mode 100644 assets/CudiBundle/sale/less/companies.less create mode 100644 assets/CudiBundle/sale/less/layout.less create mode 100644 assets/CudiBundle/sale/less/sale.less create mode 100644 assets/CudiBundle/sale/less/variables.less create mode 100644 assets/CudiBundle/sale/sale.js create mode 100644 assets/CudiBundle/sale/sale.scss create mode 100644 assets/CudiBundle/sale/scss/_variables.scss create mode 100644 package.json create mode 100644 postcss.config.js delete mode 100644 public/.htaccess create mode 100644 webpack.config.js create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore index 586796f169..dcacc0eee0 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,8 @@ data/proxies data/form/files public/_assetic +public/_encore + public/_common/profile public/_gallery/albums public/_publications/pdf @@ -26,6 +28,7 @@ public/_publications/html public/_br/img # Exclude dependencies +node_modules/ vendor/ # Output from external tools diff --git a/assets/CommonBundle/common/common.js b/assets/CommonBundle/common/common.js new file mode 100644 index 0000000000..2e65bc5ec2 --- /dev/null +++ b/assets/CommonBundle/common/common.js @@ -0,0 +1,8 @@ +// JS + +import 'script-loader!./js/permanentModal.js'; +import 'script-loader!./js/resizableColumns.js'; +import 'script-loader!./js/serialize.js'; +import 'script-loader!./js/socket.js'; +import 'script-loader!./js/typeaheadRemote.js'; +import 'script-loader!./js/unserialize.js'; diff --git a/assets/CommonBundle/common/js/permanentModal.js b/assets/CommonBundle/common/js/permanentModal.js new file mode 100644 index 0000000000..5dd2ae0a97 --- /dev/null +++ b/assets/CommonBundle/common/js/permanentModal.js @@ -0,0 +1,41 @@ +(function ($) { + var defaults = { + closable: false + }; + + var methods = { + open: function (options) { + options = $.extend(defaults, options); + + $(this).find('.modal-header .close').toggle(options.closable); + + if ($(this).data('bs.modal')) { + $(this).data('bs.modal').options.keyboard = options.closable; + $(this).data('bs.modal').options.backdrop = options.closable ? true : 'static'; + $(this).modal(); + } else { + $(this).modal({ + keyboard: options.closable, + backdrop: options.closable ? true : 'static', + }); + } + + return this; + }, + hide: function () { + $(this).modal('hide'); + + return this; + } + }; + + $.fn.permanentModal = function (method) { + if (methods[method]) { + return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); + } else if (typeof method === 'object' || ! method) { + return methods.open.apply(this, arguments); + } else { + $.error('Method ' + method + ' does not exist on $.permanentModal'); + } + }; +}) (jQuery); \ No newline at end of file diff --git a/assets/CommonBundle/common/js/resizableColumns.js b/assets/CommonBundle/common/js/resizableColumns.js new file mode 100644 index 0000000000..d63dabc3d5 --- /dev/null +++ b/assets/CommonBundle/common/js/resizableColumns.js @@ -0,0 +1,177 @@ +var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + __slice = [].slice; + +(function($, window) { + var ResizableColumns, parseWidth, pointerX, setWidth; + parseWidth = function(node) { + return parseFloat(node.style.width.replace('%', '')); + }; + setWidth = function(node, width) { + width = width.toFixed(2); + return node.style.width = "" + width + "%"; + }; + pointerX = function(e) { + if (e.type.indexOf('touch') === 0) { + return (e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]).pageX; + } + return e.pageX; + }; + ResizableColumns = (function() { + ResizableColumns.prototype.defaults = { + store: window.store, + rigidSizing: false, + resizeFromBody: true + }; + + function ResizableColumns($table, options) { + this.pointerdown = __bind(this.pointerdown, this); + var _this = this; + this.options = $.extend({}, this.defaults, options); + this.$table = $table; + this.setHeaders(); + this.restoreColumnWidths(); + this.syncHandleWidths(); + $(window).on('resize.rc', (function() { + return _this.syncHandleWidths(); + })); + } + + ResizableColumns.prototype.getColumnId = function($el) { + return this.$table.data('resizable-columns-id') + '-' + $el.data('resizable-column-id'); + }; + + ResizableColumns.prototype.setHeaders = function() { + this.$tableHeaders = this.$table.find('tr th:visible'); + this.assignPercentageWidths(); + return this.createHandles(); + }; + + ResizableColumns.prototype.destroy = function() { + this.$handleContainer.remove(); + this.$table.removeData('resizableColumns'); + return $(window).off('.rc'); + }; + + ResizableColumns.prototype.assignPercentageWidths = function() { + var _this = this; + return this.$tableHeaders.each(function(_, el) { + var $el; + $el = $(el); + return setWidth($el[0], $el.outerWidth() / _this.$table.width() * 100); + }); + }; + + ResizableColumns.prototype.createHandles = function() { + var _ref, + _this = this; + if ((_ref = this.$handleContainer) != null) { + _ref.remove(); + } + this.$table.before((this.$handleContainer = $("
"))); + this.$tableHeaders.each(function(i, el) { + var $handle; + if (_this.$tableHeaders.eq(i + 1).length === 0 || (_this.$tableHeaders.eq(i).attr('data-noresize') != null) || (_this.$tableHeaders.eq(i + 1).attr('data-noresize') != null)) { + return; + } + $handle = $("
"); + $handle.data('th', $(el)); + return $handle.appendTo(_this.$handleContainer); + }); + return this.$handleContainer.on('mousedown touchstart', '.rc-handle', this.pointerdown); + }; + + ResizableColumns.prototype.syncHandleWidths = function() { + var _this = this; + this.setHeaders(); + return this.$handleContainer.width(this.$table.width()).find('.rc-handle').each(function(_, el) { + var $el; + $el = $(el); + return $el.css({ + left: $el.data('th').outerWidth() + ($el.data('th').offset().left - _this.$handleContainer.offset().left), + height: _this.options.resizeFromBody ? _this.$table.height() : _this.$table.find('thead').height() + }); + }); + }; + + ResizableColumns.prototype.saveColumnWidths = function() { + var _this = this; + return this.$tableHeaders.each(function(_, el) { + var $el; + $el = $(el); + if ($el.attr('data-noresize') == null) { + if (_this.options.store != null) { + return _this.options.store.set(_this.getColumnId($el), parseWidth($el[0])); + } + } + }); + }; + + ResizableColumns.prototype.restoreColumnWidths = function() { + var _this = this; + return this.$tableHeaders.each(function(_, el) { + var $el, width; + $el = $(el); + if ((_this.options.store != null) && (width = _this.options.store.get(_this.getColumnId($el)))) { + return setWidth($el[0], width); + } + }); + }; + + ResizableColumns.prototype.totalColumnWidths = function() { + var total, + _this = this; + total = 0; + this.$tableHeaders.each(function(_, el) { + return total += parseFloat($(el)[0].style.width.replace('%', '')); + }); + return total; + }; + + ResizableColumns.prototype.pointerdown = function(e) { + var $currentGrip, $leftColumn, $rightColumn, startPosition, widths, + _this = this; + e.preventDefault(); + startPosition = pointerX(e); + $currentGrip = $(e.currentTarget); + $leftColumn = $currentGrip.data('th'); + $rightColumn = this.$tableHeaders.eq(this.$tableHeaders.index($leftColumn) + 1); + widths = { + left: parseWidth($leftColumn[0]), + right: parseWidth($rightColumn[0]) + }; + this.$table.addClass('rc-table-resizing'); + $(document).on('mousemove.rc touchmove.rc', function(e) { + var difference; + difference = (pointerX(e) - startPosition) / _this.$table.width() * 100; + setWidth($rightColumn[0], widths.right - difference); + return setWidth($leftColumn[0], widths.left + difference); + }); + return $(document).one('mouseup touchend', function() { + $(document).off('mousemove.rc touchmove.rc'); + _this.$table.removeClass('rc-table-resizing'); + _this.syncHandleWidths(); + return _this.saveColumnWidths(); + }); + }; + + return ResizableColumns; + + })(); + return $.fn.extend({ + resizableColumns: function() { + var args, option; + option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + return this.each(function() { + var $table, data; + $table = $(this); + data = $table.data('resizableColumns'); + if (!data) { + $table.data('resizableColumns', (data = new ResizableColumns($table, option))); + } + if (typeof option === 'string') { + return data[option].apply(data, args); + } + }); + } + }); +})(window.jQuery, window); diff --git a/assets/CommonBundle/common/js/serialize.js b/assets/CommonBundle/common/js/serialize.js new file mode 100644 index 0000000000..fae9538ff6 --- /dev/null +++ b/assets/CommonBundle/common/js/serialize.js @@ -0,0 +1,121 @@ +function serialize (mixed_value) { + // http://kevin.vanzonneveld.net + // + original by: Arpad Ray (mailto:arpad@php.net) + // + improved by: Dino + // + bugfixed by: Andrej Pavlovic + // + bugfixed by: Garagoth + // + input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html) + // + bugfixed by: Russell Walker (http://www.nbill.co.uk/) + // + bugfixed by: Jamie Beck (http://www.terabit.ca/) + // + input by: Martin (http://www.erlenwiese.de/) + // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/) + // + improved by: Le Torbi (http://www.letorbi.de/) + // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/) + // + bugfixed by: Ben (http://benblume.co.uk/) + // % note: We feel the main purpose of this function should be to ease the transport of data between php & js + // % note: Aiming for PHP-compatibility, we have to translate objects to arrays + // * example 1: serialize(['Kevin', 'van', 'Zonneveld']); + // * returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}' + // * example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}); + // * returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}' + var val, key, okey, + ktype = '', vals = '', count = 0, + _utf8Size = function (str) { + var size = 0, + i = 0, + l = str.length, + code = ''; + for (i = 0; i < l; i++) { + code = str.charCodeAt(i); + if (code < 0x0080) { + size += 1; + } + else if (code < 0x0800) { + size += 2; + } + else { + size += 3; + } + } + return size; + }, + _getType = function (inp) { + var match, key, cons, types, type = typeof inp; + + if (type === 'object' && !inp) { + return 'null'; + } + if (type === 'object') { + if (!inp.constructor) { + return 'object'; + } + cons = inp.constructor.toString(); + match = cons.match(/(\w+)\(/); + if (match) { + cons = match[1].toLowerCase(); + } + types = ['boolean', 'number', 'string', 'array']; + for (key in types) { + if (cons == types[key]) { + type = types[key]; + break; + } + } + } + return type; + }, + type = _getType(mixed_value) + ; + + switch (type) { + case 'function': + val = ''; + break; + case 'boolean': + val = 'b:' + (mixed_value ? '1' : '0'); + break; + case 'number': + val = (Math.round(mixed_value) == mixed_value ? 'i' : 'd') + ':' + mixed_value; + break; + case 'string': + val = 's:' + _utf8Size(mixed_value) + ':"' + mixed_value + '"'; + break; + case 'array': case 'object': + val = 'a'; + /* + if (type === 'object') { + var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/); + if (objname == undefined) { + return; + } + objname[1] = this.serialize(objname[1]); + val = 'O' + objname[1].substring(1, objname[1].length - 1); + } + */ + + for (key in mixed_value) { + if (mixed_value.hasOwnProperty(key)) { + ktype = _getType(mixed_value[key]); + if (ktype === 'function') { + continue; + } + + okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key); + vals += this.serialize(okey) + this.serialize(mixed_value[key]); + count++; + } + } + val += ':' + count + ':{' + vals + '}'; + break; + case 'undefined': + // Fall-through + default: + // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP + val = 'N'; + break; + } + if (type !== 'object' && type !== 'array') { + val += ';'; + } + return val; +} \ No newline at end of file diff --git a/assets/CommonBundle/common/js/socket.js b/assets/CommonBundle/common/js/socket.js new file mode 100644 index 0000000000..b54aaf74c3 --- /dev/null +++ b/assets/CommonBundle/common/js/socket.js @@ -0,0 +1,88 @@ +(function ($) { + var socketConnectTimeout; + + var defaults = { + name: 'webSocket', + url: '', + open: function(){}, + error: function(){}, + message: function(){} + }; + + var methods = { + init : function (options) { + var settings = $.extend(defaults, options); + + url = options.url; + if (url[0] == ':') { + url = document.location.host + url; + } + + if (location.protocol != 'https:') { + var ws = new WebSocket('ws://' + url); + } else { + var ws = new WebSocket('wss://' + url); + } + + clearTimeout(socketConnectTimeout); + socketConnectTimeout = setTimeout( + function () { + ws.close(); + }, + 5000 + ); + + $(ws) + .bind('open', function (e) { + clearTimeout(socketConnectTimeout); + settings.open(e); + }) + .bind('close', function (e) { + clearTimeout(socketConnectTimeout); + socketConnectTimeout = setTimeout(function () {$.webSocket(settings)}, 1000); + settings.error(e); + }) + .bind('error', function (e) { + clearTimeout(socketConnectTimeout); + settings.error(e); + }) + .bind('message', function (e) { + clearTimeout(socketConnectTimeout); + if (e.originalEvent.type == 'message' && e.originalEvent.data) + settings.message(e.originalEvent, $.parseJSON(e.originalEvent.data)); + }); + + $(window).on('beforeunload', function() { + $.webSocket('close', settings); + }); + + $(document).data(settings.name, ws); + return this; + }, + send : function (data) { + var socket = $(document).data(data.name); + if (socket != undefined) + socket.send(data.text); + return this; + }, + close : function (data) { + var socket = $(document).data(data.name); + if (socket != undefined) + $(document).data(data.name).close(); + $(document).removeData(data.name); + return this; + } + }; + + $.extend({ + webSocket: function ( method ) { + if ( methods[ method ] ) { + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( typeof method === 'object' || ! method ) { + return methods.init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on $.webSocket' ); + } + } + }); +}) (jQuery); diff --git a/assets/CommonBundle/common/js/typeaheadRemote.js b/assets/CommonBundle/common/js/typeaheadRemote.js new file mode 100644 index 0000000000..4f5285ed98 --- /dev/null +++ b/assets/CommonBundle/common/js/typeaheadRemote.js @@ -0,0 +1,246 @@ +!function( $ ){ + + "use strict" + + var TypeaheadRemote = function ( element, options ) { + this.$element = $(element) + this.options = $.extend({}, $.fn.typeaheadRemote.defaults, options) + this.matcher = this.options.matcher || this.matcher + this.sorter = this.options.sorter || this.sorter + this.highlighter = this.options.highlighter || this.highlighter + this.$menu = $(this.options.menu).appendTo('body') + this.source = this.options.source + this.shown = false + this.listen() + } + + TypeaheadRemote.prototype = { + + constructor: TypeaheadRemote + + , select: function () { + var val = this.$menu.find('.active').data('value') + this.$element.val(val.value).data('value', val); + this.$element.change(); + return this.hide() + } + + , show: function () { + var pos = $.extend({}, this.$element.offset(), { + height: this.$element[0].offsetHeight + }) + + this.$menu.css({ + top: pos.top + pos.height + , left: pos.left + , zIndex: 2000 + }) + + this.$menu.show() + this.shown = true + return this + } + + , hide: function () { + this.$menu.hide() + this.shown = false + return this + } + + , lookup: function (event) { + var that = this + , items + , q + + this.query = this.$element.val() + + if (!this.query) { + return this.shown ? this.hide() : this + } + + if (this.$element.data('timeout')) + clearTimeout(this.$element.data('timeout')); + + this.$element.data('timeout', setTimeout(function () { + if (that.jsonRequest) + that.jsonRequest.abort(); + that.jsonRequest = $.getJSON(that.source + that.query, function(items) { + if (!items.length || !that.$element.is(':visible')) + return that.shown ? that.hide() : that + + return that.render(items.slice(0, that.options.items)).show() + }); + }, 200)); + } + + , highlighter: function (item) { + return item.value.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) { + return '' + match + '' + }) + } + + , render: function (items) { + var that = this + + items = $(items).map(function (i, item) { + i = $(that.options.item).data('value', item) + i.find('a').html(that.highlighter(item)) + return i[0] + }) + + items.first().addClass('active') + this.$menu.html(items) + return this + } + + , next: function (event) { + var active = this.$menu.find('.active').removeClass('active') + , next = active.next() + + if (!next.length) { + next = $(this.$menu.find('li')[0]) + } + + next.addClass('active') + } + + , prev: function (event) { + var active = this.$menu.find('.active').removeClass('active') + , prev = active.prev() + + if (!prev.length) { + prev = this.$menu.find('li').last() + } + + prev.addClass('active') + } + + , listen: function () { + this.$element.attr( "autocomplete", "off" ); + this.$element + .on('blur', $.proxy(this.blur, this)) + .on('keypress', $.proxy(this.keypress, this)) + .on('keyup', $.proxy(this.keyup, this)) + + if (this.eventSupported('keydown')) { + this.$element.on('keydown', $.proxy(this.keypress, this)) + } + + this.$menu + .on('click', $.proxy(this.click, this)) + .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) + } + + , eventSupported: function(eventName) { + var isSupported = eventName in this.$element + if (!isSupported) { + this.$element.setAttribute(eventName, 'return;') + isSupported = typeof this.$element[eventName] === 'function' + } + return isSupported + } + + , keyup: function (e) { + switch(e.keyCode) { + case 40: // down arrow + case 38: // up arrow + break + + case 9: // tab + case 13: // enter + if (!this.shown) return + this.select() + break + + case 27: // escape + if (!this.shown) return + this.hide() + break + + default: + this.lookup() + } + + e.stopPropagation() + e.preventDefault() + } + + , keypress: function (e) { + if (!this.shown) return + + switch(e.keyCode) { + case 9: // tab + case 13: // enter + case 27: // escape + e.preventDefault() + break + + case 38: // up arrow + e.preventDefault() + this.prev() + break + + case 40: // down arrow + e.preventDefault() + this.next() + break + } + + e.stopPropagation() + } + + , blur: function (e) { + var that = this + setTimeout(function () { that.hide() }, 150) + } + + , click: function (e) { + e.stopPropagation() + e.preventDefault() + this.select() + } + + , mouseenter: function (e) { + this.$menu.find('.active').removeClass('active') + $(e.currentTarget).addClass('active') + } + + } + + + /* TYPEAHEAD PLUGIN DEFINITION + * =========================== */ + + $.fn.typeaheadRemote = function ( option ) { + return this.each(function () { + var $this = $(this) + , data = $this.data('typeahead') + , options = typeof option == 'object' && option + if (!data) $this.data('typeahead', (data = new TypeaheadRemote(this, options))) + if (typeof option == 'string') data[option]() + }) + } + + $.fn.typeaheadRemote.defaults = { + source: [] + , items: 8 + , menu: '' + , item: '
  • ' + } + + $.fn.typeaheadRemote.Constructor = TypeaheadRemote + + + /* TYPEAHEAD DATA-API + * ================== */ + + $(function () { + $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { + var $this = $(this) + if ($this.data('typeahead')) return + e.preventDefault() + $this.typeaheadRemote($this.data()) + }) + }) + +}( window.jQuery ); diff --git a/assets/CommonBundle/common/js/unserialize.js b/assets/CommonBundle/common/js/unserialize.js new file mode 100644 index 0000000000..03b4551dd1 --- /dev/null +++ b/assets/CommonBundle/common/js/unserialize.js @@ -0,0 +1,171 @@ +function unserialize (data) { + // http://kevin.vanzonneveld.net + // + original by: Arpad Ray (mailto:arpad@php.net) + // + improved by: Pedro Tainha (http://www.pedrotainha.com) + // + bugfixed by: dptr1988 + // + revised by: d3x + // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) + // + input by: Brett Zamir (http://brett-zamir.me) + // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) + // + improved by: Chris + // + improved by: James + // + input by: Martin (http://www.erlenwiese.de/) + // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) + // + improved by: Le Torbi + // + input by: kilops + // + bugfixed by: Brett Zamir (http://brett-zamir.me) + // + input by: Jaroslaw Czarniak + // + improved by: Eli Skeggs + // % note: We feel the main purpose of this function should be to ease the transport of data between php & js + // % note: Aiming for PHP-compatibility, we have to translate objects to arrays + // * example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'); + // * returns 1: ['Kevin', 'van', 'Zonneveld'] + // * example 2: unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'); + // * returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'} + var that = this, + utf8Overhead = function (chr) { + // http://phpjs.org/functions/unserialize:571#comment_95906 + var code = chr.charCodeAt(0); + if (code < 0x0080) { + return 0; + } + if (code < 0x0800) { + return 1; + } + return 2; + }, + error = function (type, msg, filename, line) { + throw new that.window[type](msg, filename, line); + }, + read_until = function (data, offset, stopchr) { + var i = 2, buf = [], chr = data.slice(offset, offset + 1); + + while (chr != stopchr) { + if ((i + offset) > data.length) { + error('Error', 'Invalid'); + } + buf.push(chr); + chr = data.slice(offset + (i - 1), offset + i); + i += 1; + } + return [buf.length, buf.join('')]; + }, + read_chrs = function (data, offset, length) { + var i, chr, buf; + + buf = []; + for (i = 0; i < length; i++) { + chr = data.slice(offset + (i - 1), offset + i); + buf.push(chr); + length -= utf8Overhead(chr); + } + return [buf.length, buf.join('')]; + }, + _unserialize = function (data, offset) { + var dtype, dataoffset, keyandchrs, keys, contig, + length, array, readdata, readData, ccount, + stringlength, i, key, kprops, kchrs, vprops, + vchrs, value, chrs = 0, + typeconvert = function (x) { + return x; + }; + + if (!offset) { + offset = 0; + } + dtype = (data.slice(offset, offset + 1)).toLowerCase(); + + dataoffset = offset + 2; + + switch (dtype) { + case 'i': + typeconvert = function (x) { + return parseInt(x, 10); + }; + readData = read_until(data, dataoffset, ';'); + chrs = readData[0]; + readdata = readData[1]; + dataoffset += chrs + 1; + break; + case 'b': + typeconvert = function (x) { + return parseInt(x, 10) !== 0; + }; + readData = read_until(data, dataoffset, ';'); + chrs = readData[0]; + readdata = readData[1]; + dataoffset += chrs + 1; + break; + case 'd': + typeconvert = function (x) { + return parseFloat(x); + }; + readData = read_until(data, dataoffset, ';'); + chrs = readData[0]; + readdata = readData[1]; + dataoffset += chrs + 1; + break; + case 'n': + readdata = null; + break; + case 's': + ccount = read_until(data, dataoffset, ':'); + chrs = ccount[0]; + stringlength = ccount[1]; + dataoffset += chrs + 2; + + readData = read_chrs(data, dataoffset + 1, parseInt(stringlength, 10)); + chrs = readData[0]; + readdata = readData[1]; + dataoffset += chrs + 2; + if (chrs != parseInt(stringlength, 10) && chrs != readdata.length) { + error('SyntaxError', 'String length mismatch'); + } + break; + case 'a': + readdata = {}; + + keyandchrs = read_until(data, dataoffset, ':'); + chrs = keyandchrs[0]; + keys = keyandchrs[1]; + dataoffset += chrs + 2; + + length = parseInt(keys, 10); + contig = true; + + for (i = 0; i < length; i++) { + kprops = _unserialize(data, dataoffset); + kchrs = kprops[1]; + key = kprops[2]; + dataoffset += kchrs; + + vprops = _unserialize(data, dataoffset); + vchrs = vprops[1]; + value = vprops[2]; + dataoffset += vchrs; + + if (key !== i) + contig = false; + + readdata[key] = value; + } + + if (contig) { + array = new Array(length); + for (i = 0; i < length; i++) + array[i] = readdata[i]; + readdata = array; + } + + dataoffset += 1; + break; + default: + error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype); + break; + } + return [dtype, dataoffset - offset, typeconvert(readdata)]; + } + ; + + return _unserialize((data + ''), 0)[2]; +} \ No newline at end of file diff --git a/module/CudiBundle/Resources/assets/sale/js/barcodeControl.js b/assets/CudiBundle/sale/js/barcodeControl.js similarity index 100% rename from module/CudiBundle/Resources/assets/sale/js/barcodeControl.js rename to assets/CudiBundle/sale/js/barcodeControl.js diff --git a/module/CudiBundle/Resources/assets/sale/js/calculateChange.js b/assets/CudiBundle/sale/js/calculateChange.js similarity index 100% rename from module/CudiBundle/Resources/assets/sale/js/calculateChange.js rename to assets/CudiBundle/sale/js/calculateChange.js diff --git a/module/CudiBundle/Resources/assets/sale/js/collect.js b/assets/CudiBundle/sale/js/collect.js similarity index 100% rename from module/CudiBundle/Resources/assets/sale/js/collect.js rename to assets/CudiBundle/sale/js/collect.js diff --git a/module/CudiBundle/Resources/assets/sale/js/queue.js b/assets/CudiBundle/sale/js/queue.js similarity index 100% rename from module/CudiBundle/Resources/assets/sale/js/queue.js rename to assets/CudiBundle/sale/js/queue.js diff --git a/module/CudiBundle/Resources/assets/sale/js/sale.js b/assets/CudiBundle/sale/js/sale.js similarity index 97% rename from module/CudiBundle/Resources/assets/sale/js/sale.js rename to assets/CudiBundle/sale/js/sale.js index 422cb925e3..2925de846e 100644 --- a/module/CudiBundle/Resources/assets/sale/js/sale.js +++ b/assets/CudiBundle/sale/js/sale.js @@ -115,13 +115,13 @@ $('