diff --git a/apps/presentationeditor/main/app/view/FileMenu.js b/apps/presentationeditor/main/app/view/FileMenu.js index f76d34328..74be7d698 100644 --- a/apps/presentationeditor/main/app/view/FileMenu.js +++ b/apps/presentationeditor/main/app/view/FileMenu.js @@ -49,6 +49,7 @@ define([ PE.Views.FileMenu = Common.UI.BaseView.extend(_.extend({ el: '#file-menu-panel', + rendered: false, options: {alias:'FileMenu'}, template: _.template(tpl), @@ -84,89 +85,92 @@ define([ }, render: function () { - this.$el = $(this.el); - this.$el.html(this.template()); + var $markup = $(this.template()); this.miSave = new Common.UI.MenuItem({ - el : $('#fm-btn-save',this.el), + el : $markup.elementById('#fm-btn-save'), action : 'save', caption : this.btnSaveCaption, canFocused: false, disabled: true }); + if ( !!this.options.miSave ) { + this.miSave.setDisabled(this.options.miSave.isDisabled()); + delete this.options.miSave; + } this.miEdit = new Common.UI.MenuItem({ - el : $('#fm-btn-edit',this.el), + el : $markup.elementById('#fm-btn-edit'), action : 'edit', caption : this.btnToEditCaption, canFocused: false }); this.miDownload = new Common.UI.MenuItem({ - el : $('#fm-btn-download',this.el), + el : $markup.elementById('#fm-btn-download'), action : 'saveas', caption : this.btnDownloadCaption, canFocused: false }); this.miSaveCopyAs = new Common.UI.MenuItem({ - el : $('#fm-btn-save-copy',this.el), + el : $markup.elementById('#fm-btn-save-copy'), action : 'save-copy', caption : this.btnSaveCopyAsCaption, canFocused: false }); this.miSaveAs = new Common.UI.MenuItem({ - el : $('#fm-btn-save-desktop',this.el), + el : $markup.elementById('#fm-btn-save-desktop'), action : 'save-desktop', caption : this.btnSaveAsCaption, canFocused: false }); this.miPrint = new Common.UI.MenuItem({ - el : $('#fm-btn-print',this.el), + el : $markup.elementById('#fm-btn-print'), action : 'print', caption : this.btnPrintCaption, canFocused: false }); this.miRename = new Common.UI.MenuItem({ - el : $('#fm-btn-rename',this.el), + el : $markup.elementById('#fm-btn-rename'), action : 'rename', caption : this.btnRenameCaption, canFocused: false }); this.miProtect = new Common.UI.MenuItem({ - el : $('#fm-btn-protect',this.el), + el : $markup.elementById('#fm-btn-protect'), action : 'protect', caption : this.btnProtectCaption, canFocused: false }); this.miRecent = new Common.UI.MenuItem({ - el : $('#fm-btn-recent',this.el), + el : $markup.elementById('#fm-btn-recent'), action : 'recent', caption : this.btnRecentFilesCaption, canFocused: false }); this.miNew = new Common.UI.MenuItem({ - el : $('#fm-btn-create',this.el), + el : $markup.elementById('#fm-btn-create'), action : 'new', caption : this.btnCreateNewCaption, canFocused: false }); this.miAccess = new Common.UI.MenuItem({ - el : $('#fm-btn-rights',this.el), + el : $markup.elementById('#fm-btn-rights'), action : 'rights', caption : this.btnRightsCaption, canFocused: false }); this.miHelp = new Common.UI.MenuItem({ - el : $('#fm-btn-help',this.el), + el : $markup.elementById('#fm-btn-help'), action : 'help', caption : this.btnHelpCaption, canFocused: false @@ -175,7 +179,7 @@ define([ this.items = []; this.items.push( new Common.UI.MenuItem({ - el : $('#fm-btn-return',this.el), + el : $markup.elementById('#fm-btn-return'), action : 'back', caption : this.btnCloseMenuCaption, canFocused: false @@ -191,35 +195,37 @@ define([ this.miRecent, this.miNew, new Common.UI.MenuItem({ - el : $('#fm-btn-info',this.el), + el : $markup.elementById('#fm-btn-info'), action : 'info', caption : this.btnInfoCaption, canFocused: false }), this.miAccess, new Common.UI.MenuItem({ - el : $('#fm-btn-settings',this.el), + el : $markup.elementById('#fm-btn-settings'), action : 'opts', caption : this.btnSettingsCaption, canFocused: false }), this.miHelp, new Common.UI.MenuItem({ - el : $('#fm-btn-back',this.el), + el : $markup.elementById('#fm-btn-back'), action : 'exit', caption : this.btnBackCaption, canFocused: false }) ); - var me = this; - me.panels = { - 'opts' : (new PE.Views.FileMenuPanels.Settings({menu:me})).render(), - 'info' : (new PE.Views.FileMenuPanels.DocumentInfo({menu:me})).render(), - 'rights' : (new PE.Views.FileMenuPanels.DocumentRights({menu:me})).render() - }; + this.rendered = true; + this.$el.html($markup); + this.$el.find('.content-box').hide(); + this.applyMode(); - me.$el.find('.content-box').hide(); + if ( !!this.api ) { + this.panels['info'].setApi(this.api); + if ( this.panels['protect'] ) + this.panels['protect'].setApi(api); + } return this; }, @@ -227,6 +233,9 @@ define([ show: function(panel) { if (this.isVisible() && panel===undefined || !this.mode) return; + if ( !this.rendered ) + this.render(); + var defPanel = (this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline)) ? 'saveas' : 'info'; if (!panel) panel = this.active || defPanel; @@ -245,6 +254,16 @@ define([ }, applyMode: function() { + if (!this.panels) { + this.panels = { + 'opts' : (new PE.Views.FileMenuPanels.Settings({menu:this})).render(this.$el.find('#panel-settings')), + 'info' : (new PE.Views.FileMenuPanels.DocumentInfo({menu:this})).render(this.$el.find('#panel-info')), + 'rights' : (new PE.Views.FileMenuPanels.DocumentRights({menu:this})).render(this.$el.find('#panel-rights')) + }; + } + + if (!this.mode) return; + this.miDownload[(this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline))?'show':'hide'](); this.miSaveCopyAs[(this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline)) && (this.mode.canRequestSaveAs || this.mode.saveAsUrl) ?'show':'hide'](); this.miSaveAs[(this.mode.canDownload && this.mode.isDesktopApp && this.mode.isOffline)?'show':'hide'](); @@ -278,30 +297,28 @@ define([ if ( this.mode.canCreateNew ) { if (this.mode.templates && this.mode.templates.length) { $('a',this.miNew.$el).text(this.btnCreateNewCaption + '...'); - this.panels['new'] = ((new PE.Views.FileMenuPanels.CreateNew({menu: this, docs: this.mode.templates})).render()); + !this.panels['new'] && (this.panels['new'] = ((new PE.Views.FileMenuPanels.CreateNew({menu: this, docs: this.mode.templates})).render())); } } - if ( this.mode.canOpenRecent ) { - if (this.mode.recent){ - this.panels['recent'] = (new PE.Views.FileMenuPanels.RecentFiles({menu:this, recent: this.mode.recent})).render(); - } + if ( this.mode.canOpenRecent && this.mode.recent ) { + !this.panels['recent'] && (this.panels['recent'] = (new PE.Views.FileMenuPanels.RecentFiles({menu:this, recent: this.mode.recent})).render()); } if (this.mode.canProtect) { - this.panels['protect'] = (new PE.Views.FileMenuPanels.ProtectDoc({menu:this})).render(); + !this.panels['protect'] && (this.panels['protect'] = (new PE.Views.FileMenuPanels.ProtectDoc({menu:this})).render()); this.panels['protect'].setMode(this.mode); } if (this.mode.canDownload) { - this.panels['saveas'] = ((new PE.Views.FileMenuPanels.ViewSaveAs({menu: this})).render()); + !this.panels['saveas'] && (this.panels['saveas'] = ((new PE.Views.FileMenuPanels.ViewSaveAs({menu: this})).render())); } if (this.mode.canDownload && (this.mode.canRequestSaveAs || this.mode.saveAsUrl)) { - this.panels['save-copy'] = ((new PE.Views.FileMenuPanels.ViewSaveCopy({menu: this})).render()); + !this.panels['save-copy'] && (this.panels['save-copy'] = ((new PE.Views.FileMenuPanels.ViewSaveCopy({menu: this})).render())); } - if (this.mode.canHelp) { + if (this.mode.canHelp && !this.panels['help']) { this.panels['help'] = ((new PE.Views.FileMenuPanels.Help({menu: this})).render()); this.panels['help'].setLangConfig(this.mode.lang); } @@ -319,14 +336,21 @@ define([ this.mode = mode; } - if (!delay) this.applyMode(); + if (!delay) { + if ( this.rendered ) + this.applyMode(); + } }, setApi: function(api) { this.api = api; - this.panels['info'].setApi(api); - if (this.panels['protect']) this.panels['protect'].setApi(api); + + if ( this.rendered ) { + this.panels['info'].setApi(api); + if (this.panels['protect']) this.panels['protect'].setApi(api); + } this.api.asc_registerCallback('asc_onDocumentName', _.bind(this.onDocumentName, this)); + return this; }, loadDocument: function(data) { @@ -370,7 +394,8 @@ define([ onDocumentName: function(name) { this.document.title = name; - this.panels['info'].updateInfo(this.document); + if (this.rendered) + this.panels['info'].updateInfo(this.document); }, isVisible: function () { @@ -378,8 +403,12 @@ define([ }, getButton: function(type) { - if (type == 'save') - return this.miSave; + if (type == 'save') { + if (this.rendered) + return this.miSave; + else + return this.options.miSave ? this.options.miSave : (this.options.miSave = new Common.UI.MenuItem({})); + } }, btnSaveCaption : 'Save', diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index af9828b86..d0186f790 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -84,12 +84,12 @@ define([ }, render: function() { - $(this.el).html(this.template({rows:this.formats})); + this.$el.html(this.template({rows:this.formats})); $('.btn-doc-format',this.el).on('click', _.bind(this.onFormatClick,this)); if (_.isUndefined(this.scroller)) { this.scroller = new Common.UI.Scroller({ - el: $(this.el), + el: this.$el, suppressScrollX: true }); } @@ -140,12 +140,12 @@ define([ }, render: function() { - $(this.el).html(this.template({rows:this.formats})); + this.$el.html(this.template({rows:this.formats})); $('.btn-doc-format',this.el).on('click', _.bind(this.onFormatClick,this)); if (_.isUndefined(this.scroller)) { this.scroller = new Common.UI.Scroller({ - el: $(this.el), + el: this.$el, suppressScrollX: true }); } @@ -221,21 +221,22 @@ define([ this.menu = options.menu; }, - render: function() { - $(this.el).html(this.template({scope: this})); + render: function(node) { + var me = this; + var $markup = $(this.template({scope: this})); this.chSpell = new Common.UI.CheckBox({ - el: $('#fms-chb-spell-check'), + el: $markup.findById('#fms-chb-spell-check'), labelText: this.strSpellCheckMode }); this.chInputMode = new Common.UI.CheckBox({ - el: $('#fms-chb-input-mode'), + el: $markup.findById('#fms-chb-input-mode'), labelText: this.strInputMode }); this.cmbZoom = new Common.UI.ComboBox({ - el : $('#fms-cmb-zoom'), + el : $markup.findById('#fms-cmb-zoom'), style : 'width: 160px;', editable : false, cls : 'input-group-nr', @@ -259,7 +260,7 @@ define([ /** coauthoring begin **/ this.cmbCoAuthMode = new Common.UI.ComboBox({ - el : $('#fms-cmb-coauth-mode'), + el : $markup.findById('#fms-cmb-coauth-mode'), style : 'width: 160px;', editable : false, cls : 'input-group-nr', @@ -267,38 +268,38 @@ define([ { value: 1, displayValue: this.strFast, descValue: this.strCoAuthModeDescFast}, { value: 0, displayValue: this.strStrict, descValue: this.strCoAuthModeDescStrict } ] - }).on('selected', _.bind(function(combo, record) { - if (record.value == 1 && (this.chAutosave.getValue()!=='checked')) - this.chAutosave.setValue(1); - this.lblCoAuthMode.text(record.descValue); - }, this)); + }).on('selected', function(combo, record) { + if (record.value == 1 && (me.chAutosave.getValue()!=='checked')) + me.chAutosave.setValue(1); + me.lblCoAuthMode.text(record.descValue); + }); - this.lblCoAuthMode = $('#fms-lbl-coauth-mode'); + this.lblCoAuthMode = $markup.findById('#fms-lbl-coauth-mode'); /** coauthoring end **/ this.chAutosave = new Common.UI.CheckBox({ - el: $('#fms-chb-autosave'), + el: $markup.findById('#fms-chb-autosave'), labelText: this.strAutosave - }).on('change', _.bind(function(field, newValue, oldValue, eOpts){ - if (field.getValue()!=='checked' && this.cmbCoAuthMode.getValue()) { - this.cmbCoAuthMode.setValue(0); - this.lblCoAuthMode.text(this.strCoAuthModeDescStrict); + }).on('change', function(field, newValue, oldValue, eOpts){ + if (field.getValue()!=='checked' && me.cmbCoAuthMode.getValue()) { + me.cmbCoAuthMode.setValue(0); + me.lblCoAuthMode.text(me.strCoAuthModeDescStrict); } - }, this)); - this.lblAutosave = $('#fms-lbl-autosave'); + }); + this.lblAutosave = $markup.findById('#fms-lbl-autosave'); this.chForcesave = new Common.UI.CheckBox({ - el: $('#fms-chb-forcesave'), + el: $markup.findById('#fms-chb-forcesave'), labelText: this.strForcesave }); this.chAlignGuides = new Common.UI.CheckBox({ - el: $('#fms-chb-align-guides'), + el: $markup.findById('#fms-chb-align-guides'), labelText: this.strAlignGuides }); this.cmbFontRender = new Common.UI.ComboBox({ - el : $('#fms-cmb-font-render'), + el : $markup.findById('#fms-cmb-font-render'), style : 'width: 160px;', editable : false, cls : 'input-group-nr', @@ -310,7 +311,7 @@ define([ }); this.cmbUnit = new Common.UI.ComboBox({ - el : $('#fms-cmb-unit'), + el : $markup.findById('#fms-cmb-unit'), style : 'width: 160px;', editable : false, cls : 'input-group-nr', @@ -322,14 +323,16 @@ define([ }); this.btnApply = new Common.UI.Button({ - el: '#fms-btn-apply' + el: $markup.findById('#fms-btn-apply') }); this.btnApply.on('click', _.bind(this.applySettings, this)); + this.$el = $(node).html($markup); + if (_.isUndefined(this.scroller)) { this.scroller = new Common.UI.Scroller({ - el: $(this.el), + el: this.$el, suppressScrollX: true }); } @@ -472,7 +475,7 @@ define([ }, render: function() { - $(this.el).html(this.template()); + this.$el.html(this.template()); this.viewRecentPicker = new Common.UI.DataView({ el: $('#id-recent-view'), @@ -490,7 +493,7 @@ define([ if (_.isUndefined(this.scroller)) { this.scroller = new Common.UI.Scroller({ - el: $(this.el), + el: this.$el, suppressScrollX: true }); } @@ -552,14 +555,14 @@ define([ }, render: function() { - $(this.el).html(this.template({ + this.$el.html(this.template({ scope: this, docs: this.options[0].docs })); if (_.isUndefined(this.scroller)) { this.scroller = new Common.UI.Scroller({ - el: $(this.el), + el: this.$el, suppressScrollX: true }); } @@ -662,15 +665,14 @@ define([ this.authors = []; }, - render: function() { - $(this.el).html(this.template()); - + render: function(node) { var me = this; + var $markup = $(me.template()); // server info - this.lblPlacement = $('#id-info-placement'); - this.lblOwner = $('#id-info-owner'); - this.lblUploaded = $('#id-info-uploaded'); + this.lblPlacement = $markup.findById('#id-info-placement'); + this.lblOwner = $markup.findById('#id-info-owner'); + this.lblUploaded = $markup.findById('#id-info-uploaded'); // edited info var keyDownBefore = function(input, e){ @@ -685,7 +687,7 @@ define([ }; this.inputTitle = new Common.UI.InputField({ - el : $('#id-info-title'), + el : $markup.findById('#id-info-title'), style : 'width: 200px;', placeHolder : this.txtAddText, validateOnBlur: false @@ -696,7 +698,7 @@ define([ } }).on('keydown:before', keyDownBefore); this.inputSubject = new Common.UI.InputField({ - el : $('#id-info-subject'), + el : $markup.findById('#id-info-subject'), style : 'width: 200px;', placeHolder : this.txtAddText, validateOnBlur: false @@ -707,7 +709,7 @@ define([ } }).on('keydown:before', keyDownBefore); this.inputComment = new Common.UI.InputField({ - el : $('#id-info-comment'), + el : $markup.findById('#id-info-comment'), style : 'width: 200px;', placeHolder : this.txtAddText, validateOnBlur: false @@ -719,18 +721,18 @@ define([ }).on('keydown:before', keyDownBefore); // modify info - this.lblModifyDate = $('#id-info-modify-date'); - this.lblModifyBy = $('#id-info-modify-by'); + this.lblModifyDate = $markup.findById('#id-info-modify-date'); + this.lblModifyBy = $markup.findById('#id-info-modify-by'); // creation info - this.lblDate = $('#id-info-date'); - this.lblApplication = $('#id-info-appname'); - this.tblAuthor = $('#id-info-author table'); - this.trAuthor = $('#id-info-add-author').closest('tr'); + this.lblDate = $markup.findById('#id-info-date'); + this.lblApplication = $markup.findById('#id-info-appname'); + this.tblAuthor = $markup.findById('#id-info-author table'); + this.trAuthor = $markup.findById('#id-info-add-author').closest('tr'); this.authorTpl = '