2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
'use strict';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
var
|
2014-09-02 08:15:31 +08:00
|
|
|
_ = require('_'),
|
2014-08-25 23:49:01 +08:00
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Utils = require('Common/Utils'),
|
2015-04-25 21:50:10 +08:00
|
|
|
Translator = require('Common/Translator'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-22 06:00:51 +08:00
|
|
|
MessageStore = require('Stores/User/Message'),
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
AbstractView = require('Knoin/AbstractView')
|
2013-11-16 06:21:12 +08:00
|
|
|
;
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractView
|
2014-08-21 23:08:34 +08:00
|
|
|
*/
|
2014-09-06 05:44:29 +08:00
|
|
|
function AdvancedSearchPopupView()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.call(this, 'Popups', 'PopupsAdvancedSearch');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
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.hasAttachment = ko.observable(false);
|
|
|
|
this.starred = ko.observable(false);
|
|
|
|
this.unseen = ko.observable(false);
|
|
|
|
|
|
|
|
this.searchCommand = Utils.createCommand(this, function () {
|
|
|
|
|
|
|
|
var sSearch = this.buildSearchString();
|
|
|
|
if ('' !== sSearch)
|
|
|
|
{
|
2015-02-22 06:00:51 +08:00
|
|
|
MessageStore.mainMessageListSearch(sSearch);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.cancelCommand();
|
|
|
|
});
|
|
|
|
|
2015-04-25 21:50:10 +08:00
|
|
|
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);
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
kn.constructorEnd(this);
|
2013-12-17 00:08:05 +08:00
|
|
|
}
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
kn.extendAsViewModel(['View/Popup/AdvancedSearch', 'PopupsAdvancedSearchViewModel'], AdvancedSearchPopupView);
|
|
|
|
_.extend(AdvancedSearchPopupView.prototype, AbstractView.prototype);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AdvancedSearchPopupView.prototype.buildSearchStringValue = function (sValue)
|
2013-12-17 00:08:05 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
if (-1 < sValue.indexOf(' '))
|
|
|
|
{
|
|
|
|
sValue = '"' + sValue + '"';
|
|
|
|
}
|
2013-12-17 00:08:05 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
return sValue;
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AdvancedSearchPopupView.prototype.buildSearchString = function ()
|
2013-12-17 00:08:05 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
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));
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
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())
|
|
|
|
{
|
2015-03-07 08:32:06 +08:00
|
|
|
aResult.push('date:' + require('Common/Momentor').searchSubtractFormatDateHelper(this.selectedDateValue()) + '/');
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sText && '' !== sText)
|
|
|
|
{
|
|
|
|
aResult.push('text:' + this.buildSearchStringValue(sText));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Utils.trim(aResult.join(' '));
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AdvancedSearchPopupView.prototype.clearPopup = function ()
|
2014-04-26 05:50:17 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.from('');
|
|
|
|
this.to('');
|
|
|
|
this.subject('');
|
|
|
|
this.text('');
|
|
|
|
|
|
|
|
this.selectedDateValue(-1);
|
|
|
|
this.hasAttachment(false);
|
|
|
|
this.starred(false);
|
|
|
|
this.unseen(false);
|
2014-04-26 05:50:17 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.fromFocus(true);
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AdvancedSearchPopupView.prototype.onShow = function ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.clearPopup();
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-16 05:55:59 +08:00
|
|
|
AdvancedSearchPopupView.prototype.onShowWithDelay = function ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
this.fromFocus(true);
|
|
|
|
};
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
module.exports = AdvancedSearchPopupView;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|