stream post
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -4,8 +4,14 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row post-control{{#if interactiveMode}} hidden{{/if}}">
|
||||
<div class="cell cell-attachments col-sm-6 form-group">
|
||||
<div class="field field-attachments">{{{attachments}}}</div>
|
||||
|
||||
<div class="col-sm-6 form-group">
|
||||
<div>
|
||||
|
||||
<button type="button" class="btn btn-primary post pull-left">{{translate 'Post'}}</button>
|
||||
<div class="field field-attachments" style="display: inline-block;">{{{attachments}}}</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="cell cell-targetType form-group">
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user