Skip to content

Commit

Permalink
converted fulltext box search js code from ext2 to jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
MFSepplive committed Sep 20, 2017
1 parent ae9f059 commit 4cbcba1
Showing 1 changed file with 34 additions and 43 deletions.
77 changes: 34 additions & 43 deletions Kwc/FulltextSearch/Box/Component.defer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
//TODO: convert to jquery
/*
var onReady = require('kwf/on-ready-ext2');
var $ = require('jQuery');
var onReady = require('kwf/on-ready');
var getKwcRenderUrl = require('kwf/get-kwc-render-url');
var historyState = require('kwf/history-state');
var findForm = require('kwf/frontend-form/find-form');
var kwfNs = require('kwf/namespace');
var Field = require('kwf/frontend-form/field/field');

var FulltextSearchBoxComponent = function(el, config) {
this.el = el;
this.config = config;

if (this.config.hideSubmit) {
this.el.child('.submitWrapper').enableDisplayMode();
this.el.child('.submitWrapper').hide();
this.el.find('.submitWrapper').hide();
}


if (this.config.useLiveSearch) {
historyState.on('popstate', function() {
if (historyState.currentState.searchVisible) {
Expand All @@ -40,20 +39,20 @@ var FulltextSearchBoxComponent = function(el, config) {
}, this);
}

this.searchForm = findForm(el.dom);
this.searchForm = findForm(el.find('.kwfUp-kwcForm'));

if (location.pathname == config.searchUrl) {
if (location.pathname === config.searchUrl) {
//we are already on search page; nothing to do
this.searchMainContent = Ext2.select('.kwfUp-kwfMainContent').first();
this.searchMainContent = $('.kwfUp-kwfMainContent').first();
historyState.currentState.searchBoxValues = this.searchForm.getValues();
historyState.currentState.searchVisible = true;
historyState.updateState();
return;
}
this.previousSearchFormValues = this.searchForm.getValues();

this.searchForm.on('fieldChange', function(f) {
if (f instanceof Kwf.FrontendForm.Field && f.getValue().length < this.config.minSearchTermLength) {
this.searchForm.on('fieldChange', function(ev, f) {
if (f instanceof Field && f.getValue().length < this.config.minSearchTermLength) {
return; //minimum length
}
this.doSearch();
Expand All @@ -69,7 +68,8 @@ var FulltextSearchBoxComponent = function(el, config) {
}, this);

historyState.currentState.searchVisible = false;
this.previousMainContent = Ext2.select('.kwfUp-kwfMainContent').first();
this.previousMainContent = $('.kwfUp-kwfMainContent').first();

};

FulltextSearchBoxComponent.prototype =
Expand All @@ -87,7 +87,7 @@ FulltextSearchBoxComponent.prototype =
var values = this.searchForm.getValues();
var diffFound = false;
for(var i in values) {
if (values[i] != this.previousSearchFormValues[i]) {
if (values[i] !== this.previousSearchFormValues[i]) {
diffFound = true;
break;
}
Expand All @@ -108,7 +108,7 @@ FulltextSearchBoxComponent.prototype =
this.loadSearch({
success: function() {
historyState.currentState.searchVisible = true;
var ajaxViewEl = this.searchMainContent.child('.kwcDirectoriesListViewAjax');
var ajaxViewEl = this.searchMainContent.find('.kwcDirectoriesListViewAjax');
if (ajaxViewEl && ajaxViewEl.kwcViewAjax) {
ajaxViewEl.kwcViewAjax.pushSearchFormHistoryState();
}
Expand All @@ -119,37 +119,32 @@ FulltextSearchBoxComponent.prototype =

loadSearch: function(params)
{
this.previousMainContent = Ext2.select('.kwfUp-kwfMainContent').first();
this.previousMainContent.enableDisplayMode('block');
this.previousMainContent = $('.kwfUp-kwfMainContent').first();
this.previousMainContent.hide();
this.loadingContent = this.el.createChild({
cls: 'kwfUp-kwfMainContent loadingContent',
tag: 'main',
style: 'width: ' + this.previousMainContent.getStyle('width'),

this.loadingContent = $('<main>', {
class: 'kwfUp-kwfMainContent loadingContent',
style: 'width: ' + this.previousMainContent.width(),
html: '<div class="loading"></div>'
}, this.previousMainContent);
this.loadingContent.enableDisplayMode('block');
}).insertBefore(this.previousMainContent);

var requestParams = this.searchForm.getValuesIncludingPost();
requestParams.url = location.protocol+'//'+location.host+this.config.searchUrl;
Ext2.Ajax.request({
params: requestParams,

$.ajax({
url: getKwcRenderUrl(),
success: function(response, options) {
this.loadingContent.remove();
this.searchMainContent = this.el.createChild({
cls: 'kwfUp-kwfMainContent',
tag: 'main',
style: 'width: ' + this.previousMainContent.getStyle('width'),
html: response.responseText
}, this.previousMainContent);
this.searchMainContent.enableDisplayMode('block');
onReady.callOnContentReady(this.searchMainContent, {newRender: true});
if (params && params.success) params.success.call(params.scope || this);
},
scope: this
});
data: requestParams
}).then((function (data) {
this.loadingContent.remove();
this.searchMainContent = $('<main>',{
class: 'kwfUp-kwfMainContent',
style: 'width: ' + this.previousMainContent.width(),
html: data
}).insertBefore(this.previousMainContent);
onReady.callOnContentReady(this.searchMainContent, {newRender: true});

if (params && params.success) params.success.call(params.scope || this);
}).bind(this));
},

hideSearch: function() {
Expand All @@ -165,14 +160,10 @@ FulltextSearchBoxComponent.prototype =
}
};

onReady.onRender('.kwcClass', function fulltextSearchBox(el, config) {
new FulltextSearchBoxComponent(el, config);
}, {
priority: 0, //call *after* initializing kwcForm to have access to searchForm
defer: true
});

*/

0 comments on commit 4cbcba1

Please sign in to comment.