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'),
|
|
|
|
moment = require('moment'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Utils = require('Common/Utils'),
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
aResult.push('date:' + moment().subtract('days', this.selectedDateValue()).format('YYYY.MM.DD') + '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}());
|