3.0 source code

This commit is contained in:
agolybev
2015-04-28 17:59:00 +03:00
parent c69fd34bdd
commit 7b3b2248e5
16311 changed files with 1445974 additions and 3108429 deletions

View File

@@ -1,288 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
Ext.define("SSE.controller.CellEdit", {
extend: "Ext.app.Controller",
views: ["CellInfo"],
refs: [{
ref: "infoBox",
selector: "ssecellinfo"
},
{
ref: "dlgFormula",
selector: "sseformuladialog"
},
{
ref: "formulaList",
selector: "#formulas-list"
},
{
ref: "toolBar",
selector: "ssetoolbar"
},
{
ref: "cellTextBox",
selector: "#infobox-cell-edit"
},
{
ref: "buttonExpand",
selector: "#infobox-cell-multiline-button"
}],
init: function () {
this.control({
"sseformuladialog": {
beforeshow: function (o, eOpts) {},
show: function () {
this.getFormulaList().getSelectionModel().select(0);
this.getDlgFormula().focus(undefined, 100);
},
beforerender: function () {
if (! (this.getFormulaList().getStore().getCount() > 0)) {
this._reloadFormulas();
}
this.getDlgFormula().setGroups(this.arrGroups);
},
hide: function () {
this.getToolBar().fireEvent("editcomplete", this.getToolBar());
}
},
"sseformuladialog #formulas-group-combo": {
select: function (combo, records, eOpts) {
this.getFormulaList().getStore().clearFilter();
if (records[0].data["groupid"] !== "all") {
this.getFormulaList().getStore().filter("group", records[0].data["groupid"]);
}
}
},
"sseformuladialog #formulas-button-ok": {
click: function (btn) {
var data = this.getFormulaList().getSelectionModel().getSelection()[0].data;
this.api.asc_insertFormula(data.func);
this.getDlgFormula().hide();
}
},
"#formulas-list > gridview": {
afterrender: function (cmp) {
this.funcSearch = {
index: 0,
update: false,
word: ""
};
cmp.addElListener("keypress", Ext.bind(this.keypressFormulasList, this));
}
},
"#toolbar-button-insertformula": {
click: function (btn) {
this._handleInsertFormula(btn.menu, {
func: "SUM"
});
}
},
"#toolbar-menu-insertformula": {
click: this._handleInsertFormula
},
"#infobox-cell-edit": {
blur: function (o) {
if (this.api.isTextAreaBlur !== null) {
this.api.isTextAreaBlur = true;
}
},
specialkey: function (o, e) {
if (e.getKey() == e.ENTER && !e.altKey) {
this.api.isTextAreaBlur = null;
}
}
},
"ssecellinfo #infobox-cell-name": {
specialkey: function (o, e) {
if (e.getKey() == e.ENTER) {
this.api.asc_findCell(o.getValue());
this.getInfoBox().fireEvent("editcomplete", this.getInfoBox());
}
}
},
"ssecellinfo": {
resize: function (o, adjWidth, adjHeight, opts) {
this.getButtonExpand()[adjHeight > 23 ? "addCls" : "removeCls"]("button-collapse");
}
},
"ssecellinfo #infobox-cell-multiline-button": {
click: this._expandFormulaField
},
"#field-formula-splitter": {
beforedragstart: function (obj, event) {
return event.currentTarget && !event.currentTarget.disabled;
},
move: function (obj, x, y) {
delete this.getInfoBox().width;
}
}
});
},
setApi: function (o) {
this.api = o;
if (this.api) {
this.api.isTextAreaBlur = false;
this.api.asc_registerCallback("asc_onSelectionNameChanged", Ext.bind(this.updateBox, this));
this.api.asc_registerCallback("asc_onEditCell", Ext.bind(this._onEditCell, this));
this.api.asc_registerCallback("asc_onСoAuthoringDisconnect", Ext.bind(this.onCoAuthoringDisconnect, this));
}
},
updateBox: function (info) {
this.getInfoBox().updateCellInfo(info);
},
_onEditCell: function (state) {
if (state == c_oAscCellEditorState.editStart) {
this.api.isCellEdited = true;
} else {
if (state == c_oAscCellEditorState.editEnd) {
this.api.isCellEdited = false;
}
}
},
_reloadFormulas: function () {
var arrFuncs = [];
this.arrGroups = [];
dlgFormulas.arrayFormula = [];
var groupFuncs, groupName, addGroup;
var qa = this.api.asc_getFormulasInfo();
for (var i = 0; i < qa.length; i++) {
groupName = qa[i].asc_getGroupName();
groupFuncs = qa[i].asc_getFormulasArray();
addGroup = false;
for (var j = 0; j < groupFuncs.length; j++) {
if (addGroup !== true) {
this.arrGroups.push(groupName);
addGroup = true;
}
arrFuncs.push({
group: groupName,
func: groupFuncs[j].asc_getName(),
args: groupFuncs[j].asc_getArguments()
});
dlgFormulas.arrayFormula.push(groupFuncs[j].asc_getName());
}
}
this.getFormulaList().getStore().loadData(arrFuncs);
},
_smoothScrollIntoView: function (element, container) {
var c = Ext.getDom(container) || Ext.getBody().dom,
o = element.getOffsetsTo(c),
t = o[1] + c.scrollTop;
var newCTop = t - c.clientHeight / 2;
if (newCTop < 0) {
newCTop = 0;
}
container.scrollTo("top", newCTop, true);
},
scrollViewToNode: function (dataview, node) {
if (dataview && node) {
var plugin = dataview.getPlugin("scrollpane");
if (plugin) {
var doScroll = new Ext.util.DelayedTask(function () {
plugin.scrollToElement(node, false, true);
});
doScroll.delay(100);
}
}
},
keypressFormulasList: function (event, el) {
if ((new Date().getTime()) - this.funcSearch.presstime > 3000) {
this.funcSearch.word = "";
}
var store = this.getFormulaList().getStore();
var symbol = String.fromCharCode(event.getCharCode());
var index = this.funcSearch.index;
if (/[a-zA-Z]/.test(symbol)) {
this.funcSearch.word += symbol;
this.funcSearch.index = store.find("func", this.funcSearch.word, index);
if (this.funcSearch.index < 0) {
this.funcSearch.word = symbol;
this.funcSearch.index = store.find("func", this.funcSearch.word, index + 1);
}
if (this.funcSearch.index < 0) {
this.funcSearch.index = store.find("func", this.funcSearch.word, 0);
}
if (! (this.funcSearch.index < 0)) {
this.getFormulaList().getSelectionModel().select(this.funcSearch.index);
var row = this.getFormulaList().getView().getNode(this.funcSearch.index);
this.scrollViewToNode(this.getFormulaList(), row);
}
}
this.funcSearch.presstime = new Date().getTime();
},
_handleInsertFormula: function (menu, item, opt) {
if (item.func === "more") {
var me = this;
dlgFormulas.addListener("onmodalresult", function (o, mr, s) {
me.getToolBar().fireEvent("editcomplete", me.getToolBar(), {
checkorder: true
});
Common.component.Analytics.trackEvent("Toolbar", "Insert formula");
},
this, {
single: true
});
dlgFormulas.show();
} else {
if (! (this.getFormulaList().getStore().getCount() > 0)) {
this._reloadFormulas();
}
var index = this.getFormulaList().getStore().findExact("func", item.func);
if (! (index < 0)) {
var record = this.getFormulaList().getStore().getAt(index);
this.api.asc_insertFormula(record.data.func, true);
}
this.getToolBar().fireEvent("editcomplete", this.getToolBar(), {
checkorder: true
});
Common.component.Analytics.trackEvent("ToolBar", "Insert formula");
}
},
_expandFormulaField: function () {
if (this.getInfoBox().getHeight() > 23) {
this.getInfoBox().keep_height = this.getInfoBox().getHeight();
this.getInfoBox().setHeight(23);
this.getButtonExpand().removeCls("button-collapse");
} else {
this.getInfoBox().setHeight(this.getInfoBox().keep_height);
this.getButtonExpand().addCls("button-collapse");
}
},
onCoAuthoringDisconnect: function () {
if (dlgFormulas.isVisible()) {
dlgFormulas.hide();
}
this.getInfoBox().setMode({
isDisconnected: true
});
}
});

View File

@@ -0,0 +1,173 @@
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
define(["core", "spreadsheeteditor/main/app/view/CellEditor"], function (Viewport) {
SSE.Controllers.CellEditor = Backbone.Controller.extend({
views: ["CellEditor"],
events: function () {
return {
"keyup input#ce-cell-name": _.bind(this.onCellName, this),
"keyup textarea#ce-cell-content": _.bind(this.onKeyupCellEditor, this),
"blur textarea#ce-cell-content": _.bind(this.onBlurCellEditor, this),
"click button#ce-btn-expand": _.bind(this.expandEditorField, this),
"click button#ce-func-label": _.bind(this.onInsertFunction, this)
};
},
initialize: function () {
this.addListeners({
"CellEditor": {},
"Viewport": {
"layout:resizedrag": _.bind(this.onLayoutResize, this)
}
});
},
setApi: function (api) {
this.api = api;
this.api.isCEditorFocused = false;
this.api.asc_registerCallback("asc_onSelectionNameChanged", _.bind(this.onApiCellSelection, this));
this.api.asc_registerCallback("asc_onEditCell", _.bind(this.onApiEditCell, this));
this.api.asc_registerCallback("asc_onСoAuthoringDisconnect", _.bind(this.onApiDisconnect, this));
Common.NotificationCenter.on("api:disconnect", _.bind(this.onApiDisconnect, this));
Common.NotificationCenter.on("cells:range", _.bind(this.onCellsRange, this));
return this;
},
setMode: function (mode) {
this.mode = mode;
this.editor.$btnfunc[this.mode.isEdit ? "removeClass" : "addClass"]("disabled");
},
onLaunch: function () {
this.editor = this.createView("CellEditor", {
el: "#cell-editing-box"
}).render();
this.bindViewEvents(this.editor, this.events);
this.editor.$el.parent().find(".after").css({
zIndex: "4"
});
var me = this;
$("#ce-cell-content").keydown(function (e) {
if (Common.UI.Keys.RETURN === e.keyCode || Common.UI.Keys.ESC === e.keyCode) {
me.api.asc_enableKeyEvents(true);
}
});
},
onApiEditCell: function (state) {
if (state == c_oAscCellEditorState.editStart) {
this.api.isCellEdited = true;
} else {
if (state == c_oAscCellEditorState.editEnd) {
this.api.isCellEdited = false;
this.api.isCEditorFocused = false;
}
}
},
onApiCellSelection: function (info) {
this.editor.updateCellInfo(info);
},
onApiDisconnect: function () {
this.mode.isEdit = false;
var controller = this.getApplication().getController("FormulaDialog");
if (controller) {
controller.hideDialog();
}
if (!this.mode.isEdit) {
$("#ce-func-label", this.editor.el).addClass("disabled");
}
},
onCellsRange: function (status) {
var isRangeSelection = (status != c_oAscSelectionDialogType.None);
if (isRangeSelection) {
this.editor.$cellname.attr("disabled", "disabled");
this.editor.$btnfunc["addClass"]("disabled");
} else {
this.editor.$cellname.removeAttr("disabled");
this.editor.$btnfunc["removeClass"]("disabled");
}
},
onLayoutResize: function (o, r) {
if (r == "cell:edit") {
if (this.editor.$el.height() > 19) {
if (!this.editor.$btnexpand.hasClass("btn-collapse")) {
this.editor.$btnexpand["addClass"]("btn-collapse");
}
} else {
this.editor.$btnexpand["removeClass"]("btn-collapse");
}
}
},
onCellName: function (e) {
if (e.keyCode == Common.UI.Keys.RETURN) {
var name = this.editor.$cellname.val();
if (name && name.length) {
this.api.asc_findCell(name);
}
Common.NotificationCenter.trigger("edit:complete", this.editor);
}
},
onBlurCellEditor: function () {
if (this.api.isCEditorFocused == "clear") {
this.api.isCEditorFocused = undefined;
} else {
if (this.api.isCellEdited) {
this.api.isCEditorFocused = true;
}
}
},
onKeyupCellEditor: function (e) {
if (e.keyCode == Common.UI.Keys.RETURN && !e.altKey) {
this.api.isCEditorFocused = "clear";
}
},
expandEditorField: function () {
if (this.editor.$el.height() > 19) {
this.editor.keep_height = this.editor.$el.height();
this.editor.$el.height(19);
this.editor.$btnexpand["removeClass"]("btn-collapse");
} else {
this.editor.$el.height(this.editor.keep_height || 74);
this.editor.$btnexpand["addClass"]("btn-collapse");
}
Common.NotificationCenter.trigger("layout:changed", "celleditor");
Common.NotificationCenter.trigger("edit:complete", this.editor, {
restorefocus: true
});
},
onInsertFunction: function () {
if (this.mode.isEdit && !this.editor.$btnfunc["hasClass"]("disabled")) {
var controller = this.getApplication().getController("FormulaDialog");
if (controller) {
$("#ce-func-label", this.editor.el).blur();
this.api.asc_enableKeyEvents(false);
controller.showDialog();
}
}
}
});
});

