Refactoring create new file: show "create new" when templates are available in config

This commit is contained in:
Julia Radzhabova 2021-08-24 18:30:55 +03:00
parent 2b81097012
commit 704c5a6a00
9 changed files with 36 additions and 21 deletions

View file

@ -373,7 +373,7 @@ define([
this.appOptions.user.anonymous && Common.localStorage.setItem("guest-id", this.appOptions.user.id);
this.appOptions.isDesktopApp = this.editorConfig.targetApp == 'desktop';
this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl);
this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl) || this.editorConfig.templates && this.editorConfig.templates.length;
this.appOptions.canOpenRecent = this.editorConfig.recent !== undefined && !this.appOptions.isDesktopApp;
this.appOptions.templates = this.editorConfig.templates;
this.appOptions.recent = this.editorConfig.recent;

View file

@ -389,7 +389,7 @@ define([
if ( this.mode.canCreateNew ) {
if (this.mode.templates && this.mode.templates.length) {
$('a',this.miNew.$el).text(this.btnCreateNewCaption + '...');
!this.panels['new'] && (this.panels['new'] = ((new DE.Views.FileMenuPanels.CreateNew({menu: this, docs: this.mode.templates})).render()));
!this.panels['new'] && (this.panels['new'] = ((new DE.Views.FileMenuPanels.CreateNew({menu: this, docs: this.mode.templates, blank: this.mode.canRequestCreateNew || !!this.mode.createUrl})).render()));
}
}

View file

@ -869,21 +869,23 @@ define([
template: _.template([
'<h3 style="margin-top: 20px;"><%= scope.txtCreateNew %></h3>',
'<div class="thumb-list">',
'<% if (blank) { %> ',
'<div class="blank-document">',
'<div class="blank-document-btn">',
'<svg class="btn-blank-format"><use xlink:href="#svg-format-blank"></use></svg>',
'</div>',
'<div class="title"><%= scope.txtBlank %></div>',
'</div>',
'<% _.each(docs, function(item, index) { %>',
'<div class="thumb-wrap" template="<%= item.url %>">',
'<div class="thumb" ',
'<% if (!_.isEmpty(item.image)) {%> ',
' style="background-image: url(<%= item.image %>);">',
' <%} else {' +
'print(\"><svg class=\'btn-blank-format\'><use xlink:href=\'#svg-file-template\'></use></svg>\")' +
' } %>',
'</div>',
'<% } %>',
'<% _.each(docs, function(item, index) { %>',
'<div class="thumb-wrap" template="<%= item.url %>">',
'<div class="thumb" ',
'<% if (!_.isEmpty(item.image)) {%> ',
' style="background-image: url(<%= item.image %>);">',
' <%} else {' +
'print(\"><svg class=\'btn-blank-format\'><use xlink:href=\'#svg-file-template\'></use></svg>\")' +
' } %>',
'</div>',
'<div class="title"><%= Common.Utils.String.htmlEncode(item.title || item.name || "") %></div>',
'</div>',
'<% }) %>',
@ -894,14 +896,17 @@ define([
Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.menu = options.menu;
this.docs = options.docs;
this.blank = !!options.blank;
},
render: function() {
this.$el.html(this.template({
scope: this,
docs: this.options[0].docs
docs: this.docs,
blank: this.blank
}));
var docs=[{title: this.txtBlank}].concat(this.options[0].docs);
var docs = (this.blank ? [{title: this.txtBlank}] : []).concat(this.docs);
var thumbsElm= this.$el.find('.thumb-wrap, .blank-document');
_.each(thumbsElm, function (tmb, index){
$(tmb).find('.title').tooltip({

View file

@ -333,7 +333,7 @@ define([
this.appOptions.user.anonymous && Common.localStorage.setItem("guest-id", this.appOptions.user.id);
this.appOptions.isDesktopApp = this.editorConfig.targetApp == 'desktop';
this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl);
this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl) || this.editorConfig.templates && this.editorConfig.templates.length;
this.appOptions.canOpenRecent = this.editorConfig.recent !== undefined && !this.appOptions.isDesktopApp;
this.appOptions.templates = this.editorConfig.templates;
this.appOptions.recent = this.editorConfig.recent;

View file

@ -388,7 +388,7 @@ define([
if ( this.mode.canCreateNew ) {
if (this.mode.templates && this.mode.templates.length) {
$('a',this.miNew.$el).text(this.btnCreateNewCaption + '...');
!this.panels['new'] && (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, blank: this.mode.canRequestCreateNew || !!this.mode.createUrl})).render());
}
}

View file

@ -767,12 +767,14 @@ define([
template: _.template([
'<h3 style="margin-top: 20px;"><%= scope.txtCreateNew %></h3>',
'<div class="thumb-list">',
'<% if (blank) { %> ',
'<div class="blank-document">',
'<div class="blank-document-btn">',
'<svg class="btn-blank-format"><use xlink:href="#svg-format-blank"></use></svg>',
'</div>',
'<div class="title"><%= scope.txtBlank %></div>',
'</div>',
'<% } %>',
'<% _.each(docs, function(item, index) { %>',
'<div class="thumb-wrap" template="<%= item.url %>">',
'<div class="thumb" ',
@ -792,14 +794,17 @@ define([
Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.menu = options.menu;
this.docs = options.docs;
this.blank = !!options.blank;
},
render: function() {
this.$el.html(this.template({
scope: this,
docs: this.options[0].docs
docs: this.docs,
blank: this.blank
}));
var docs=[{title: this.txtBlank}].concat(this.options[0].docs);
var docs = (this.blank ? [{title: this.txtBlank}] : []).concat(this.docs);
var thumbsElm= this.$el.find('.thumb-wrap, .blank-document');
_.each(thumbsElm, function (tmb, index){
$(tmb).find('.title').tooltip({

View file

@ -372,7 +372,7 @@ define([
this.appOptions.user.anonymous && Common.localStorage.setItem("guest-id", this.appOptions.user.id);
this.appOptions.isDesktopApp = this.editorConfig.targetApp == 'desktop';
this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl);
this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl) || this.editorConfig.templates && this.editorConfig.templates.length;
this.appOptions.canOpenRecent = this.editorConfig.recent !== undefined && !this.appOptions.isDesktopApp;
this.appOptions.templates = this.editorConfig.templates;
this.appOptions.recent = this.editorConfig.recent;

View file

@ -374,7 +374,7 @@ define([
if ( this.mode.canCreateNew ) {
if (this.mode.templates && this.mode.templates.length) {
$('a',this.miNew.$el).text(this.btnCreateNewCaption + '...');
!this.panels['new'] && (this.panels['new'] = (new SSE.Views.FileMenuPanels.CreateNew({menu: this, docs: this.mode.templates})).render());
!this.panels['new'] && (this.panels['new'] = (new SSE.Views.FileMenuPanels.CreateNew({menu: this, docs: this.mode.templates, blank: this.mode.canRequestCreateNew || !!this.mode.createUrl})).render());
}
}

View file

@ -1734,12 +1734,14 @@ define([
template: _.template([
'<h3 style="margin-top: 20px;"><%= scope.txtCreateNew %></h3>',
'<div class="thumb-list">',
'<% if (blank) { %> ',
'<div class="blank-document">',
'<div class="blank-document-btn">',
'<svg class="btn-blank-format"><use xlink:href="#svg-format-blank"></use></svg>',
'</div>',
'<div class="title"><%= scope.txtBlank %></div>',
'</div>',
'<% } %>',
'<% _.each(docs, function(item, index) { %>',
'<div class="thumb-wrap" template="<%= item.url %>">',
'<div class="thumb" ',
@ -1759,14 +1761,17 @@ define([
Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.menu = options.menu;
this.docs = options.docs;
this.blank = !!options.blank;
},
render: function() {
this.$el.html(this.template({
scope: this,
docs: this.options[0].docs
docs: this.docs,
blank: this.blank
}));
var docs=[{title: this.txtBlank}].concat(this.options[0].docs);
var docs = (this.blank ? [{title: this.txtBlank}] : []).concat(this.docs);
var thumbsElm= this.$el.find('.thumb-wrap, .blank-document');
_.each(thumbsElm, function (tmb, index){
$(tmb).find('.title').tooltip({