From ff4ff15f166d7caeb3b298ce209163c3cc94bf73 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 14 Apr 2016 16:21:12 +0300 Subject: [PATCH] =?UTF-8?q?[SSE]=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=BA=D0=BD=D0=B0=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=B5=D0=BA=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82=D0=B2=D0=B8?= =?UTF-8?q?=D0=B8=20=D1=81=20=D0=BC=D0=B0=D0=BA=D0=B5=D1=82=D0=B0=D0=BC?= =?UTF-8?q?=D0=B8=20https://nct.onlyoffice.com/products/files/#preview/487?= =?UTF-8?q?01.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/lib/component/ColorPaletteExt.js | 213 +++++++++ .../main/resources/less/colorpalette.less | 42 ++ .../main/app/view/AutoFilterDialog.js | 446 ++++++++++++++---- .../main/resources/less/filterdialog.less | 12 +- 4 files changed, 628 insertions(+), 85 deletions(-) create mode 100644 apps/common/main/lib/component/ColorPaletteExt.js diff --git a/apps/common/main/lib/component/ColorPaletteExt.js b/apps/common/main/lib/component/ColorPaletteExt.js new file mode 100644 index 000000000..f1c1f7fae --- /dev/null +++ b/apps/common/main/lib/component/ColorPaletteExt.js @@ -0,0 +1,213 @@ +/** + * ColorPaletteExt.js + * + * Created by Julia Radzhabova on 07/21/15 + * Copyright (c) 2014 Ascensio System SIA. All rights reserved. + * + */ + +if (Common === undefined) + var Common = {}; + +define([ + 'common/main/lib/component/BaseView' +], function () { 'use strict'; + + Common.UI.ColorPaletteExt = Common.UI.BaseView.extend({ + options: { + dynamiccolors: 10, + allowReselect: true, + cls: '', + style: '' + }, + + template: + _.template([ + '
', + '<% var me = this; %>', + '<% $(colors).each(function(num, item) { %>', + '<% if (me.isColor(item)) { %>', + '
', + ' ', + '
', + '<% } else if (me.isTransparent(item)) { %>', + '
', + ' ', + '
', + '<% } else if (me.isEffect(item)) { %>', + '
', + ' ', + '
', + '<% } %>', + '<% }); %>', + '
'].join('')), + + colorRe: /(?:^|\s)color-(.{6})(?:\s|$)/, + selectedCls: 'selected', + + initialize : function(options) { + Common.UI.BaseView.prototype.initialize.call(this, options); + + this.id = this.options.id; + this.cls = this.options.cls; + this.style = this.options.style; + this.colors = this.options.colors || []; + this.value = this.options.value; + + if (this.options.el) + this.render(); + + if (this.options.value) + this.select(this.options.value, true); + }, + + render: function (parentEl) { + var me = this; + + if (!me.rendered) { + this.cmpEl = $(this.template({ + id : this.id, + cls : this.cls, + style : this.style, + colors : this.colors + })); + + if (parentEl) { + this.setElement(parentEl, false); + parentEl.html(this.cmpEl); + } else { + $(this.el).html(this.cmpEl); + } + + this.cmpEl.on('click', _.bind(this.handleClick, this)); + } else { + this.cmpEl = $(this.el); + } + + me.rendered = true; + return this; + }, + + isColor: function(v) { + return typeof(v) == 'string' && (/[0-9A-F]{6}/).test(v); + }, + + isTransparent: function(v) { + return typeof(v) == 'string' && (v=='transparent'); + }, + + isEffect: function(v) { + return (typeof(v) == 'object' && v.effectId !== undefined); + }, + + getColor: function() { + return this.value; + }, + + handleClick: function(e) { + var me = this; + var target = $(e.target).closest('a'); + var color, cmp; + + if (target.length==0) return; + + if (target.hasClass('color-transparent') ) { + $(me.el).find('a.' + me.selectedCls).removeClass(me.selectedCls); + target.addClass(me.selectedCls); + me.value = 'transparent'; + me.trigger('select', me, 'transparent'); + } else { + if (!/^[a-fA-F0-9]{6}$/.test(me.value) || _.indexOf(me.colors, me.value)<0 ) + me.value = false; + + $(me.el).find('a.' + me.selectedCls).removeClass(me.selectedCls); + target.addClass(me.selectedCls); + + color = target[0].className.match(me.colorRe)[1]; + if ( target.hasClass('palette-color-effect') ) { + var effectId = parseInt(target.attr('effectid')); + if (color) { + me.value = color.toUpperCase(); + me.trigger('select', me, {color: color, effectId: effectId}); + } + } else { + if (/#?[a-fA-F0-9]{6}/.test(color)) { + color = /#?([a-fA-F0-9]{6})/.exec(color)[1].toUpperCase(); + me.value = color; + me.trigger('select', me, color); + } + } + } + }, + + select: function(color, suppressEvent) { + var el = $(this.el); + el.find('a.' + this.selectedCls).removeClass(this.selectedCls); + + if (!color) return; + + if (typeof(color) == 'object' ) { + var effectEl; + if (color.effectId !== undefined) { + effectEl = el.find('a[effectid="'+color.effectId+'"]').first(); + if (effectEl.length>0) { + effectEl.addClass(this.selectedCls); + this.value = effectEl[0].className.match(this.colorRe)[1].toUpperCase(); + } else + this.value = false; + } else if (color.effectValue !== undefined) { + effectEl = el.find('a[effectvalue="'+color.effectValue+'"].color-' + color.color.toUpperCase()).first(); + if (effectEl.length>0) { + effectEl.addClass(this.selectedCls); + this.value = effectEl[0].className.match(this.colorRe)[1].toUpperCase(); + } else + this.value = false; + } + } else { + if (/#?[a-fA-F0-9]{6}/.test(color)) { + color = /#?([a-fA-F0-9]{6})/.exec(color)[1].toUpperCase(); + this.value = color; + } + + if (/^[a-fA-F0-9]{6}|transparent$/.test(color) && _.indexOf(this.colors, color)>=0 ) { + if (_.indexOf(this.colors, this.value)<0) this.value = false; + + if (color != this.value || this.options.allowReselect) { + (color == 'transparent') ? el.find('a.color-transparent').addClass(this.selectedCls) : el.find('a.palette-color.color-' + color).first().addClass(this.selectedCls); + this.value = color; + if (suppressEvent !== true) { + this.fireEvent('select', this, color); + } + } + } else { + var co = el.find('#'+color).first(); + if (co.length==0) + co = el.find('a[color="'+color+'"]').first(); + if (co.length>0) { + co.addClass(this.selectedCls); + this.value = color.toUpperCase(); + } + } + } + }, + + updateColors: function(effectcolors) { + if (effectcolors===undefined) return; + + this.colors = effectcolors; + this.cmpEl = $(this.template({ + id : this.id, + cls : this.cls, + style : this.style, + colors : this.colors + })); + $(this.el).html(this.cmpEl); + this.cmpEl.on('click', _.bind(this.handleClick, this)); + }, + + clearSelection: function(suppressEvent) { + $(this.el).find('a.' + this.selectedCls).removeClass(this.selectedCls); + this.value = undefined; + } + }); +}); \ No newline at end of file diff --git a/apps/common/main/resources/less/colorpalette.less b/apps/common/main/resources/less/colorpalette.less index eb32981c4..08cd85b7b 100644 --- a/apps/common/main/resources/less/colorpalette.less +++ b/apps/common/main/resources/less/colorpalette.less @@ -10,4 +10,46 @@ .box-shadow(0 0 0 1px @primary); } } +} + +.palette-color-ext { + padding: 10px; + .palette-color-item { + padding: 0; + border: 1px solid #fff; + display: inline-block; + text-decoration: none; + -moz-outline: 0 none; + outline: 0 none; + cursor: pointer; + vertical-align: middle; + + em { + border: none; + display: block; + + span{ + height: 12px; + width: 12px; + cursor: pointer; + display: block; + border: 1px solid rgba(0, 0, 0, 0.2); + } + } + + &:hover, &.selected { + border-color: #000; + em span { + border-color: #fff; + } + } + } + + .color-transparent { + background-position: @nocolor-offset-x @nocolor-offset-y; + + em span { + border:solid 1px #C0C0C0; + } + } } \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js b/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js index 851a7542b..527526757 100644 --- a/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js +++ b/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js @@ -41,7 +41,8 @@ */ define([ - 'common/main/lib/component/Window' + 'common/main/lib/component/Window', + 'common/main/lib/component/ColorPaletteExt' ], function () { 'use strict'; @@ -66,29 +67,22 @@ define([ this.template = options.template || [ '
', '
', - - '', - - '
', - '
', - '
', - '
', - - '
', - '
', - '
', - '
', - - '
', - '
', - '
', - '
', - + '', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', '
', '
', - '
', - '