es5 -> es2015 (last stage)

Signature plugin fixes
Add view decorator
A large number of fixes
This commit is contained in:
RainLoop Team 2016-08-17 01:01:20 +03:00
parent e88c193334
commit 17669b7be0
153 changed files with 21193 additions and 21115 deletions

View file

@ -1,187 +1,174 @@
var
_ = require('_'),
ko = require('ko'),
import _ from '_';
import ko from 'ko';
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
import {trim, createCommand} from 'Common/Utils';
import {i18n, trigger as translatorTrigger} from 'Common/Translator';
import {searchSubtractFormatDateHelper} from 'Common/Momentor';
MessageStore = require('Stores/User/Message'),
import MessageStore from 'Stores/User/Message';
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
import {view, ViewType} from 'Knoin/Knoin';
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
/**
* @constructor
* @extends AbstractView
*/
function AdvancedSearchPopupView()
@view({
name: 'View/Popup/AdvancedSearch',
type: ViewType.Popup,
templateID: 'PopupsAdvancedSearch'
})
class AdvancedSearchPopupView extends AbstractViewNext
{
AbstractView.call(this, 'Popups', 'PopupsAdvancedSearch');
constructor() {
super();
this.fromFocus = ko.observable(false);
this.fromFocus = ko.observable(false);
this.from = ko.observable('');
this.to = ko.observable('');
this.subject = ko.observable('');
this.text = ko.observable('');
this.selectedDateValue = ko.observable(-1);
this.from = ko.observable('');
this.to = ko.observable('');
this.subject = ko.observable('');
this.text = ko.observable('');
this.selectedDateValue = ko.observable(-1);
this.hasAttachment = ko.observable(false);
this.starred = ko.observable(false);
this.unseen = ko.observable(false);
this.hasAttachment = ko.observable(false);
this.starred = ko.observable(false);
this.unseen = ko.observable(false);
this.searchCommand = Utils.createCommand(this, function() {
this.searchCommand = createCommand(() => {
const search = this.buildSearchString();
if ('' !== search)
{
MessageStore.mainMessageListSearch(search);
}
var sSearch = this.buildSearchString();
if ('' !== sSearch)
this.cancelCommand();
});
this.selectedDates = ko.computed(() => {
translatorTrigger();
return [
{id: -1, name: i18n('SEARCH/LABEL_ADV_DATE_ALL')},
{id: 3, name: i18n('SEARCH/LABEL_ADV_DATE_3_DAYS')},
{id: 7, name: i18n('SEARCH/LABEL_ADV_DATE_7_DAYS')},
{id: 30, name: i18n('SEARCH/LABEL_ADV_DATE_MONTH')},
{id: 90, name: i18n('SEARCH/LABEL_ADV_DATE_3_MONTHS')},
{id: 180, name: i18n('SEARCH/LABEL_ADV_DATE_6_MONTHS')},
{id: 365, name: i18n('SEARCH/LABEL_ADV_DATE_YEAR')}
];
});
}
parseSearchStringValue(search) {
const parts = (search || '').split(/[\s]+/g);
_.each(parts, (part) => {
switch (part)
{
case 'has:attachment':
this.hasAttachment(true);
break;
case 'is:unseen,flagged':
this.starred(true);
/* falls through */
case 'is:unseen':
this.unseen(true);
break;
// no default
}
});
}
buildSearchStringValue(value) {
if (-1 < value.indexOf(' '))
{
MessageStore.mainMessageListSearch(sSearch);
value = '"' + value + '"';
}
return value;
}
buildSearchString() {
const
result = [],
from_ = trim(this.from()),
to = trim(this.to()),
subject = trim(this.subject()),
text = trim(this.text()),
isPart = [],
hasPart = [];
if (from_ && '' !== from_)
{
result.push('from:' + this.buildSearchStringValue(from_));
}
this.cancelCommand();
});
if (to && '' !== to)
{
result.push('to:' + this.buildSearchStringValue(to));
}
this.selectedDates = ko.computed(function() {
Translator.trigger();
return [
{'id': -1, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_ALL')},
{'id': 3, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_3_DAYS')},
{'id': 7, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_7_DAYS')},
{'id': 30, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_MONTH')},
{'id': 90, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_3_MONTHS')},
{'id': 180, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_6_MONTHS')},
{'id': 365, 'name': Translator.i18n('SEARCH/LABEL_ADV_DATE_YEAR')}
];
}, this);
if (subject && '' !== subject)
{
result.push('subject:' + this.buildSearchStringValue(subject));
}
kn.constructorEnd(this);
if (this.hasAttachment())
{
hasPart.push('attachment');
}
if (this.unseen())
{
isPart.push('unseen');
}
if (this.starred())
{
isPart.push('flagged');
}
if (0 < hasPart.length)
{
result.push('has:' + hasPart.join(','));
}
if (0 < isPart.length)
{
result.push('is:' + isPart.join(','));
}
if (-1 < this.selectedDateValue())
{
result.push('date:' + searchSubtractFormatDateHelper(this.selectedDateValue()) + '/');
}
if (text && '' !== text)
{
result.push('text:' + this.buildSearchStringValue(text));
}
return trim(result.join(' '));
}
clearPopup() {
this.from('');
this.to('');
this.subject('');
this.text('');
this.selectedDateValue(-1);
this.hasAttachment(false);
this.starred(false);
this.unseen(false);
this.fromFocus(true);
}
onShow(search) {
this.clearPopup();
this.parseSearchStringValue(search);
}
onShowWithDelay() {
this.fromFocus(true);
}
}
kn.extendAsViewModel(['View/Popup/AdvancedSearch', 'PopupsAdvancedSearchViewModel'], AdvancedSearchPopupView);
_.extend(AdvancedSearchPopupView.prototype, AbstractView.prototype);
AdvancedSearchPopupView.prototype.parseSearchStringValue = function(search)
{
var
self = this,
parts = (search || '').split(/[\s]+/g);
_.each(parts, function(part) {
switch (part)
{
case 'has:attachment':
self.hasAttachment(true);
break;
case 'is:unseen,flagged':
self.starred(true);
/* falls through */
case 'is:unseen':
self.unseen(true);
break;
// no default
}
});
};
AdvancedSearchPopupView.prototype.buildSearchStringValue = function(sValue)
{
if (-1 < sValue.indexOf(' '))
{
sValue = '"' + sValue + '"';
}
return sValue;
};
AdvancedSearchPopupView.prototype.buildSearchString = function()
{
var
aResult = [],
sFrom = Utils.trim(this.from()),
sTo = Utils.trim(this.to()),
sSubject = Utils.trim(this.subject()),
sText = Utils.trim(this.text()),
aIs = [],
aHas = [];
if (sFrom && '' !== sFrom)
{
aResult.push('from:' + this.buildSearchStringValue(sFrom));
}
if (sTo && '' !== sTo)
{
aResult.push('to:' + this.buildSearchStringValue(sTo));
}
if (sSubject && '' !== sSubject)
{
aResult.push('subject:' + this.buildSearchStringValue(sSubject));
}
if (this.hasAttachment())
{
aHas.push('attachment');
}
if (this.unseen())
{
aIs.push('unseen');
}
if (this.starred())
{
aIs.push('flagged');
}
if (0 < aHas.length)
{
aResult.push('has:' + aHas.join(','));
}
if (0 < aIs.length)
{
aResult.push('is:' + aIs.join(','));
}
if (-1 < this.selectedDateValue())
{
aResult.push('date:' + require('Common/Momentor').searchSubtractFormatDateHelper(this.selectedDateValue()) + '/');
}
if (sText && '' !== sText)
{
aResult.push('text:' + this.buildSearchStringValue(sText));
}
return Utils.trim(aResult.join(' '));
};
AdvancedSearchPopupView.prototype.clearPopup = function()
{
this.from('');
this.to('');
this.subject('');
this.text('');
this.selectedDateValue(-1);
this.hasAttachment(false);
this.starred(false);
this.unseen(false);
this.fromFocus(true);
};
AdvancedSearchPopupView.prototype.onShow = function(search)
{
this.clearPopup();
this.parseSearchStringValue(search);
};
AdvancedSearchPopupView.prototype.onShowWithDelay = function()
{
this.fromFocus(true);
};
module.exports = AdvancedSearchPopupView;