Commit b25768be authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5_officejs: Bookmark Dispatcher, update encoding

parent a097e772
/*globals window, RSVP, rJS*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS) {
"use strict";
function getSearchedString() {
var regex = new RegExp("[\\#?&]search=([^&]*)"),
results = regex.exec(window.location.hash);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function updateSearchUrl(event) {
var gadget = this;
makeOptionDict(gadget)
.push(function() {
return gadget.getSetting("option");
})
.push(function(option) {
return gadget.getUrlFor(option);
})
.push(function(url) {
url = window.location.href + url;
gadget.props.element.getElementsByClassName("search-engine-url")[0].innerHTML = url;
});
}
rJS(window)
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod('getSetting', 'getSetting')
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareMethod("render", function (options) {
var gadget = this,
portal_type = null,
option = {
auto_redirect: false,
search_engine: ""
};
return new RSVP.Queue()
.push(gadget.updateHeader({title: 'Search in Bookmarks'}))
.push(function () {
return gadget.getSetting("portal_type")
.push(function(result) {
portal_type = result;
});
})
.push(function (){
return gadget.getSetting("option")
.push(function(result) {
if (result) {
option = result;
}
});
})
.push(function () {
var search = window.decodeURIComponent(getSearchedString()),
query = "";
if (search) {
query = {
query: '(title:"%' + search + '%" OR url_string:"%' + search + '%" OR description:"%' + search + '%") AND portal_type:"' + portal_type + '"',
select_list: ['title', 'url_string', 'description'],
};
return gadget.jio_allDocs(query)
.push(function (query_result) {
var result_list_length = query_result.data.rows.length;
// if 0 result, let's search with a real search engine
if (result_list_length === 0 && option.search_engine !== '') {
window.location.href = option.search_engine + window.encodeURIComponent(search);
}
// if 1 result, we go there
else if (result_list_length === 1 && option.auto_redirect === true) {
window.location.href = query_result.data.rows[0].value.url_string;
}
else {
return gadget.getUrlFor({page: "bookmark_list", search: window.encodeURIComponent(search)})
.push(function (url) {
window.location.href = url;
});
}
});
}
});
})
.onEvent("submit", function () {
var gadget = this;
//var option_parameter = gadget.getSetting("option");
var option_parameter = {
search: window.encodeURIComponent(gadget.props.element.getElementsByTagName('input')[0].value),
page: 'bookmark_dispatcher'
};
return gadget.getUrlFor(option_parameter)
.push(function (url) {
window.location.href = url;
});
});
/*globals window, RSVP, rJS*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS) {
"use strict";
function getSearchedString() {
var regex = new RegExp("[\\#?&]search=([^&]*)"),
results = regex.exec(window.location.hash);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function updateSearchUrl(event) {
var gadget = this;
makeOptionDict(gadget)
.push(function() {
return gadget.getSetting("option");
})
.push(function(option) {
return gadget.getUrlFor(option);
})
.push(function(url) {
url = window.location.href + url;
gadget.props.element.getElementsByClassName("search-engine-url")[0].innerHTML = url;
});
}
rJS(window)
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod('getSetting', 'getSetting')
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareMethod("render", function (options) {
var gadget = this,
portal_type = null,
option = {
auto_redirect: false,
search_engine: ""
};
return new RSVP.Queue()
.push(gadget.updateHeader({title: 'Search in Bookmarks'}))
.push(function () {
return gadget.getSetting("portal_type")
.push(function(result) {
portal_type = result;
});
})
.push(function (){
return gadget.getSetting("option")
.push(function(result) {
if (result) {
option = result;
}
});
})
.push(function () {
var search = window.decodeURIComponent(getSearchedString()),
query = "";
if (search) {
query = {
query: '(title:"%' + search + '%" OR url_string:"%' + search + '%" OR description:"%' + search + '%") AND portal_type:"' + portal_type + '"',
select_list: ['title', 'url_string', 'description'],
};
return gadget.jio_allDocs(query)
.push(function (query_result) {
var result_list_length = query_result.data.rows.length;
// if 0 result, let's search with a real search engine
if (result_list_length === 0 && option.search_engine !== '') {
window.location.href = option.search_engine + window.encodeURIComponent(search);
}
// if 1 result, we go there
else if (result_list_length === 1 && option.auto_redirect === true) {
window.location.href = query_result.data.rows[0].value.url_string;
}
else {
return gadget.getUrlFor({page: "bookmark_list", search: window.encodeURIComponent(search)})
.push(function (url) {
window.location.href = url;
});
}
});
}
});
})
.onEvent("submit", function () {
var gadget = this;
//var option_parameter = gadget.getSetting("option");
var option_parameter = {
search: window.encodeURIComponent(gadget.props.element.getElementsByTagName('input')[0].value),
page: 'bookmark_dispatcher'
};
return gadget.getUrlFor(option_parameter)
.push(function (url) {
window.location.href = url;
});
});
}(window, RSVP, rJS));
\ No newline at end of file
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.64652.37486.36010</string> </value>
<value> <string>960.32759.37420.3857</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1485780744.68</float>
<float>1499162399.03</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment