stream: store post content on leave

This commit is contained in:
yuri
2017-05-09 12:57:49 +03:00
parent c28e73ce3f
commit c564b1b75a
5 changed files with 114 additions and 6 deletions
+26 -2
View File
@@ -29,8 +29,30 @@
Espo.define(
'app',
['ui', 'utils', 'acl-manager', 'cache', 'storage', 'models/settings', 'language', 'metadata', 'field-manager', 'models/user', 'models/preferences', 'model-factory' ,'collection-factory', 'pre-loader', 'view-helper', 'controllers/base', 'router', 'date-time', 'layout-manager', 'theme-manager'],
function (Ui, Utils, AclManager, Cache, Storage, Settings, Language, Metadata, FieldManager, User, Preferences, ModelFactory, CollectionFactory, PreLoader, ViewHelper, BaseController, Router, DateTime, LayoutManager, ThemeManager) {
[
'ui',
'utils',
'acl-manager',
'cache',
'storage',
'models/settings',
'language',
'metadata',
'field-manager',
'models/user',
'models/preferences',
'model-factory',
'collection-factory',
'pre-loader',
'view-helper',
'controllers/base',
'router',
'date-time',
'layout-manager',
'theme-manager',
'session-storage'
],
function (Ui, Utils, AclManager, Cache, Storage, Settings, Language, Metadata, FieldManager, User, Preferences, ModelFactory, CollectionFactory, PreLoader, ViewHelper, BaseController, Router, DateTime, LayoutManager, ThemeManager, SessionStorage) {
var App = function (options, callback) {
var options = options || {};
@@ -56,6 +78,7 @@ Espo.define(
}
this.storage = new Storage();
this.sessionStorage = new SessionStorage();
this.loader.cache = this.cache;
@@ -323,6 +346,7 @@ Espo.define(
helper.cache = this.cache;
helper.storage = this.storage;
helper.themeManager = this.themeManager;
helper.sessionStorage = this.sessionStorage;
helper.basePath = this.basePath;
this.viewLoader = function (viewName, callback) {
+50
View File
@@ -0,0 +1,50 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2017 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
Espo.define('session-storage', 'storage', function (Dep) {
return Dep.extend({
_prefix: 's',
storageObject: sessionStorage,
get: function (name) {
return Dep.prototype.get.call(this, 'session', name);
},
set: function (name, value) {
Dep.prototype.set.call(this, 'session', name, value);
},
clear: function (type, name) {
Dep.prototype.clear.call(this, 'session', name);
}
});
});
+9 -4
View File
@@ -35,6 +35,8 @@ Espo.define('storage', [], function () {
_prefix: 'espo',
storageObject: localStorage,
_composeFullPrefix: function (type) {
return this._prefix + '-' + type;
},
@@ -53,7 +55,8 @@ Espo.define('storage', [], function () {
this._checkType(type);
var key = this._composeKey(type, name);
var stored = localStorage.getItem(key);
var stored = this.storageObject.getItem(key);
if (stored) {
var str = stored;
if (stored[0] == "{" || stored[0] == "[") {
@@ -76,7 +79,7 @@ Espo.define('storage', [], function () {
if (value instanceof Object) {
value = JSON.stringify(value);
}
localStorage.setItem(key, value);
this.storageObject.setItem(key, value);
},
clear: function (type, name) {
@@ -91,13 +94,15 @@ Espo.define('storage', [], function () {
reText = '^' + this._prefix + '-';
}
var re = new RegExp(reText);
for (var i in localStorage) {
for (var i in this.storageObject) {
if (re.test(i)) {
delete localStorage[i];
delete this.storageObject[i];
}
}
}
});
Storage.extend = Backbone.Router.extend;
return Storage;
});
+6
View File
@@ -112,6 +112,12 @@ Espo.define('view', [], function () {
}
},
getSessionStorage: function () {
if (this._helper) {
return this._helper.sessionStorage;
}
},
getLanguage: function () {
if (this._helper) {
return this._helper.language;
+23
View File
@@ -97,6 +97,9 @@ Espo.define('views/stream/panel', ['views/record/panels/relationship', 'lib!Text
this.$el.find('.buttons-panel').removeClass('hide');
if (!this.postingMode) {
if (this.$textarea.val() && this.$textarea.val().length) {
this.controlTextareaHeight();
}
$('body').on('click.stream-panel', function (e) {
var $target = $(e.target);
if ($target.parent().hasClass('remove-attachment')) return;
@@ -143,6 +146,19 @@ Espo.define('views/stream/panel', ['views/record/panels/relationship', 'lib!Text
this.isInternalNoteMode = false;
this.storageTextKey = 'stream-post-' + this.model.name + '-' + this.model.id;
this.on('remove', function () {
if (this.$textarea && this.$textarea.size()) {
var text = this.$textarea.val();
if (text.length) {
this.getSessionStorage().set(this.storageTextKey, text);
} else {
this.getSessionStorage().clear(this.storageTextKey);
}
}
}, this);
this.wait(true);
this.getModelFactory().create('Note', function (model) {
this.seed = model;
@@ -170,6 +186,11 @@ Espo.define('views/stream/panel', ['views/record/panels/relationship', 'lib!Text
var $textarea = this.$textarea;
var storedText = this.getSessionStorage().get(this.storageTextKey);
if (storedText && storedText.length) {
this.$textarea.val(storedText);
}
$textarea.off('drop');
$textarea.off('dragover');
$textarea.off('dragleave');
@@ -319,6 +340,8 @@ Espo.define('views/stream/panel', ['views/record/panels/relationship', 'lib!Text
if (this.getPreferences().get('followEntityOnStreamPost')) {
this.model.set('isFollowed', true);
}
this.getSessionStorage().clear(this.storageTextKey);
}, this);
model.set('post', message);