From 19e10aa7480be2878bbc500f93eb696e0aa1ac47 Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 27 Oct 2015 17:12:27 +0200 Subject: [PATCH] stream post --- .../Espo/Resources/i18n/en_US/Global.json | 1 + .../res/templates/stream/record/edit.tpl | 10 ++++- frontend/client/src/views/record/base.js | 8 ++++ frontend/client/src/views/record/detail.js | 4 -- frontend/client/src/views/stream.js | 4 ++ frontend/client/src/views/stream/panel.js | 3 +- .../client/src/views/stream/record/edit.js | 45 ++++++++++++++++--- 7 files changed, 63 insertions(+), 12 deletions(-) diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.json index f4c50f7ad9..c8618082e3 100644 --- a/application/Espo/Resources/i18n/en_US/Global.json +++ b/application/Espo/Resources/i18n/en_US/Global.json @@ -175,6 +175,7 @@ }, "messages": { "pleaseWait": "Please wait...", + "posting": "Posting...", "confirmLeaveOutMessage": "Are you sure you want to leave the form?", "notModified": "You have not modified the record", "duplicate": "The record you are creating seems to be a duplicate", diff --git a/frontend/client/res/templates/stream/record/edit.tpl b/frontend/client/res/templates/stream/record/edit.tpl index 7396037aae..18c2f6e090 100644 --- a/frontend/client/res/templates/stream/record/edit.tpl +++ b/frontend/client/res/templates/stream/record/edit.tpl @@ -4,8 +4,14 @@
-
-
{{{attachments}}}
+ +
+
+ + +
{{{attachments}}}
+ +
diff --git a/frontend/client/src/views/record/base.js b/frontend/client/src/views/record/base.js index e084a0f352..5168dfba47 100644 --- a/frontend/client/src/views/record/base.js +++ b/frontend/client/src/views/record/base.js @@ -103,6 +103,10 @@ Espo.define('views/record/base', 'view', function (Dep) { this.$el.find('.panel[data-panel-name="'+name+'"]').addClass('hidden'); }, + setConfirmLeaveOut: function (value) { + this.getRouter().confirmLeaveOut = value; + }, + getFields: function () { var fields = {}; this.fieldList.forEach(function (item) { @@ -127,6 +131,10 @@ Espo.define('views/record/base', 'view', function (Dep) { throw new Error('Model has not been injected into record view.'); } + this.on('remove', function () { + this.setConfirmLeaveOut(false); + }, this); + this.events = this.events || {}; this.scope = this.model.name; diff --git a/frontend/client/src/views/record/detail.js b/frontend/client/src/views/record/detail.js index 441865a074..975ac8a5e5 100644 --- a/frontend/client/src/views/record/detail.js +++ b/frontend/client/src/views/record/detail.js @@ -113,10 +113,6 @@ Espo.define('views/record/detail', 'views/record/base', function (Dep) { } }, - setConfirmLeaveOut: function (value) { - this.getRouter().confirmLeaveOut = value; - }, - actionEdit: function () { if (!this.editModeDisabled) { this.setEditMode(); diff --git a/frontend/client/src/views/stream.js b/frontend/client/src/views/stream.js index f7d9d47dd1..281807d711 100644 --- a/frontend/client/src/views/stream.js +++ b/frontend/client/src/views/stream.js @@ -45,6 +45,10 @@ Espo.define('views/stream', 'view', function (Dep) { el: this.options.el + ' .create-post-container', model: model, interactiveMode: true + }, function (view) { + this.listenTo(view, 'after:save', function () { + this.getView('list').showNewRecords(); + }, this); }, this); this.wait(false); }, this); diff --git a/frontend/client/src/views/stream/panel.js b/frontend/client/src/views/stream/panel.js index 138621744b..d6e8029e9c 100644 --- a/frontend/client/src/views/stream/panel.js +++ b/frontend/client/src/views/stream/panel.js @@ -66,7 +66,6 @@ Espo.define('views/stream/panel', ['views/record/panels/relationship', 'lib!Text if (this.$textarea.val() == '') { var attachmentsIds = this.seed.get('attachmentsIds'); if (!attachmentsIds.length) { - $('body').off('click.stream-panel'); this.disablePostingMode(); } } @@ -83,6 +82,8 @@ Espo.define('views/stream/panel', ['views/record/panels/relationship', 'lib!Text this.$textarea.val(''); this.getView('attachments').empty(); this.$el.find('.buttons-panel').addClass('hide'); + + $('body').off('click.stream-panel'); }, setup: function () { diff --git a/frontend/client/src/views/stream/record/edit.js b/frontend/client/src/views/stream/record/edit.js index 83e1d3ef8d..aedb2991c7 100644 --- a/frontend/client/src/views/stream/record/edit.js +++ b/frontend/client/src/views/stream/record/edit.js @@ -89,6 +89,8 @@ Espo.define('views/stream/record/edit', 'views/record/base', function (Dep) { setup: function () { Dep.prototype.setup.call(this); + this.seed = this.model.clone(); + if (this.options.interactiveMode) { this.events['focus textarea[name="post"]'] = function (e) { this.enablePostingMode(); @@ -97,7 +99,7 @@ Espo.define('views/stream/record/edit', 'views/record/base', function (Dep) { if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey) { this.post(); } else if (e.keyCode == 9) { - $text = $(e.currentTarget) + $text = $(e.currentTarget); if ($text.val() == '') { this.disablePostingMode(); } @@ -131,22 +133,29 @@ Espo.define('views/stream/record/edit', 'views/record/base', function (Dep) { this.createField('teams', 'views/fields/teams', {}); this.createField('post', 'views/note/fields/post', {required: true}); this.createField('attachments', 'views/stream/fields/attachment-multiple', {}); + + this.listenTo(this.model, 'change', function () { + if (this.postingMode) { + this.setConfirmLeaveOut(true); + } + }, this); }, disablePostingMode: function () { this.postingMode = false; this.$el.find('.post-control').addClass('hidden'); + this.setConfirmLeaveOut(false); + $('body').off('click.stream-create-post'); }, enablePostingMode: function () { this.$el.find('.post-control').removeClass('hidden'); - if (!this.postingMode) { + $('body').off('click.stream-create-post'); $('body').on('click.stream-create-post', function (e) { if ($.contains(window.document.body, e.target) && !$.contains(this.$el.get(0), e.target) && !$(e.target).closest('.modal-dialog').size()) { - if (this.$textarea.val() == '') { + if (this.getView('post').$element.val() == '') { if (!(this.model.get('attachmentsIds') || []).length) { - $('body').off('click.stream-create-post'); this.disablePostingMode(); } } @@ -158,7 +167,7 @@ Espo.define('views/stream/record/edit', 'views/record/base', function (Dep) { }, afterRender: function () { - this.$textarea = this.$el.find('textarea[name="post"]'); + this.$post = this.$el.find('button.post'); }, validate: function () { @@ -168,6 +177,32 @@ Espo.define('views/stream/record/edit', 'views/record/base', function (Dep) { notValid = true; } return notValid; + }, + + post: function () { + this.save(); + }, + + beforeSave: function () { + Espo.Ui.notify(this.translate('posting', 'messages')); + this.$post.addClass('disabled'); + }, + + afterSave: function () { + Espo.Ui.success(this.translate('Posted')); + if (this.options.interactiveMode) { + this.model.clear(); + this.model.set('targetType', 'self'); + this.model.set('type', 'Post'); + + this.disablePostingMode(); + this.$post.removeClass('disabled'); + this.getView('post').$element.prop('rows', 1); + } + }, + + afterNotValid: function () { + this.$post.removeClass('disabled'); } });