View File

@@ -1,164 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
var url_create_template = "{0}?title={1}&template={2}&action=create&doctype=spreadsheet";
var url_create_new = "{0}?title={1}&action=create&doctype=spreadsheet";
Ext.define("SSE.controller.CreateFile", {
extend: "Ext.app.Controller",
uses: ["SSE.view.OpenDialog"],
views: ["CreateFile"],
stores: ["FileTemplates"],
refs: [{
ref: "filePanel",
selector: "ssefile"
}],
init: function () {
Common.Gateway.on("init", Ext.bind(this.loadConfig, this));
this.control({
"ssecreatenew": {
afterrender: Ext.bind(this.onRenderView, this, {
single: true
})
},
"ssecreatenew dataview": {
itemclick: this.onTemplateClick
},
"ssefile #file-button-createnew": {
click: function (el, event) {
var templates = this.getFileTemplatesStore();
if (! (templates && templates.getCount())) {
this.onBlankDocClick(event, el);
}
}
},
"ssefile button[docType]": {
click: this.clickBtnDownloadAs
},
"ssefile button[docType=0]": {
click: this.clickBtnDownloadAs
}
});
},
loadConfig: function (data) {
var templates = this.getFileTemplatesStore();
if (templates) {
templates.removeAll();
if (data && data.config) {
this.createUrl = data.config.createUrl;
this.nativeApp = data.config.nativeApp;
if (data.config.templates) {
templates.add(data.config.templates);
}
}
}
},
onRenderView: function () {
var btnBlankDocument = Ext.fly("id-create-blank-document");
if (btnBlankDocument) {
btnBlankDocument.addClsOnOver("over");
btnBlankDocument.on("click", this.onBlankDocClick, this);
}
},
onBlankDocClick: function (event, el) {
var filePanel = this.getFilePanel();
if (filePanel) {
filePanel.closeMenu();
}
if (this.nativeApp === true) {
this.api.asc_openNewDocument();
} else {
if (this.createUrl && this.createUrl.length) {
var newDocumentPage = window.open(Ext.String.format(url_create_new, this.createUrl, this.newDocumentTitle));
if (newDocumentPage) {
newDocumentPage.focus();
}
}
}
Common.component.Analytics.trackEvent("Create New", "Blank");
},
onTemplateClick: function (view, record, item, index, e) {
var filePanel = this.getFilePanel();
if (filePanel) {
filePanel.closeMenu();
}
if (this.nativeApp === true) {
this.api.asc_openNewDocument(record.data.name);
} else {
if (this.createUrl && this.createUrl.length) {
var newDocumentPage = window.open(Ext.String.format(url_create_template, this.createUrl, this.newDocumentTitle, record.data.name));
if (newDocumentPage) {
newDocumentPage.focus();
}
}
}
Common.component.Analytics.trackEvent("Create New");
},
setApi: function (o) {
this.api = o;
return this;
},
clickBtnDownloadAs: function (btn) {
if (this.api) {
if (this.api.asc_drawingObjectsExist() && btn.docType != c_oAscFileType.XLSX) {
Ext.create("Ext.window.MessageBox", {
buttonText: {
ok: "OK",
yes: "Yes",
no: "No",
cancel: this.textCancel
}
}).show({
title: this.textWarning,
msg: this.warnDownloadAs,
icon: Ext.Msg.QUESTION,
buttons: Ext.Msg.OKCANCEL,
scope: this,
fn: function (res, text) {
if (res == "ok") {
this.getFilePanel().fireEvent("downloadas");
this.api.asc_DownloadAs(btn.docType);
this.getFilePanel().closeMenu();
}
}
});
} else {
this.getFilePanel().fireEvent("downloadas");
this.api.asc_DownloadAs(btn.docType);
this.getFilePanel().closeMenu();
}
}
Common.component.Analytics.trackEvent("Download As", String(btn.docType));
},
warnDownloadAs: "If you continue saving in this format all the charts and images will be lost.<br>Are you sure you want to continue?",
newDocumentTitle : "Unnamed document",
textWarning: "Warning",
textCancel: "Cancel"
});

View File

@@ -0,0 +1,128 @@
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
define(["core", "spreadsheeteditor/main/app/collection/FormulaGroups", "spreadsheeteditor/main/app/view/FormulaDialog"], function () {
SSE.Controllers = SSE.Controllers || {};
SSE.Controllers.FormulaDialog = Backbone.Controller.extend({
models: [],
views: ["FormulaDialog"],
collections: ["FormulaGroups"],
initialize: function () {},
setApi: function (api) {
this.api = api;
if (this.formulasGroups && this.api) {
this.loadingFormulas();
var me = this;
this.formulas = new SSE.Views.FormulaDialog({
api: this.api,
toolclose: "hide",
formulasGroups: this.formulasGroups,
handler: function (func) {
if (func && me.api) {
me.api.asc_insertFormula(func);
}
}
});
this.formulas.on({
"hide": function () {
if (me.api) {
me.api.asc_enableKeyEvents(true);
}
}
});
}
return this;
},
onLaunch: function () {
this.formulasGroups = this.getApplication().getCollection("FormulaGroups");
},
showDialog: function () {
if (this.formulas) {
this.formulas.show();
}
},
hideDialog: function () {
if (this.formulas && this.formulas.isVisible()) {
this.formulas.hide();
}
},
loadingFormulas: function () {
var i = 0,
j = 0,
ascGroupName, ascFunctions, functions, store = this.formulasGroups,
formulaGroup = null,
index = 0,
funcInd = 0,
info = null,
allFunctions = [],
allFunctionsGroup = null;
if (store) {
allFunctionsGroup = new SSE.Models.FormulaGroup({
name: "All",
index: index,
store: store
});
if (allFunctionsGroup) {
index += 1;
store.push(allFunctionsGroup);
info = this.api.asc_getFormulasInfo();
for (i = 0; i < info.length; i += 1) {
ascGroupName = info[i].asc_getGroupName();
ascFunctions = info[i].asc_getFormulasArray();
formulaGroup = new SSE.Models.FormulaGroup({
name: ascGroupName,
index: index,
store: store
});
index += 1;
functions = [];
for (j = 0; j < ascFunctions.length; j += 1) {
var func = new SSE.Models.FormulaModel({
index: funcInd,
group: ascGroupName,
name: ascFunctions[j].asc_getName(),
args: ascFunctions[j].asc_getArguments()
});
funcInd += 1;
functions.push(func);
allFunctions.push(func);
}
formulaGroup.set("functions", functions);
store.push(formulaGroup);
}
allFunctionsGroup.set("functions", _.sortBy(allFunctions, function (model) {
return model.get("name");
}));
}
}
}
});
});

View File

@@ -0,0 +1,571 @@
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
define(["core", "common/main/lib/util/Shortcuts", "spreadsheeteditor/main/app/view/LeftMenu", "spreadsheeteditor/main/app/view/FileMenu"], function () {
SSE.Controllers.LeftMenu = Backbone.Controller.extend(_.extend({
views: ["LeftMenu", "FileMenu"],
initialize: function () {
this.addListeners({
"Common.Views.Chat": {
"hide": _.bind(this.onHideChat, this)
},
"Statusbar": {
"click:users": _.bind(this.clickStatusbarUsers, this)
},
"LeftMenu": {
"file:show": _.bind(this.fileShowHide, this, true),
"file:hide": _.bind(this.fileShowHide, this, false),
"comments:show": _.bind(this.commentsShowHide, this, true),
"comments:hide": _.bind(this.commentsShowHide, this, false),
},
"Common.Views.About": {
"show": _.bind(this.aboutShowHide, this, true),
"hide": _.bind(this.aboutShowHide, this, false)
},
"FileMenu": {
"item:click": _.bind(this.clickMenuFileItem, this),
"saveas:format": _.bind(this.clickSaveAsFormat, this),
"settings:apply": _.bind(this.applySettings, this),
"create:new": _.bind(this.onCreateNew, this),
"recent:open": _.bind(this.onOpenRecent, this)
},
"Toolbar": {
"file:settings": _.bind(this.clickToolbarSettings, this)
},
"SearchDialog": {
"hide": _.bind(this.onSearchDlgHide, this),
"search:back": _.bind(this.onQuerySearch, this, "back"),
"search:next": _.bind(this.onQuerySearch, this, "next"),
"search:replace": _.bind(this.onQueryReplace, this),
"search:replaceall": _.bind(this.onQueryReplaceAll, this)
}
});
},
onLaunch: function () {
this.leftMenu = this.createView("LeftMenu").render();
this.leftMenu.btnSearch.on("toggle", _.bind(this.onMenuSearch, this));
Common.util.Shortcuts.delegateShortcuts({
shortcuts: {
"command+shift+s,ctrl+shift+s": _.bind(this.onShortcut, this, "save"),
"command+f,ctrl+f": _.bind(this.onShortcut, this, "search"),
"command+h,ctrl+h": _.bind(this.onShortcut, this, "replace"),
"alt+f": _.bind(this.onShortcut, this, "file"),
"esc": _.bind(this.onShortcut, this, "escape"),
"ctrl+alt+q": _.bind(this.onShortcut, this, "chat"),
"command+shift+h,ctrl+shift+h": _.bind(this.onShortcut, this, "comments"),
"f1": _.bind(this.onShortcut, this, "help")
}
});
Common.util.Shortcuts.suspendEvents();
var me = this;
this.leftMenu.$el.find("button").each(function () {
$(this).on("keydown", function (e) {
if (Common.UI.Keys.RETURN === e.keyCode || Common.UI.Keys.SPACE === e.keyCode) {
me.leftMenu.btnFile.toggle(false);
me.leftMenu.btnAbout.toggle(false);
this.blur();
e.preventDefault();
me.api.asc_enableKeyEvents(true);
}
});
});
},
setApi: function (api) {
this.api = api;
this.api.asc_registerCallback("asc_onRenameCellTextEnd", _.bind(this.onRenameText, this));
this.api.asc_registerCallback("asc_onСoAuthoringDisconnect", _.bind(this.onApiServerDisconnect, this));
Common.NotificationCenter.on("api:disconnect", _.bind(this.onApiServerDisconnect, this));
if (this.mode.canCoAuthoring) {
this.api.asc_registerCallback("asc_onCoAuthoringChatReceiveMessage", _.bind(this.onApiChatMessage, this));
}
if (!this.mode.isEditDiagram) {
this.api.asc_registerCallback("asc_onEditCell", _.bind(this.onApiEditCell, this));
}
this.leftMenu.getMenu("file").setApi(api);
return this;
},
setMode: function (mode) {
this.mode = mode;
this.leftMenu.setMode(mode);
this.leftMenu.getMenu("file").setMode(mode);
return this;
},
createDelayedElements: function () {
if (this.mode.canCoAuthoring) {
this.leftMenu.btnComments[this.mode.isEdit ? "show" : "hide"]();
this.leftMenu.btnChat.show();
this.leftMenu.setOptionsPanel("chat", this.getApplication().getController("Common.Controllers.Chat").getView("Common.Views.Chat"));
this.leftMenu.setOptionsPanel("comment", this.getApplication().getController("Common.Controllers.Comments").getView("Common.Views.Comments"));
} else {
this.leftMenu.btnChat.hide();
this.leftMenu.btnComments.hide();
}
Common.util.Shortcuts.resumeEvents();
if (!this.mode.isEditDiagram) {
Common.NotificationCenter.on("cells:range", _.bind(this.onCellsRange, this));
}
return this;
},
clickMenuFileItem: function (menu, action, isopts) {
var close_menu = true;
switch (action) {
case "back":
break;
case "save":
this.api.asc_Save();
break;
case "print":
this.api.asc_Print();
break;
case "exit":
Common.Gateway.goBack();
break;
case "edit":
Common.Gateway.requestEditRights();
break;
case "new":
if (isopts) {
close_menu = false;
} else {
this.onCreateNew(undefined, "blank");
}
break;
default:
close_menu = false;
}
if (close_menu) {
menu.hide();
this.leftMenu.btnFile.toggle(false, true);
}
},
clickSaveAsFormat: function (menu, format) {
if (format == c_oAscFileType.CSV || format != c_oAscFileType.XLSX && this.api.asc_drawingObjectsExist()) {
Common.UI.warning({
closable: false,
title: this.textWarning,
msg: this.warnDownloadAs,
buttons: ["ok", "cancel"],
callback: _.bind(function (btn) {
if (btn == "ok") {
this.api.asc_DownloadAs(format);
menu.hide();
this.leftMenu.btnFile.toggle(false, true);
}
},
this)
});
} else {
this.api.asc_DownloadAs(format);
menu.hide();
this.leftMenu.btnFile.toggle(false, true);
}
},
applySettings: function (menu) {
this.api.asc_setFontRenderingMode(parseInt(window.localStorage.getItem("sse-settings-fontrender")));
var value = window.localStorage.getItem("sse-settings-livecomment");
(!(value !== null && parseInt(value) == 0)) ? this.api.asc_showComments() : this.api.asc_hideComments();
if (this.mode.canAutosave) {
value = window.localStorage.getItem("sse-settings-autosave");
this.api.asc_setAutoSaveGap(parseInt(value));
}
menu.hide();
this.leftMenu.btnFile.toggle(false, true);
},
onCreateNew: function (menu, type) {
if (this.mode.nativeApp === true) {
this.api.asc_openNewDocument(type == "blank" ? "" : type);
} else {
var newDocumentPage = window.open(_.template("<%= url %>?title=<%= title %>" + '<% if (doctype != "blank") { %>&template=<%= doctype %><% } %>' + "&action=create&doctype=spreadsheet", {
url: this.mode.createUrl,
title: this.newDocumentTitle,
doctype: type
}));
if (newDocumentPage) {
newDocumentPage.focus();
}
}
if (menu) {
menu.hide();
this.leftMenu.btnFile.toggle(false, true);
}
},
onOpenRecent: function (menu, url) {
if (menu) {
menu.hide();
this.leftMenu.btnFile.toggle(false, true);
}
var recentDocPage = window.open(url);
if (recentDocPage) {
recentDocPage.focus();
}
Common.component.Analytics.trackEvent("Open Recent");
},
clickToolbarSettings: function (obj) {
if (this.leftMenu.btnFile.pressed && this.leftMenu.btnFile.panel.active == "opts") {
this.leftMenu.close();
} else {
this.leftMenu.showMenu("file:opts");
}
},
clickStatusbarUsers: function () {
if (this.mode.canCoAuthoring) {
if (this.leftMenu.btnChat.pressed) {
this.leftMenu.close();
} else {
this.leftMenu.showMenu("chat");
}
}
},
onHideChat: function () {
$(this.leftMenu.btnChat.el).blur();
Common.NotificationCenter.trigger("layout:changed", "leftmenu");
},
onQuerySearch: function (d, w, opts) {
if (opts.textsearch && opts.textsearch.length) {
var options = this.dlgSearch.findOptions;
options.asc_setFindWhat(opts.textsearch);
options.asc_setScanForward(d != "back");
options.asc_setIsMatchCase(opts.matchcase);
options.asc_setIsWholeCell(opts.matchword);
options.asc_setScanOnOnlySheet(this.dlgSearch.menuWithin.menu.items[0].checked);
options.asc_setScanByRows(this.dlgSearch.menuSearch.menu.items[0].checked);
options.asc_setLookIn(this.dlgSearch.menuLookin.menu.items[0].checked ? c_oAscFindLookIn.Formulas : c_oAscFindLookIn.Value);
if (!this.api.asc_findText(options)) {
var me = this;
Common.UI.info({
msg: this.textNoTextFound,
callback: function () {
me.dlgSearch.focus();
}
});
}
}
},
onQueryReplace: function (w, opts) {
if (!_.isEmpty(opts.textsearch) && !_.isEmpty(opts.textreplace)) {
this.api.isReplaceAll = false;
var options = this.dlgSearch.findOptions;
options.asc_setFindWhat(opts.textsearch);
options.asc_setReplaceWith(opts.textreplace);
options.asc_setIsMatchCase(opts.matchcase);
options.asc_setIsWholeCell(opts.matchword);
options.asc_setScanOnOnlySheet(this.dlgSearch.menuWithin.menu.items[0].checked);
options.asc_setScanByRows(this.dlgSearch.menuSearch.menu.items[0].checked);
options.asc_setLookIn(this.dlgSearch.menuLookin.menu.items[0].checked ? c_oAscFindLookIn.Formulas : c_oAscFindLookIn.Value);
options.asc_setIsReplaceAll(false);
this.api.asc_replaceText(options);
}
},
onQueryReplaceAll: function (w, opts) {
if (!_.isEmpty(opts.textsearch) && !_.isEmpty(opts.textreplace)) {
this.api.isReplaceAll = true;
var options = this.dlgSearch.findOptions;
options.asc_setFindWhat(opts.textsearch);
options.asc_setReplaceWith(opts.textreplace);
options.asc_setIsMatchCase(opts.matchcase);
options.asc_setIsWholeCell(opts.matchword);
options.asc_setScanOnOnlySheet(this.dlgSearch.menuWithin.menu.items[0].checked);
options.asc_setScanByRows(this.dlgSearch.menuSearch.menu.items[0].checked);
options.asc_setLookIn(this.dlgSearch.menuLookin.menu.items[0].checked ? c_oAscFindLookIn.Formulas : c_oAscFindLookIn.Value);
options.asc_setIsReplaceAll(true);
this.api.asc_replaceText(options);
}
},
showSearchDlg: function (show, action) {
if (!this.dlgSearch) {
var menuWithin = new Common.UI.MenuItem({
caption: this.textWithin,
menu: new Common.UI.Menu({
menuAlign: "tl-tr",
items: [{
caption: this.textSheet,
toggleGroup: "searchWithih",
checkable: true,
checked: true
},
{
caption: this.textWorkbook,
toggleGroup: "searchWithih",
checkable: true,
checked: false
}]
})
});
var menuSearch = new Common.UI.MenuItem({
caption: this.textSearch,
menu: new Common.UI.Menu({
menuAlign: "tl-tr",
items: [{
caption: this.textByRows,
toggleGroup: "searchByrows",
checkable: true,
checked: true
},
{
caption: this.textByColumns,
toggleGroup: "searchByrows",
checkable: true,
checked: false
}]
})
});
var menuLookin = new Common.UI.MenuItem({
caption: this.textLookin,
menu: new Common.UI.Menu({
menuAlign: "tl-tr",
items: [{
caption: this.textFormulas,
toggleGroup: "searchLookin",
checkable: true,
checked: true
},
{
caption: this.textValues,
toggleGroup: "searchLookin",
checkable: true,
checked: false
}]
})
});
this.dlgSearch = (new Common.UI.SearchDialog({
matchcase: true,
matchword: true,
matchwordstr: this.textItemEntireCell,
markresult: false,
extraoptions: [menuWithin, menuSearch, menuLookin]
}));
this.dlgSearch.menuWithin = menuWithin;
this.dlgSearch.menuSearch = menuSearch;
this.dlgSearch.menuLookin = menuLookin;
this.dlgSearch.findOptions = new Asc.asc_CFindOptions();
}
if (show) {
var mode = this.mode.isEdit ? (action || undefined) : "no-replace";
if (this.dlgSearch.isVisible()) {
this.dlgSearch.setMode(mode);
this.dlgSearch.focus();
} else {
this.dlgSearch.show(mode);
}
this.api.asc_closeCellEditor();
} else {
this.dlgSearch["hide"]();
}
},
onMenuSearch: function (obj, show) {
this.showSearchDlg(show);
},
onSearchDlgHide: function () {
this.leftMenu.btnSearch.toggle(false, true);
$(this.leftMenu.btnSearch.el).blur();
this.api.asc_enableKeyEvents(true);
},
onRenameText: function (found, replaced) {
var me = this;
if (this.api.isReplaceAll) {
Common.UI.info({
msg: (found) ? ((!found - replaced) ? Common.Utils.String.format(this.textReplaceSuccess, replaced) : Common.Utils.String.format(this.textReplaceSkipped, found - replaced)) : this.textNoTextFound,
callback: function () {
me.dlgSearch.focus();
}
});
} else {
var sett = this.dlgSearch.getSettings();
var options = this.dlgSearch.findOptions;
options.asc_setFindWhat(sett.textsearch);
options.asc_setScanForward(true);
options.asc_setIsMatchCase(sett.matchcase);
options.asc_setIsWholeCell(sett.matchword);
options.asc_setScanOnOnlySheet(this.dlgSearch.menuWithin.menu.items[0].checked);
options.asc_setScanByRows(this.dlgSearch.menuSearch.menu.items[0].checked);
options.asc_setLookIn(this.dlgSearch.menuLookin.menu.items[0].checked ? c_oAscFindLookIn.Formulas : c_oAscFindLookIn.Value);
if (!me.api.asc_findText(options)) {
Common.UI.info({
msg: this.textNoTextFound,
callback: function () {
me.dlgSearch.focus();
}
});
}
}
},
onApiServerDisconnect: function () {
this.mode.isEdit = false;
this.leftMenu.close();
this.leftMenu.btnComments.setDisabled(true);
this.leftMenu.btnChat.setDisabled(true);
this.leftMenu.getMenu("file").setMode({
isDisconnected: true
});
if (this.dlgSearch) {
this.leftMenu.btnSearch.toggle(false, true);
this.dlgSearch["hide"]();
}
},
onApiChatMessage: function () {
this.leftMenu.markCoauthOptions();
},
commentsShowHide: function (state) {
if (this.api) {
var value = window.localStorage.getItem("sse-settings-livecomment");
if (value !== null && parseInt(value) == 0) {
(state) ? this.api.asc_showComments() : this.api.asc_hideComments();
}
if (state) {
this.getApplication().getController("Common.Controllers.Comments").focusOnInput();
}
this.api.asc_enableKeyEvents(!state);
if (!state) {
$(this.leftMenu.btnComments.el).blur();
}
}
},
fileShowHide: function (state) {
if (this.api) {
this.api.asc_closeCellEditor();
this.api.asc_enableKeyEvents(!state);
if (!state) {
$(this.leftMenu.btnFile.el).blur();
}
}
},
aboutShowHide: function (state) {
if (this.api) {
this.api.asc_closeCellEditor();
this.api.asc_enableKeyEvents(!state);
if (!state) {
$(this.leftMenu.btnAbout.el).blur();
}
}
},
onShortcut: function (s, e) {
if (this.mode.isEditDiagram && s != "escape") {
return false;
}
switch (s) {
case "replace":
case "search":
if (!this.leftMenu.btnSearch.isDisabled()) {
Common.UI.Menu.Manager.hideAll();
this.showSearchDlg(true, s);
this.leftMenu.btnSearch.toggle(true, true);
this.leftMenu.btnFile.toggle(false);
this.leftMenu.btnAbout.toggle(false);
}
return false;
case "save":
if (this.mode.canDownload && !this.leftMenu.btnFile.isDisabled()) {
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu("file:saveas");
}
return false;
case "help":
if (!this.leftMenu.btnFile.isDisabled()) {
Common.UI.Menu.Manager.hideAll();
this.api.asc_closeCellEditor();
this.leftMenu.showMenu("file:help");
}
return false;
case "file":
if (!this.leftMenu.btnFile.isDisabled()) {
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu("file");
}
return false;
case "escape":
var statusbar = SSE.getController("Statusbar");
var menu_opened = statusbar.statusbar.$el.find('.open > [data-toggle="dropdown"]');
if (menu_opened.length) {
$.fn.dropdown.Constructor.prototype.keydown.call(menu_opened[0], e);
return false;
}
if (this.leftMenu.btnFile.pressed || this.leftMenu.btnAbout.pressed || $(e.target).parents("#left-menu").length && this.api.isCellEdited !== true) {
this.leftMenu.close();
Common.NotificationCenter.trigger("layout:changed", "leftmenu");
return false;
}
if (this.mode.isEditDiagram) {
menu_opened = $(document.body).find(".open > .dropdown-menu");
if (!this.api.isCellEdited && !menu_opened.length) {
Common.Gateway.internalMessage("shortcut", {
key: "escape"
});
return false;
}
}
break;
case "chat":
if (this.mode.canCoAuthoring) {
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu("chat");
}
return false;
case "comments":
if (this.mode.canCoAuthoring && this.mode.isEdit) {
Common.UI.Menu.Manager.hideAll();
this.leftMenu.showMenu("comments");
this.getApplication().getController("Common.Controllers.Comments").focusOnInput();
}
return false;
}
},
onCellsRange: function (status) {
var isRangeSelection = (status != c_oAscSelectionDialogType.None);
this.leftMenu.btnFile.setDisabled(isRangeSelection);
this.leftMenu.btnAbout.setDisabled(isRangeSelection);
this.leftMenu.btnSearch.setDisabled(isRangeSelection);
},
onApiEditCell: function (state) {
var isEditFormula = (state == c_oAscCellEditorState.editFormula);
this.leftMenu.btnFile.setDisabled(isEditFormula);
this.leftMenu.btnAbout.setDisabled(isEditFormula);
this.leftMenu.btnSearch.setDisabled(isEditFormula);
},
textNoTextFound: "Text not found",
newDocumentTitle: "Unnamed document",
textItemEntireCell: "Entire cell contents",
requestEditRightsText: "Requesting editing rights...",
textReplaceSuccess: "Search has been done. {0} occurrences have been replaced",
textReplaceSkipped: "The replacement has been made. {0} occurrences were skipped.",
warnDownloadAs: "If you continue saving in this format all features except the text will be lost.<br>Are you sure you want to continue?",
textWarning : "Warning",
textSheet: "Sheet",
textWorkbook: "Workbook",
textByColumns: "By columns",
textByRows: "By rows",
textFormulas: "Formulas",
textValues: "Values",
textWithin: "Within",
textSearch: "Search",
textLookin: "Look in"
},
SSE.Controllers.LeftMenu || {}));
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,382 +1,391 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
Ext.define("SSE.controller.Print", {
extend: "Ext.app.Controller",
uses: ["SSE.view.DocumentStatusInfo", "SSE.view.PrintSettings"],
views: ["MainSettingsPrint"],
refs: [{
ref: "toolbar",
selector: "ssetoolbar"
},
{
ref: "printAdvanced",
selector: "ssemainsettingsprint"
}],
init: function () {
this.adjPrintParams = new Asc.asc_CAdjustPrint();
this.adjPrintParams.asc_setPrintType(c_oAscPrintType.ActiveSheets);
this.adjPrintParams.asc_setLayoutPageType(c_oAscLayoutPageType.FitToWidth);
this.control({
"documentstatusinfo": {
"updatesheetsinfo": function () {
this.isFillSheets = false;
this.diffParams = {};
}
},
"ssemainsettingsprint": {
show: function () {
if (!this.isFillSheets) {
this.isFillSheets = true;
this.updateSettings();
}
if (!this.isUpdatedSettings) {
this.isUpdatedSettings = true;
this.getPrintAdvanced().cmbSheet.select(this.getPrintAdvanced().cmbSheet.getStore().findRecord("sheetindex", this.api.asc_getActiveWorksheetIndex()));
}
}
},
"sseprintsettings": {
onmodalresult: this.closePrintSettings
},
"#advsettings-print-combo-sheets": {
change: this.comboSheetsChange
},
"#advsettings-print-button-save": {
click: this.querySavePrintSettings
},
"#toolbar-menuitem-print-options": {
click: this.openPrintSettings
},
"#dialog-print-options-ok": {
click: this.queryClosePrintSettings
},
"#dialog-printoptions-grouprange": {
change: function (obj, newvalue, oldvalue, opts) {
if (typeof(newvalue.printrange) == "number") {
var panel = obj.up("window");
if (newvalue.printrange == c_oAscPrintType.EntireWorkbook) {
this.indeterminatePageOptions(panel);
} else {
if (obj.lastCheckedRange == c_oAscPrintType.EntireWorkbook) {
this.fillPageOptions(panel, this.api.asc_getPageOptions());
}
}
obj.lastCheckedRange = newvalue.printrange;
}
}
}
});
},
setApi: function (o) {
this.api = o;
},
updateSettings: function () {
var panel = this.getPrintAdvanced();
panel.cmbSheet.getStore().removeAll();
var wc = this.api.asc_getWorksheetsCount(),
i = -1;
var items = [{
sheetname: this.strAllSheets,
sheetindex: -255
}];
while (++i < wc) {
if (!this.api.asc_isWorksheetHidden(i)) {
items.push({
sheetname: this.api.asc_getWorksheetName(i).replace(/\s/g, "&nbsp;"),
sheetindex: i
});
}
}
panel.cmbSheet.getStore().loadData(items);
},
comboSheetsChange: function (combo, newvalue, oldvalue, eopts) {
var panel = this.getPrintAdvanced();
if (newvalue == -255) {
this.indeterminatePageOptions(panel);
} else {
this.fillPageOptions(panel, this.api.asc_getPageOptions(newvalue));
}
},
isDiffRefill: function () {
for (var item in this.diffParams) {
if (this.diffParams[item] == undefined) {
return true;
}
}
return item == undefined;
},
indeterminatePageOptions: function (panel) {
if (this.isDiffRefill()) {
var wc = this.api.asc_getWorksheetsCount();
if (wc == 1) {
this.diffParams.orientation = false;
this.diffParams.size = false;
this.diffParams.headings = false;
this.diffParams.grid = false;
this.diffParams.margintop = false;
this.diffParams.marginright = false;
this.diffParams.marginbottom = false;
this.diffParams.marginleft = false;
} else {
var index = 0;
var opts = this.api.asc_getPageOptions(index),
opts_next;
while (++index < wc) {
opts_next = this.api.asc_getPageOptions(index);
if (this.diffParams.orientation == undefined) {
this.diffParams.orientation = opts.asc_getPageSetup().asc_getOrientation() != opts_next.asc_getPageSetup().asc_getOrientation();
}
if (this.diffParams.size == undefined) {
this.diffParams.size = (opts.asc_getPageSetup().asc_getWidth() != opts_next.asc_getPageSetup().asc_getWidth() || opts.asc_getPageSetup().asc_getHeight() != opts_next.asc_getPageSetup().asc_getHeight());
}
if (this.diffParams.headings == undefined) {
this.diffParams.headings = opts.asc_getHeadings() != opts_next.asc_getHeadings();
}
if (this.diffParams.grid == undefined) {
this.diffParams.grid = opts.asc_getGridLines() != opts_next.asc_getGridLines();
}
if (this.diffParams.margintop == undefined) {
this.diffParams.margintop = opts.asc_getPageMargins().asc_getTop() != opts_next.asc_getPageMargins().asc_getTop();
}
if (this.diffParams.marginright == undefined) {
this.diffParams.marginright = opts.asc_getPageMargins().asc_getRight() != opts_next.asc_getPageMargins().asc_getRight();
}
if (this.diffParams.marginbottom == undefined) {
this.diffParams.marginbottom = opts.asc_getPageMargins().asc_getBottom() != opts_next.asc_getPageMargins().asc_getBottom();
}
if (this.diffParams.marginleft == undefined) {
this.diffParams.marginleft = opts.asc_getPageMargins().asc_getLeft() != opts_next.asc_getPageMargins().asc_getLeft();
}
}
}
}
if (this.diffParams.orientation) {
panel.cmbPaperOrientation.setValue("-");
}
if (this.diffParams.size) {
panel.cmbPaperSize.setValue("-");
}
if (this.diffParams.margintop) {
panel.spnMarginTop.setRawValue("-");
}
if (this.diffParams.marginright) {
panel.spnMarginRight.setRawValue("-");
}
if (this.diffParams.marginbottom) {
panel.spnMarginBottom.setRawValue("-");
}
if (this.diffParams.marginleft) {
panel.spnMarginLeft.setRawValue("-");
}
if (this.diffParams.grid) {
panel.chPrintGrid.setValue("indeterminate");
}
if (this.diffParams.headings) {
panel.chPrintRows.setValue("indeterminate");
}
},
fillPageOptions: function (panel, props) {
var opt = props.asc_getPageSetup();
var index = panel.cmbPaperOrientation.getStore().find("orient", opt.asc_getOrientation());
panel.cmbPaperOrientation.select(panel.cmbPaperOrientation.getStore().getAt(index));
var w = opt.asc_getWidth();
var h = opt.asc_getHeight();
index = panel.cmbPaperSize.getStore().find("size", w + "|" + h);
if (index < 0) {
panel.cmbPaperSize.setValue("Custom (" + w + " x " + h);
} else {
panel.cmbPaperSize.select(panel.cmbPaperSize.getStore().getAt(index));
}
opt = props.asc_getPageMargins();
panel.spnMarginLeft.setValue(Common.MetricSettings.fnRecalcFromMM(opt.asc_getLeft()));
panel.spnMarginTop.setValue(Common.MetricSettings.fnRecalcFromMM(opt.asc_getTop()));
panel.spnMarginRight.setValue(Common.MetricSettings.fnRecalcFromMM(opt.asc_getRight()));
panel.spnMarginBottom.setValue(Common.MetricSettings.fnRecalcFromMM(opt.asc_getBottom()));
panel.chPrintGrid.setValue(props.asc_getGridLines());
panel.chPrintRows.setValue(props.asc_getHeadings());
},
fillPrintOptions: function (panel, props) {
panel.groupRange.setValue({
printrange: props.asc_getPrintType()
});
panel.groupLayout.setValue({
printlayout: props.asc_getLayoutPageType()
});
},
getPageOptions: function (panel) {
var props = new Asc.asc_CPageOptions();
props.asc_setGridLines(panel.chPrintGrid.getValue() == "indeterminate" ? undefined : panel.chPrintGrid.getValue() == "checked" ? 1 : 0);
props.asc_setHeadings(panel.chPrintRows.getValue() == "indeterminate" ? undefined : panel.chPrintRows.getValue() == "checked" ? 1 : 0);
var opt = new Asc.asc_CPageSetup();
opt.asc_setOrientation(panel.cmbPaperOrientation.getValue() == "-" ? undefined : panel.cmbPaperOrientation.getValue());
var pagew = /^\d{3}\.?\d*/.exec(panel.cmbPaperSize.getValue());
var pageh = /\d{3}\.?\d*$/.exec(panel.cmbPaperSize.getValue());
opt.asc_setWidth(!pagew ? undefined : parseFloat(pagew[0]));
opt.asc_setHeight(!pageh ? undefined : parseFloat(pageh[0]));
props.asc_setPageSetup(opt);
opt = new Asc.asc_CPageMargins();
opt.asc_setLeft(panel.spnMarginLeft.getRawValue() == "-" ? undefined : Common.MetricSettings.fnRecalcToMM(panel.spnMarginLeft.getNumberValue()));
opt.asc_setTop(panel.spnMarginTop.getRawValue() == "-" ? undefined : Common.MetricSettings.fnRecalcToMM(panel.spnMarginTop.getNumberValue()));
opt.asc_setRight(panel.spnMarginRight.getRawValue() == "-" ? undefined : Common.MetricSettings.fnRecalcToMM(panel.spnMarginRight.getNumberValue()));
opt.asc_setBottom(panel.spnMarginBottom.getRawValue() == "-" ? undefined : Common.MetricSettings.fnRecalcToMM(panel.spnMarginBottom.getNumberValue()));
props.asc_setPageMargins(opt);
return props;
},
savePageOptions: function (panel, index) {
var opts = this.getPageOptions(panel);
if (index == -255) {
var wc = this.api.asc_getWorksheetsCount();
index = -1;
while (++index < wc) {
this.api.asc_setPageOptions(opts, index);
}
if (this.diffParams.orientation) {
this.diffParams.orientation = opts.asc_getPageSetup().asc_getOrientation() == undefined;
}
if (this.diffParams.size) {
this.diffParams.size = (opts.asc_getPageSetup().asc_getWidth() == undefined || opts.asc_getPageSetup().asc_getHeight() == undefined);
}
if (this.diffParams.headings) {
this.diffParams.headings = opts.asc_getHeadings() == undefined;
}
if (this.diffParams.grid) {
this.diffParams.grid = opts.asc_getGridLines() == undefined;
}
if (this.diffParams.margintop) {
this.diffParams.margintop = opts.asc_getPageMargins().asc_getTop() == undefined;
}
if (this.diffParams.marginright) {
this.diffParams.marginright = opts.asc_getPageMargins().asc_getRight() == undefined;
}
if (this.diffParams.marginbottom) {
this.diffParams.marginbottom = opts.asc_getPageMargins().asc_getBottom() == undefined;
}
if (this.diffParams.marginleft) {
this.diffParams.marginleft = opts.asc_getPageMargins().asc_getLeft() == undefined;
}
} else {
this.api.asc_setPageOptions(opts, index);
this.diffParams = {};
}
},
openPrintSettings: function () {
if (this.api) {
var win = Ext.widget("sseprintsettings", {});
this.fillPageOptions(win, this.api.asc_getPageOptions());
this.fillPrintOptions(win, this.adjPrintParams);
win.updateMetricUnit();
win.show();
}
},
closePrintSettings: function (obj, mr) {
if (mr == 1) {
this.savePageOptions(obj, obj.groupRange.getValue().printrange == c_oAscPrintType.EntireWorkbook ? -255 : undefined);
this.adjPrintParams.asc_setPrintType(obj.groupRange.getValue().printrange);
this.adjPrintParams.asc_setLayoutPageType(obj.groupLayout.getValue().printlayout);
this.api.asc_Print(this.adjPrintParams);
this.isUpdatedSettings = false;
}
this.getToolbar().fireEvent("editcomplete", this.getToolbar());
},
querySavePrintSettings: function () {
var panel = this.getPrintAdvanced();
if (this.checkMargins(panel)) {
this.savePageOptions(panel, panel.cmbSheet.getValue());
panel.up("ssedocumentsettings").fireEvent("savedocsettings", panel);
}
},
queryClosePrintSettings: function (btn) {
var panel = btn.up("window");
if (this.checkMargins(panel)) {
panel.fireEvent("onmodalresult", panel, 1);
panel.close();
}
},
checkMargins: function (panel) {
if (panel.cmbPaperOrientation.getValue() == c_oAscPageOrientation.PagePortrait) {
var pagewidth = /^\d{3}\.?\d*/.exec(panel.cmbPaperSize.getValue());
var pageheight = /\d{3}\.?\d*$/.exec(panel.cmbPaperSize.getValue());
} else {
pageheight = /^\d{3}\.?\d*/.exec(panel.cmbPaperSize.getValue());
pagewidth = /\d{3}\.?\d*$/.exec(panel.cmbPaperSize.getValue());
}
var ml = Common.MetricSettings.fnRecalcToMM(panel.spnMarginLeft.getNumberValue());
var mr = Common.MetricSettings.fnRecalcToMM(panel.spnMarginRight.getNumberValue());
var mt = Common.MetricSettings.fnRecalcToMM(panel.spnMarginTop.getNumberValue());
var mb = Common.MetricSettings.fnRecalcToMM(panel.spnMarginBottom.getNumberValue());
var result = false;
if (ml > pagewidth) {
result = "left";
} else {
if (mr > pagewidth - ml) {
result = "right";
} else {
if (mt > pageheight) {
result = "top";
} else {
if (mb > pageheight - mt) {
result = "bottom";
}
}
}
}
if (result) {
Ext.Msg.show({
title: this.textWarning,
msg: this.warnCheckMargings,
icon: Ext.Msg.WARNING,
buttons: Ext.Msg.OK,
fn: function (btn, text) {
switch (result) {
case "left":
panel.spnMarginLeft.focus();
return;
case "right":
panel.spnMarginRight.focus();
return;
case "top":
panel.spnMarginTop.focus();
return;
case "bottom":
panel.spnMarginBottom.focus();
return;
}
}
});
return false;
}
return true;
},
warnCheckMargings: "Margins are incorrect",
strAllSheets: "All Sheets",
textWarning: "Warning"
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
define(["core", "spreadsheeteditor/main/app/view/FileMenuPanels", "spreadsheeteditor/main/app/view/PrintSettings"], function () {
SSE.Controllers.Print = Backbone.Controller.extend(_.extend({
views: ["MainSettingsPrint"],
initialize: function () {
this.adjPrintParams = new Asc.asc_CAdjustPrint();
this.adjPrintParams.asc_setPrintType(c_oAscPrintType.ActiveSheets);
this.adjPrintParams.asc_setLayoutPageType(c_oAscLayoutPageType.ActualSize);
this.diffParams = {};
this.addListeners({
"MainSettingsPrint": {
"show": _.bind(this.onShowMainSettingsPrint, this),
"render:after": _.bind(this.onAfterRender, this)
},
"Statusbar": {
"updatesheetsinfo": _.bind(function () {
if (this.printSettings.isVisible()) {
this.updateSettings();
} else {
this.isFillSheets = false;
this.diffParams = {};
}
},
this)
},
"PrintSettings": {
"changerange": _.bind(this.onChangeRange, this)
}
});
},
onLaunch: function () {
this.printSettings = this.createView("MainSettingsPrint");
},
onAfterRender: function (view) {
this.printSettings.cmbSheet.on("selected", _.bind(this.comboSheetsChange, this));
this.printSettings.btnOk.on("click", _.bind(this.querySavePrintSettings, this));
var toolbar = SSE.getController("Toolbar").getView("Toolbar");
if (toolbar) {
toolbar.mnuPrint.on("item:click", _.bind(this.openPrintSettings, this));
}
},
setApi: function (o) {
this.api = o;
},
updateSettings: function () {
var wc = this.api.asc_getWorksheetsCount(),
i = -1;
var items = [{
displayValue: this.strAllSheets,
value: -255
}];
while (++i < wc) {
if (!this.api.asc_isWorksheetHidden(i)) {
items.push({
displayValue: this.api.asc_getWorksheetName(i),
value: i
});
}
}
this.printSettings.cmbSheet.store.reset(items);
var item = this.printSettings.cmbSheet.store.findWhere({
value: this.printSettings.cmbSheet.getValue()
}) || this.printSettings.cmbSheet.store.findWhere({
value: this.api.asc_getActiveWorksheetIndex()
});
if (item) {
this.printSettings.cmbSheet.setValue(item.get("value"));
}
},
comboSheetsChange: function (combo, record) {
var newvalue = record.value;
if (newvalue == -255) {
this.indeterminatePageOptions(this.printSettings);
} else {
this.fillPageOptions(this.printSettings, this.api.asc_getPageOptions(newvalue));
}
},
isDiffRefill: function () {
for (var item in this.diffParams) {
if (this.diffParams[item] == undefined) {
return true;
}
}
return item == undefined;
},
indeterminatePageOptions: function (panel) {
if (this.isDiffRefill()) {
var wc = this.api.asc_getWorksheetsCount();
if (wc == 1) {
this.diffParams.orientation = false;
this.diffParams.size = false;
this.diffParams.headings = false;
this.diffParams.grid = false;
this.diffParams.margintop = false;
this.diffParams.marginright = false;
this.diffParams.marginbottom = false;
this.diffParams.marginleft = false;
} else {
var index = 0;
var opts = this.api.asc_getPageOptions(index),
opts_next;
while (++index < wc) {
opts_next = this.api.asc_getPageOptions(index);
if (this.diffParams.orientation == undefined) {
this.diffParams.orientation = opts.asc_getPageSetup().asc_getOrientation() != opts_next.asc_getPageSetup().asc_getOrientation();
}
if (this.diffParams.size == undefined) {
this.diffParams.size = (opts.asc_getPageSetup().asc_getWidth() != opts_next.asc_getPageSetup().asc_getWidth() || opts.asc_getPageSetup().asc_getHeight() != opts_next.asc_getPageSetup().asc_getHeight());
}
if (this.diffParams.headings == undefined) {
this.diffParams.headings = opts.asc_getHeadings() != opts_next.asc_getHeadings();
}
if (this.diffParams.grid == undefined) {
this.diffParams.grid = opts.asc_getGridLines() != opts_next.asc_getGridLines();
}
if (this.diffParams.margintop == undefined) {
this.diffParams.margintop = Math.abs(opts.asc_getPageMargins().asc_getTop() - opts_next.asc_getPageMargins().asc_getTop()) > 0.001;
}
if (this.diffParams.marginright == undefined) {
this.diffParams.marginright = Math.abs(opts.asc_getPageMargins().asc_getRight() - opts_next.asc_getPageMargins().asc_getRight()) > 0.001;
}
if (this.diffParams.marginbottom == undefined) {
this.diffParams.marginbottom = Math.abs(opts.asc_getPageMargins().asc_getBottom() - opts_next.asc_getPageMargins().asc_getBottom()) > 0.001;
}
if (this.diffParams.marginleft == undefined) {
this.diffParams.marginleft = Math.abs(opts.asc_getPageMargins().asc_getLeft() - opts_next.asc_getPageMargins().asc_getLeft()) > 0.001;
}
}
}
}
if (this.diffParams.orientation) {
panel.cmbPaperOrientation.setValue("-");
}
if (this.diffParams.size) {
panel.cmbPaperSize.setValue("-");
}
if (this.diffParams.margintop) {
panel.spnMarginTop.setValue("-");
}
if (this.diffParams.marginright) {
panel.spnMarginRight.setValue("-");
}
if (this.diffParams.marginbottom) {
panel.spnMarginBottom.setValue("-");
}
if (this.diffParams.marginleft) {
panel.spnMarginLeft.setValue("-");
}
if (this.diffParams.grid) {
panel.chPrintGrid.setValue("indeterminate");
}
if (this.diffParams.headings) {
panel.chPrintRows.setValue("indeterminate");
}
},
fillPageOptions: function (panel, props) {
var opt = props.asc_getPageSetup();
var item = panel.cmbPaperOrientation.store.findWhere({
value: opt.asc_getOrientation()
});
if (item) {
panel.cmbPaperOrientation.setValue(item.get("value"));
}
var w = opt.asc_getWidth();
var h = opt.asc_getHeight();
item = panel.cmbPaperSize.store.findWhere({
value: w + "|" + h
});
if (item) {
panel.cmbPaperSize.setValue(item.get("value"));
} else {
panel.cmbPaperSize.setValue("Custom (" + w + " x " + h);
}
opt = props.asc_getPageMargins();
panel.spnMarginLeft.setValue(Common.Utils.Metric.fnRecalcFromMM(opt.asc_getLeft()));
panel.spnMarginTop.setValue(Common.Utils.Metric.fnRecalcFromMM(opt.asc_getTop()));
panel.spnMarginRight.setValue(Common.Utils.Metric.fnRecalcFromMM(opt.asc_getRight()));
panel.spnMarginBottom.setValue(Common.Utils.Metric.fnRecalcFromMM(opt.asc_getBottom()));
panel.chPrintGrid.setValue(props.asc_getGridLines());
panel.chPrintRows.setValue(props.asc_getHeadings());
},
fillPrintOptions: function (panel, props) {
panel.setRange(props.asc_getPrintType());
},
getPageOptions: function (panel) {
var props = new Asc.asc_CPageOptions();
props.asc_setGridLines(panel.chPrintGrid.getValue() == "indeterminate" ? undefined : panel.chPrintGrid.getValue() == "checked" ? 1 : 0);
props.asc_setHeadings(panel.chPrintRows.getValue() == "indeterminate" ? undefined : panel.chPrintRows.getValue() == "checked" ? 1 : 0);
var opt = new Asc.asc_CPageSetup();
opt.asc_setOrientation(panel.cmbPaperOrientation.getValue() == "-" ? undefined : panel.cmbPaperOrientation.getValue());
var pagew = /^\d{3}\.?\d*/.exec(panel.cmbPaperSize.getValue());
var pageh = /\d{3}\.?\d*$/.exec(panel.cmbPaperSize.getValue());
opt.asc_setWidth(!pagew ? undefined : parseFloat(pagew[0]));
opt.asc_setHeight(!pageh ? undefined : parseFloat(pageh[0]));
props.asc_setPageSetup(opt);
opt = new Asc.asc_CPageMargins();
opt.asc_setLeft(panel.spnMarginLeft.getValue() == "-" ? undefined : Common.Utils.Metric.fnRecalcToMM(panel.spnMarginLeft.getNumberValue()));
opt.asc_setTop(panel.spnMarginTop.getValue() == "-" ? undefined : Common.Utils.Metric.fnRecalcToMM(panel.spnMarginTop.getNumberValue()));
opt.asc_setRight(panel.spnMarginRight.getValue() == "-" ? undefined : Common.Utils.Metric.fnRecalcToMM(panel.spnMarginRight.getNumberValue()));
opt.asc_setBottom(panel.spnMarginBottom.getValue() == "-" ? undefined : Common.Utils.Metric.fnRecalcToMM(panel.spnMarginBottom.getNumberValue()));
props.asc_setPageMargins(opt);
return props;
},
savePageOptions: function (panel, index) {
var opts = this.getPageOptions(panel);
if (index == -255) {
var wc = this.api.asc_getWorksheetsCount();
index = -1;
while (++index < wc) {
this.api.asc_setPageOptions(opts, index);
}
if (this.diffParams.orientation) {
this.diffParams.orientation = opts.asc_getPageSetup().asc_getOrientation() == undefined;
}
if (this.diffParams.size) {
this.diffParams.size = (opts.asc_getPageSetup().asc_getWidth() == undefined || opts.asc_getPageSetup().asc_getHeight() == undefined);
}
if (this.diffParams.headings) {
this.diffParams.headings = opts.asc_getHeadings() == undefined;
}
if (this.diffParams.grid) {
this.diffParams.grid = opts.asc_getGridLines() == undefined;
}
if (this.diffParams.margintop) {
this.diffParams.margintop = opts.asc_getPageMargins().asc_getTop() == undefined;
}
if (this.diffParams.marginright) {
this.diffParams.marginright = opts.asc_getPageMargins().asc_getRight() == undefined;
}
if (this.diffParams.marginbottom) {
this.diffParams.marginbottom = opts.asc_getPageMargins().asc_getBottom() == undefined;
}
if (this.diffParams.marginleft) {
this.diffParams.marginleft = opts.asc_getPageMargins().asc_getLeft() == undefined;
}
} else {
this.api.asc_setPageOptions(opts, index);
this.diffParams = {};
}
},
onShowMainSettingsPrint: function () {
if (!this.isFillSheets) {
this.isFillSheets = true;
this.updateSettings();
}
if (!this.isUpdatedSettings) {
this.isUpdatedSettings = true;
var item = this.printSettings.cmbSheet.store.findWhere({
value: this.api.asc_getActiveWorksheetIndex()
});
if (item) {
this.printSettings.cmbSheet.setValue(item.get("value"));
this.comboSheetsChange(this.printSettings.cmbSheet, item.toJSON());
}
}
},
openPrintSettings: function (menu, item) {
if (item.value === "options" && this.api) {
this.printSettingsDlg = (new SSE.Views.PrintSettings({
handler: _.bind(this.resultPrintSettings, this),
afterrender: _.bind(function () {
this.fillPageOptions(this.printSettingsDlg, this.api.asc_getPageOptions());
this.fillPrintOptions(this.printSettingsDlg, this.adjPrintParams);
},
this)
}));
this.printSettingsDlg.show();
}
},
resultPrintSettings: function (result, value) {
var view = SSE.getController("Toolbar").getView("Toolbar");
if (result == "ok") {
if (this.checkMargins(this.printSettingsDlg)) {
this.savePageOptions(this.printSettingsDlg, this.printSettingsDlg.getRange() == c_oAscPrintType.EntireWorkbook ? -255 : undefined);
this.adjPrintParams.asc_setPrintType(this.printSettingsDlg.getRange());
this.api.asc_Print(this.adjPrintParams);
this.isUpdatedSettings = false;
} else {
return true;
}
}
Common.NotificationCenter.trigger("edit:complete", view);
},
onChangeRange: function () {
var newvalue = this.printSettingsDlg.getRange();
if (newvalue == c_oAscPrintType.EntireWorkbook) {
this.indeterminatePageOptions(this.printSettingsDlg);
} else {
if (this.lastCheckedRange == c_oAscPrintType.EntireWorkbook) {
this.fillPageOptions(this.printSettingsDlg, this.api.asc_getPageOptions());
}
}
this.lastCheckedRange = newvalue;
},
querySavePrintSettings: function () {
if (this.checkMargins(this.printSettings)) {
this.savePageOptions(this.printSettings, this.printSettings.cmbSheet.getValue());
this.printSettings.applySettings();
}
},
checkMargins: function (panel) {
if (panel.cmbPaperOrientation.getValue() == c_oAscPageOrientation.PagePortrait) {
var pagewidth = /^\d{3}\.?\d*/.exec(panel.cmbPaperSize.getValue());
var pageheight = /\d{3}\.?\d*$/.exec(panel.cmbPaperSize.getValue());
} else {
pageheight = /^\d{3}\.?\d*/.exec(panel.cmbPaperSize.getValue());
pagewidth = /\d{3}\.?\d*$/.exec(panel.cmbPaperSize.getValue());
}
pagewidth = parseFloat(pagewidth[0]);
pageheight = parseFloat(pageheight[0]);
var ml = Common.Utils.Metric.fnRecalcToMM(panel.spnMarginLeft.getNumberValue());
var mr = Common.Utils.Metric.fnRecalcToMM(panel.spnMarginRight.getNumberValue());
var mt = Common.Utils.Metric.fnRecalcToMM(panel.spnMarginTop.getNumberValue());
var mb = Common.Utils.Metric.fnRecalcToMM(panel.spnMarginBottom.getNumberValue());
var result = false;
if (ml > pagewidth) {
result = "left";
} else {
if (mr > pagewidth - ml) {
result = "right";
} else {
if (mt > pageheight) {
result = "top";
} else {
if (mb > pageheight - mt) {
result = "bottom";
}
}
}
}
if (result) {
Common.UI.warning({
title: this.textWarning,
msg: this.warnCheckMargings,
callback: function (btn, text) {
switch (result) {
case "left":
panel.spnMarginLeft.$el.focus();
return;
case "right":
panel.spnMarginRight.$el.focus();
return;
case "top":
panel.spnMarginTop.$el.focus();
return;
case "bottom":
panel.spnMarginBottom.$el.focus();
return;
}
}
});
return false;
}
return true;
},
warnCheckMargings: "Margins are incorrect",
strAllSheets: "All Sheets",
textWarning: "Warning"
},
SSE.Controllers.Print || {}));
});

View File

@@ -1,64 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
Ext.define("SSE.controller.RecentFiles", {
extend: "Ext.app.Controller",
views: ["RecentFiles"],
stores: ["RecentFiles"],
refs: [{
ref: "filePanel",
selector: "ssefile"
}],
init: function () {
this.control({
"sserecentfiles dataview": {
itemclick: this.onRecentFileClick
}
});
},
loadConfig: function (data) {
var recent = this.getRecentFilesStore();
if (recent && data && data.config && data.config.recent) {
recent.removeAll();
recent.add(data.config.recent);
}
},
onRecentFileClick: function (view, record, item, index, e) {
var filePanel = this.getFilePanel();
if (filePanel) {
filePanel.closeMenu();
}
var recentDocPage = window.open(record.data.url);
if (recentDocPage) {
recentDocPage.focus();
}
}
});

View File

@@ -0,0 +1,257 @@
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
define(["core", "spreadsheeteditor/main/app/view/RightMenu"], function () {
SSE.Controllers.RightMenu = Backbone.Controller.extend({
models: [],
collections: [],
views: ["RightMenu"],
initialize: function () {
this.editMode = true;
this._state = {};
this.addListeners({
"RightMenu": {
"rightmenuclick": this.onRightMenuClick
}
});
},
onLaunch: function () {
this.rightmenu = this.createView("RightMenu");
this.rightmenu.on("render:after", _.bind(this.onRightMenuAfterRender, this));
},
onRightMenuAfterRender: function (rightMenu) {
rightMenu.shapeSettings.application = this.getApplication();
this._settings = [];
this._settings[c_oAscTypeSelectElement.Paragraph] = {
panelId: "id-paragraph-settings",
panel: rightMenu.paragraphSettings,
btn: rightMenu.btnText,
hidden: 1,
locked: false
};
this._settings[c_oAscTypeSelectElement.Image] = {
panelId: "id-image-settings",
panel: rightMenu.imageSettings,
btn: rightMenu.btnImage,
hidden: 1,
locked: false
};
this._settings[c_oAscTypeSelectElement.Shape] = {
panelId: "id-shape-settings",
panel: rightMenu.shapeSettings,
btn: rightMenu.btnShape,
hidden: 1,
locked: false
};
this._settings[c_oAscTypeSelectElement.Chart] = {
panelId: "id-chart-settings",
panel: rightMenu.chartSettings,
btn: rightMenu.btnChart,
hidden: 1,
locked: false
};
},
setApi: function (api) {
this.api = api;
this.api.asc_registerCallback("asc_onСoAuthoringDisconnect", _.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on("api:disconnect", _.bind(this.onCoAuthoringDisconnect, this));
},
setMode: function (mode) {
this.editMode = mode.isEdit;
},
onRightMenuClick: function (menu, type, minimized) {
if (!minimized && this.editMode) {
var panel = this._settings[type].panel;
var props = this._settings[type].props;
if (props && panel) {
panel.ChangeSettings.call(panel, props);
}
}
Common.NotificationCenter.trigger("layout:changed", "rightmenu");
Common.NotificationCenter.trigger("edit:complete", this.rightmenu);
},
onSelectionChanged: function (info) {
var SelectedObjects = [],
selectType = info.asc_getFlags().asc_getSelectionType();
if (selectType == c_oAscSelectionType.RangeImage || selectType == c_oAscSelectionType.RangeShape || selectType == c_oAscSelectionType.RangeChart || selectType == c_oAscSelectionType.RangeChartText || selectType == c_oAscSelectionType.RangeShapeText) {
SelectedObjects = this.api.asc_getGraphicObjectProps();
}
if (SelectedObjects.length <= 0 && !this.rightmenu.minimizedMode) {
this.rightmenu.clearSelection();
}
this.onFocusObject(SelectedObjects);
var need_disable = info.asc_getLocked(),
me = this;
if (this._state.prevDisabled != need_disable) {
this._state.prevDisabled = need_disable;
_.each(this._settings, function (item) {
item.panel.setLocked(need_disable);
});
}
},
onFocusObject: function (SelectedObjects) {
if (!this.editMode) {
return;
}
for (var i = 0; i < this._settings.length; ++i) {
if (this._settings[i]) {
this._settings[i].hidden = 1;
this._settings[i].locked = false;
}
}
for (i = 0; i < SelectedObjects.length; ++i) {
var type = SelectedObjects[i].asc_getObjectType();
if (type >= this._settings.length || this._settings[type] === undefined) {
continue;
}
var value = SelectedObjects[i].asc_getObjectValue();
if (type == c_oAscTypeSelectElement.Image) {
if (value.asc_getChartProperties() !== null) {
type = c_oAscTypeSelectElement.Chart;
} else {
if (value.asc_getShapeProperties() !== null) {
type = c_oAscTypeSelectElement.Shape;
}
}
}
this._settings[type].props = value;
this._settings[type].hidden = 0;
this._settings[type].locked = value.asc_getLocked();
}
var lastactive = -1,
currentactive, priorityactive = -1;
for (i = 0; i < this._settings.length; ++i) {
var pnl = this._settings[i];
if (pnl === undefined) {
continue;
}
if (pnl.hidden) {
if (!pnl.btn.isDisabled()) {
pnl.btn.setDisabled(true);
}
if (this.rightmenu.GetActivePane() == pnl.panelId) {
currentactive = -1;
}
} else {
if (pnl.btn.isDisabled()) {
pnl.btn.setDisabled(false);
}
lastactive = i;
if (pnl.needShow) {
pnl.needShow = false;
priorityactive = i;
} else {
if (this.rightmenu.GetActivePane() == pnl.panelId) {
currentactive = i;
}
}
pnl.panel.setLocked(pnl.locked);
}
}
if (!this.rightmenu.minimizedMode) {
var active;
if (priorityactive > -1) {
active = priorityactive;
} else {
if (lastactive >= 0 && currentactive < 0) {
active = lastactive;
} else {
if (currentactive >= 0) {
active = currentactive;
}
}
}
if (active !== undefined) {
this.rightmenu.SetActivePane(active);
this._settings[active].panel.ChangeSettings.call(this._settings[active].panel, this._settings[active].props);
}
}
this._settings[c_oAscTypeSelectElement.Image].needShow = false;
this._settings[c_oAscTypeSelectElement.Chart].needShow = false;
},
onCoAuthoringDisconnect: function () {
if (this.rightmenu) {
this.rightmenu.SetDisabled("", true, true);
}
this.setMode({
isEdit: false
});
},
onInsertImage: function () {
this._settings[c_oAscTypeSelectElement.Image].needShow = true;
},
onInsertChart: function () {
this._settings[c_oAscTypeSelectElement.Chart].needShow = true;
},
onInsertShape: function () {
this._settings[c_oAscTypeSelectElement.Shape].needShow = true;
},
UpdateThemeColors: function () {
this.rightmenu.shapeSettings.UpdateThemeColors();
},
updateMetricUnit: function () {
this.rightmenu.paragraphSettings.updateMetricUnit();
this.rightmenu.chartSettings.updateMetricUnit();
this.rightmenu.imageSettings.updateMetricUnit();
},
createDelayedElements: function () {
var me = this;
if (this.api) {
this.api.asc_registerCallback("asc_onFocusObject", _.bind(this.onFocusObject, this));
this.api.asc_registerCallback("asc_onSelectionChanged", _.bind(this.onSelectionChanged, this));
this.api.asc_registerCallback("asc_doubleClickOnObject", _.bind(this.onDoubleClickOnObject, this));
}
},
onDoubleClickOnObject: function (obj) {
if (!this.editMode) {
return;
}
var type = obj.asc_getObjectType();
if (type >= this._settings.length || this._settings[type] === undefined) {
return;
}
var value = obj.asc_getObjectValue();
if (type == c_oAscTypeSelectElement.Image) {
if (value.asc_getChartProperties() !== null) {
type = c_oAscTypeSelectElement.Chart;
} else {
if (value.asc_getShapeProperties() !== null) {
type = c_oAscTypeSelectElement.Shape;
}
}
}
if (type !== c_oAscTypeSelectElement.Paragraph) {
this.rightmenu.SetActivePane(type, true);
this._settings[type].panel.ChangeSettings.call(this._settings[type].panel, this._settings[type].props);
}
}
});
});

View File

@@ -1,193 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
Ext.define("SSE.controller.Search", {
extend: "Ext.app.Controller",
refs: [{
ref: "searchDialog",
selector: "commonsearchdialog"
},
{
ref: "searchQuery",
selector: "#search-dialog-text-search"
},
{
ref: "replaceQuery",
selector: "#search-dialog-text-replace"
}],
init: function () {
var me = this;
this.control({
"commonsearchdialog": {
show: function () {
me.api.asc_closeCellEditor();
me.setDefaultView();
}
},
"commonsearchdialog button[group=search-text]": {
click: function (btn) {
this._startSearch(btn.direction);
}
},
"commonsearchdialog button[group=replace-text]": {
click: this.btnReplaceText
},
"#search-dialog-text-search": {
searchstart: function (obj, text) {
this._startSearch("next");
obj.stopSearch(true);
}
},
"ssemainmenu #main-menu-search": {
toggle: this.showSearchDialog
}
});
},
setMode: function (mode) {
this.mode = mode;
this._frmSearch && this._frmSearch.setViewMode(!this.mode.isEdit);
},
setApi: function (o) {
this.api = o;
this.api.asc_registerCallback("asc_onRenameCellTextEnd", Ext.bind(this._onRenameText, this));
this.api.asc_registerCallback("asc_onСoAuthoringDisconnect", Ext.bind(this.onCoAuthoringDisconnect, this));
},
setDefaultView: function () {
this.getSearchDialog().searchMode();
},
showWarning: function (text) {
var me = this;
if (!this.msgbox) {
this.msgbox = Ext.create("Ext.window.MessageBox", {
listeners: {
beforehide: function () {
me.getSearchQuery().focus(true, 100);
}
}
});
}
var config = {
title: this.textSearch,
msg: text,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
};
if (Common.userAgent.isIE) {
var oldFn = {
enter: Ext.FocusManager.navigateIn,
esc: Ext.FocusManager.navigateOut
};
Ext.FocusManager.navigateIn = Ext.emptyFn;
Ext.FocusManager.navigateOut = function (event) {
me.msgbox.close();
};
config.fn = function (btn) {
Ext.FocusManager.navigateIn = oldFn.enter;
Ext.FocusManager.navigateOut = oldFn.esc;
};
}
this.msgbox.show(config);
},
btnReplaceText: function (btn, event, opts) {
var me = this;
if (me.getSearchQuery().isValueValid()) {
var sett = this.getSearchDialog().getSettings();
this.api.isReplaceAll = (btn.type == "all");
this.api.asc_replaceText(sett.textsearch, sett.textreplace, btn.type == "all", sett.casesensitive, sett.wholewords);
}
},
_startSearch: function (direction) {
if (this.api && this.getSearchQuery().isValueValid()) {
var sett = this.getSearchDialog().getSettings();
if (!this.api.asc_findText(sett.textsearch, true, direction == "next", sett.casesensitive, sett.wholewords)) {
this.showWarning(this.textNoTextFound);
}
}
},
_onRenameText: function (found, replaced) {
var me = this;
if (this.api.isReplaceAll) {
if (found) {
if (! (found - replaced)) {
me.showWarning(Ext.String.format(this.textReplaceSuccess, replaced));
} else {
me.showWarning(Ext.String.format(this.textReplaceSkipped, found - replaced));
}
} else {
me.showWarning(me.textNoTextFound);
}
} else {
var sett = this.getSearchDialog().getSettings();
if (!me.api.asc_findText(sett.textsearch, true, true, sett.casesensitive, sett.wholewords)) {
me.showWarning(me.textNoTextFound);
}
}
},
showSearchDialog: function (btn, pressed) {
if (pressed) {
var mainmenu = btn.up("#view-main-menu");
mainmenu.closeFullScaleMenu();
var me = this;
if (!me._frmSearch) {
me._frmSearch = Ext.create("Common.view.SearchDialog", {
animateTarget: "main-menu-search",
closeAction: "hide",
isViewMode: !me.mode.isEdit,
highlight: false,
listeners: {
hide: function (cnt, eOpts) {
if (!btn.ownrise) {
btn.ownrise = true;
btn.toggle(false, true);
mainmenu.fireEvent("editcomplete", mainmenu);
}
btn.ownrise = false;
}
}
});
}
me._frmSearch.show();
} else {
if (this._frmSearch && !btn.ownrise) {
btn.ownrise = true;
this._frmSearch.hide();
}
}
},
onCoAuthoringDisconnect: function () {
this.mode.isEdit = false;
this._frmSearch && this._frmSearch.setViewMode(true);
},
textSearch: "Search",
textNoTextFound: "Text not found",
textReplaceSuccess: "Search has been done. {0} occurrences have been replaced",
textReplaceSkipped: "The replacement has been made. {0} occurrences were skipped."
});

View File

@@ -0,0 +1,583 @@
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
define(["core", "spreadsheeteditor/main/app/view/Statusbar"], function () {
SSE.Controllers.Statusbar = Backbone.Controller.extend(_.extend({
models: [],
collections: [],
views: ["Statusbar"],
initialize: function () {
this.addListeners({
"Statusbar": {
"show:hidden": _.bind(function (obj, index) {
this.hideWorksheet(false, index);
},
this),
"sheet:changename": _.bind(function () {
this.api.asc_closeCellEditor();
this.renameWorksheet();
},
this),
"sheet:setcolor": _.bind(this.setWorksheetColor, this),
"sheet:updateColors": _.bind(this.updateTabsColors, this),
"sheet:move": _.bind(this.moveWorksheet, this)
}
});
var me = this;
Common.util.Shortcuts.delegateShortcuts({
shortcuts: {
"alt+pageup": function (e) {
me.moveCurrentTab(-1);
e.preventDefault();
e.stopPropagation();
},
"alt+pagedown": function (e) {
me.moveCurrentTab(1);
e.preventDefault();
e.stopPropagation();
}
}
});
},
events: function () {
return {
"click #status-btn-zoomdown": _.bind(this.zoomDocument, this, "down"),
"click #status-btn-zoomup": _.bind(this.zoomDocument, this, "up"),
"click .cnt-zoom": _.bind(this.onZoomShow, this)
};
},
onLaunch: function () {
this.statusbar = this.createView("Statusbar").render();
this.statusbar.$el.css("z-index", 10);
this.statusbar.labelZoom.css("min-width", 70);
this.statusbar.zoomMenu.on("item:click", _.bind(this.menuZoomClick, this));
this.bindViewEvents(this.statusbar, this.events);
$("#id-tab-menu-new-color").on("click", _.bind(this.onNewBorderColor, this));
},
setApi: function (api) {
this.api = api;
this.api.asc_registerCallback("asc_onZoomChanged", _.bind(this.onZoomChange, this));
this.api.asc_registerCallback("asc_onSelectionMathChanged", _.bind(this.onApiMathChanged, this));
this.api.asc_registerCallback("asc_onСoAuthoringDisconnect", _.bind(this.onApiDisconnect, this));
Common.NotificationCenter.on("api:disconnect", _.bind(this.onApiDisconnect, this));
this.api.asc_registerCallback("asc_onUpdateTabColor", _.bind(this.onApiUpdateTabColor, this));
this.api.asc_registerCallback("asc_onEditCell", _.bind(this.onApiEditCell, this));
this.api.asc_registerCallback("asc_onWorkbookLocked", _.bind(this.onWorkbookLocked, this));
this.api.asc_registerCallback("asc_onWorksheetLocked", _.bind(this.onWorksheetLocked, this));
this.api.asc_registerCallback("asc_onAuthParticipantsChanged", _.bind(this.onApiUsersChanged, this));
this.api.asc_registerCallback("asc_onParticipantsChanged", _.bind(this.onApiUsersChanged, this));
this.api.asc_coAuthoringGetUsers();
this.statusbar.setApi(api);
},
zoomDocument: function (d, e) {
switch (d) {
case "up":
var f = this.api.asc_getZoom() + 0.1; ! (f > 2) && this.api.asc_setZoom(f);
break;
case "down":
f = this.api.asc_getZoom() - 0.1; ! (f < 0.5) && this.api.asc_setZoom(f);
break;
}
},
menuZoomClick: function (menu, item) {
this.api.asc_setZoom(item.value / 100);
},
onZoomChange: function (percent, type) {
this.statusbar.labelZoom.text(Common.Utils.String.format(this.zoomText, Math.floor((percent + 0.005) * 100)));
},
onApiDisconnect: function () {
this.statusbar.setMode({
isDisconnected: true
});
this.statusbar.update();
},
onWorkbookLocked: function (locked) {
this.statusbar.tabbar[locked ? "addClass" : "removeClass"]("coauth-locked");
this.statusbar.btnAddWorksheet.setDisabled(locked || this.statusbar.rangeSelectionMode == c_oAscSelectionDialogType.Chart || this.statusbar.rangeSelectionMode == c_oAscSelectionDialogType.FormatTable);
var item, i = this.statusbar.tabbar.getCount();
while (i-->0) {
item = this.statusbar.tabbar.getAt(i);
if (item.sheetindex >= 0) {} else {
item.disable(locked);
}
}
},
onWorksheetLocked: function (index, locked) {
var count = this.statusbar.tabbar.getCount(),
tab;
for (var i = count; i-->0;) {
tab = this.statusbar.tabbar.getAt(i);
if (index == tab.sheetindex) {
tab[locked ? "addClass" : "removeClass"]("coauth-locked");
tab.isLockTheDrag = locked || (this.statusbar.rangeSelectionMode == c_oAscSelectionDialogType.FormatTable);
break;
}
}
},
onApiUsersChanged: function (users) {
var editusers = [];
_.each(users, function (item) {
if (!item.asc_getView()) {
editusers.push(item);
}
});
var length = _.size(editusers);
var panel = this.statusbar.panelUsers;
panel[length > 1 ? "show" : "hide"]();
this.statusbar.updateTabbarBorders();
var ttblock = panel.find("#status-users-block");
if (ttblock.data("bs.tooltip")) {
ttblock.removeData("bs.tooltip");
}
if (length > 1) {
panel.find("#status-users-count").text(length);
var tip = this.tipUsers + "<br/><br/>",
i = 0;
for (var n in editusers) {
tip += "\n" + Common.Utils.String.htmlEncode(editusers[n].asc_getUserName());
if (++i > 3) {
break;
}
}
if (length > 4) {
tip += "<br/>" + this.tipMoreUsers.replace("%1", length - 4);
tip += "<br/><br/>" + this.tipShowUsers;
}
ttblock.tooltip({
title: tip,
html: true,
placement: "top"
});
}
},
onApiMathChanged: function (info) {
this.statusbar.setMathInfo({
count: info.asc_getCount(),
average: info.asc_getAverage(),
sum: info.asc_getSum()
});
this.statusbar.updateTabbarBorders();
},
onApiEditCell: function (state) {
var disable = state != c_oAscCellEditorState.editEnd;
this.statusbar.btnZoomUp.setDisabled(disable);
this.statusbar.btnZoomDown.setDisabled(disable);
this.statusbar.labelZoom[disable ? "addClass" : "removeClass"]("disabled");
},
createDelayedElements: function () {
this.statusbar.$el.css("z-index", "");
this.statusbar.tabMenu.on("item:click", _.bind(this.onTabMenu, this));
this.statusbar.btnAddWorksheet.on("click", _.bind(this.onAddWorksheetClick, this));
Common.NotificationCenter.on("window:resize", _.bind(this.onWindowResize, this));
Common.NotificationCenter.on("cells:range", _.bind(this.onRangeDialogMode, this));
},
onWindowResize: function (area) {
this.statusbar.onTabInvisible(undefined, this.statusbar.tabbar.checkInvisible(true));
},
onRangeDialogMode: function (mode) {
var islocked = this.statusbar.tabbar.hasClass("coauth-locked"),
currentIdx = this.api.asc_getActiveWorksheetIndex();
this.statusbar.btnAddWorksheet.setDisabled(islocked || mode != c_oAscSelectionDialogType.None);
var item, i = this.statusbar.tabbar.getCount();
while (i-->0) {
item = this.statusbar.tabbar.getAt(i);
if (item.sheetindex !== currentIdx) {
item.disable(mode == c_oAscSelectionDialogType.FormatTable);
}
item.isLockTheDrag = (item.hasClass("coauth-locked") || (mode != c_oAscSelectionDialogType.None));
}
this.statusbar.rangeSelectionMode = mode;
},
onTabMenu: function (obj, item, e) {
switch (item.value) {
case "ins":
this.api.asc_insertWorksheet(this.createSheetName());
break;
case "del":
this.deleteWorksheet();
break;
case "ren":
this.renameWorksheet();
break;
case "copy":
this.moveWorksheet(false);
break;
case "move":
this.moveWorksheet(true);
break;
case "hide":
this.hideWorksheet(true);
break;
}
},
createSheetName: function () {
var items = [],
wc = this.api.asc_getWorksheetsCount();
while (wc--) {
items.push(this.api.asc_getWorksheetName(wc).toLowerCase());
}
var index = 0,
name;
while (++index < 1000) {
name = this.strSheet + index;
if (items.indexOf(name.toLowerCase()) < 0) {
break;
}
}
return name;
},
createCopyName: function (orig) {
var wc = this.api.asc_getWorksheetsCount(),
names = [];
while (wc--) {
names.push(this.api.asc_getWorksheetName(wc).toLowerCase());
}
var re = /^(.*)\((\d)\)$/.exec(orig);
var first = re ? re[1] : orig + " ";
var index = 1,
name;
while (++index < 1000) {
name = first + "(" + index + ")";
if (names.indexOf(name.toLowerCase()) < 0) {
break;
}
}
return name;
},
deleteWorksheet: function () {
var me = this;
if (this.statusbar.tabbar.tabs.length == 1) {
Common.UI.warning({
msg: this.errorLastSheet
});
} else {
Common.UI.warning({
msg: this.warnDeleteSheet,
buttons: ["ok", "cancel"],
callback: function (btn) {
if (btn == "ok" && !me.api.asc_deleteWorksheet()) {
_.delay(function () {
Common.UI.error({
msg: me.errorRemoveSheet
});
},
10);
}
}
});
}
},
hideWorksheet: function (hide, index) {
if (hide) {
this.statusbar.tabbar.tabs.length == 1 ? Common.UI.warning({
msg: this.errorLastSheet
}) : this.api["asc_hideWorksheet"](index);
} else {
this.api["asc_showWorksheet"](index);
this.loadTabColor(index);
}
},
renameWorksheet: function () {
var me = this;
var wc = me.api.asc_getWorksheetsCount(),
items = [];
if (wc > 0) {
var sindex = me.api.asc_getActiveWorksheetIndex();
if (me.api.asc_isWorksheetLockedOrDeleted(sindex)) {
return;
}
while (wc--) {
if (sindex !== wc) {
items.push(me.api.asc_getWorksheetName(wc).toLowerCase());
}
}
var tab = me.statusbar.tabbar.tabs[this.statusbar.tabbar.getActive()];
var top = me.statusbar.$el.position().top - 115,
left = tab.$el.offset().left;
var current = me.api.asc_getWorksheetName(me.api.asc_getActiveWorksheetIndex());
(new SSE.Views.Statusbar.RenameDialog({
current: current,
names: items,
handler: function (btn, s) {
if (btn == "ok" && s != current) {
me.api.asc_renameWorksheet(s);
tab.setCaption(s);
me.statusbar.fireEvent("updatesheetsinfo", me.statusbar);
}
me.api.asc_enableKeyEvents(true);
}
})).show(left, top);
}
},
moveWorksheet: function (cut, silent, index, destPos) {
var me = this;
var wc = me.api.asc_getWorksheetsCount(),
items = [],
i = -1;
while (++i < wc) {
if (!this.api.asc_isWorksheetHidden(i)) {
items.push({
value: me.api.asc_getWorksheetName(i),
inindex: i
});
}
}
if (!_.isUndefined(silent)) {
me.api.asc_showWorksheet(items[index].inindex);
Common.NotificationCenter.trigger("comments:updatefilter", {
property: "uid",
value: new RegExp("^(doc_|sheet" + this.api.asc_getActiveWorksheetId() + "_)")
});
if (!_.isUndefined(destPos)) {
me.api.asc_moveWorksheet(items.length === destPos ? wc : items[destPos].inindex);
}
return;
} (new SSE.Views.Statusbar.CopyDialog({
title: cut ? me.statusbar.itemMove : me.statusbar.itemCopy,
ismove: cut,
names: items,
handler: function (btn, i) {
if (btn == "ok") {
if (cut) {
me.api.asc_moveWorksheet(i == -255 ? wc : i);
} else {
var new_text = me.createCopyName(me.api.asc_getWorksheetName(me.api.asc_getActiveWorksheetIndex()));
me.api.asc_copyWorksheet(i == -255 ? wc : i, new_text);
}
}
me.api.asc_enableKeyEvents(true);
}
})).show();
},
onAddWorksheetClick: function (o, index, opts) {
if (this.api) {
this.api.asc_closeCellEditor();
this.api.asc_addWorksheet(this.createSheetName());
Common.NotificationCenter.trigger("comments:updatefilter", {
property: "uid",
value: new RegExp("^(doc_|sheet" + this.api.asc_getActiveWorksheetId() + "_)")
},
false);
}
Common.NotificationCenter.trigger("edit:complete", this.statusbar);
},
selectTab: function (sheetindex) {
if (this.api) {
var hidden = this.api.asc_isWorksheetHidden(sheetindex);
if (!hidden) {
var tab = _.findWhere(this.statusbar.tabbar.tabs, {
sheetindex: sheetindex
});
if (tab) {
this.statusbar.tabbar.setActive(tab);
}
}
}
},
moveCurrentTab: function (direction) {
if (this.api) {
var indTab = 0,
tabBar = this.statusbar.tabbar,
index = this.api.asc_getActiveWorksheetIndex(),
length = tabBar.tabs.length;
this.statusbar.tabMenu.hide();
this.api.asc_closeCellEditor();
for (var i = 0; i < length; ++i) {
if (tabBar.tabs[i].sheetindex === index) {
indTab = i;
if (direction > 0) {
indTab++;
if (indTab >= length) {
indTab = 0;
}
} else {
indTab--;
if (indTab < 0) {
indTab = length - 1;
}
}
tabBar.setActive(indTab);
this.api.asc_showWorksheet(tabBar.getAt(indTab).sheetindex);
break;
}
}
}
},
onApiUpdateTabColor: function (index) {
this.loadTabColor(index);
},
setWorksheetColor: function (color) {
if (this.api) {
var sindex = this.api.asc_getActiveWorksheetIndex();
var tab = _.findWhere(this.statusbar.tabbar.tabs, {
sheetindex: sindex
});
if (tab) {
if ("transparent" === color) {
this.api.asc_setWorksheetTabColor(sindex, null);
tab.$el.find("a").css("box-shadow", "");
} else {
var asc_clr = Common.Utils.ThemeColor.getRgbColor(color);
if (asc_clr) {
this.api.asc_setWorksheetTabColor(sindex, asc_clr);
this.setTabLineColor(tab, asc_clr);
}
}
}
}
},
updateThemeColors: function () {
var updateColors = function (picker, defaultColorIndex) {
if (picker) {
var clr, effectcolors = Common.Utils.ThemeColor.getEffectColors();
for (var i = 0; i < effectcolors.length; ++i) {
if (typeof(picker.currentColor) == "object" && clr === undefined && picker.currentColor.effectId == effectcolors[i].effectId) {
clr = effectcolors[i];
}
}
picker.updateColors(effectcolors, Common.Utils.ThemeColor.getStandartColors());
if (picker.currentColor === undefined) {
picker.currentColor = effectcolors[defaultColorIndex];
} else {
if (clr !== undefined) {
picker.currentColor = clr;
}
}
}
};
if (this.statusbar) {
updateColors(this.statusbar.mnuTabColor, 1);
}
},
onNewBorderColor: function () {
if (this.statusbar && this.statusbar.mnuTabColor) {
this.statusbar.mnuTabColor.addNewColor();
}
},
updateTabsColors: function (updateCurrentColor) {
var i = -1,
tabind = -1,
color = null,
clr = null,
ishidden = false,
wc = this.api.asc_getWorksheetsCount(),
sindex = this.api.asc_getActiveWorksheetIndex();
if (!_.isUndefined(updateCurrentColor)) {
var toolbarController = this.application.getController("Toolbar");
if (toolbarController) {
this.statusbar.mnuTabColor.updateCustomColors();
color = this.api.asc_getWorksheetTabColor(sindex);
if (color) {
if (color.get_type() == c_oAscColor.COLOR_TYPE_SCHEME) {
clr = {
color: Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b()),
effectValue: color.get_value()
};
} else {
clr = Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b());
}
}
if (_.isObject(clr)) {
var isselected = false;
for (i = 0; i < 10; i++) {
if (Common.Utils.ThemeColor.ThemeValues[i] === clr.effectValue) {
this.statusbar.mnuTabColor.select(clr, true);
isselected = true;
break;
}
}
if (!isselected) {
this.statusbar.mnuTabColor.clearSelection();
}
} else {
this.statusbar.mnuTabColor.select(clr || "transparent", true);
}
}
}
i = -1;
while (++i < wc) {
++tabind;
ishidden = this.api.asc_isWorksheetHidden(i);
if (ishidden) {
--tabind;
}
if (!ishidden) {
this.setTabLineColor(this.statusbar.tabbar.getAt(tabind), this.api.asc_getWorksheetTabColor(i));
}
}
},
loadTabColor: function (sheetindex) {
if (this.api) {
if (!this.api.asc_isWorksheetHidden(sheetindex)) {
var tab = _.findWhere(this.statusbar.tabbar.tabs, {
sheetindex: sheetindex
});
if (tab) {
this.setTabLineColor(tab, this.api.asc_getWorksheetTabColor(sheetindex));
}
}
}
},
setTabLineColor: function (tab, color) {
if (tab) {
if (null !== color) {
color = "#" + Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b());
} else {
color = "";
}
if (color.length) {
if (!tab.isActive()) {
color = "0px 3px 0 " + Common.Utils.RGBColor(color).toRGBA(0.7) + " inset";
} else {
color = "0px 3px 0 " + color + " inset";
}
tab.$el.find("a").css("box-shadow", color);
} else {
tab.$el.find("a").css("box-shadow", "");
}
}
},
onZoomShow: function (e) {
if (e.target.classList.contains("disabled")) {
return false;
}
},
tipUsers: "Document is in the collaborative editing mode.",
tipMoreUsers: "and %1 users.",
tipShowUsers: "To see all users click the icon below.",
zoomText: "Zoom {0}%",
errorLastSheet: "Workbook must have at least one visible worksheet.",
errorRemoveSheet: "Can't delete the worksheet.",
warnDeleteSheet: "The worksheet maybe has data. Proceed operation?",
strSheet : "Sheet"
},
SSE.Controllers.Statusbar || {}));
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,109 @@
/*
* (c) Copyright Ascensio System SIA 2010-2015
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
define(["core", "common/main/lib/view/Header", "spreadsheeteditor/main/app/view/Viewport"], function (Viewport) {
SSE.Controllers.Viewport = Backbone.Controller.extend({
models: [],
collections: [],
views: ["Viewport", "Common.Views.Header"],
initialize: function () {
this.addListeners({
"Viewport": {}
});
},
setApi: function (api) {
this.api = api;
},
onLaunch: function () {
this.viewport = this.createView("Viewport").render();
this.header = this.createView("Common.Views.Header", {
headerCaption: "Spreadsheet Editor"
}).render();
Common.NotificationCenter.on("layout:changed", _.bind(this.onLayoutChanged, this));
$(window).on("resize", _.bind(this.onWindowResize, this));
this.viewport.celayout.on("layout:resizedrag", function () {
this.viewport.fireEvent("layout:resizedrag", [this, "cell:edit"]);
this.api.asc_Resize();
},
this);
this.viewport.hlayout.on("layout:resizedrag", function () {
this.api.asc_Resize();
},
this);
this.boxSdk = $("#editor_sdk");
this.boxFormula = $("#cell-editing-box");
this.boxSdk.css("border-left", "none");
this.boxFormula.css("border-left", "none");
},
onLayoutChanged: function (area) {
switch (area) {
default:
this.viewport.vlayout.doLayout();
this.viewport.celayout.doLayout();
case "rightmenu":
this.viewport.hlayout.doLayout();
break;
case "leftmenu":
var panel = this.viewport.hlayout.items[0];
if (panel.resize.el) {
if (panel.el.width() > 40) {
this.boxSdk.css("border-left", "");
this.boxFormula.css("border-left", "");
panel.resize.el.show();
} else {
panel.resize.el.hide();
this.boxSdk.css("border-left", "none");
this.boxFormula.css("border-left", "none");
}
}
this.viewport.hlayout.doLayout();
break;
case "header":
case "toolbar":
case "status":
this.viewport.vlayout.doLayout();
this.viewport.celayout.doLayout();
break;
case "celleditor":
if (arguments[1]) {
this.boxSdk.css("border-top", arguments[1] == "hidden" ? "none" : "");
}
this.viewport.celayout.doLayout();
break;
}
this.api.asc_Resize();
},
onWindowResize: function (e) {
this.onLayoutChanged("window");
Common.NotificationCenter.trigger("window:resize");
}
});
});