2010-03-03 00:48:21 +01:00
|
|
|
(function() {
|
2010-03-08 21:56:04 +01:00
|
|
|
var oldResponse = $.suggest.suggest.prototype.response;
|
|
|
|
var typeToIncludedTypes = {};
|
|
|
|
var resortByType = function(data, type) {
|
|
|
|
var schemaPrefixes = [ type + "/" ];
|
|
|
|
|
|
|
|
var includedTypes = typeToIncludedTypes[type];
|
|
|
|
for (var i = 0; i < includedTypes.length; i++) {
|
|
|
|
schemaPrefixes.push(includedTypes[i] + "/");
|
|
|
|
}
|
|
|
|
|
2010-04-07 20:23:07 +02:00
|
|
|
var results = "result" in data ? data.result : [];
|
2010-03-08 21:56:04 +01:00
|
|
|
var entries1 = [];
|
|
|
|
var entries2 = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
var result = results[i];
|
|
|
|
|
|
|
|
var matched = false;
|
|
|
|
for (var j = 0; j < schemaPrefixes.length; j++) {
|
|
|
|
var schemaPrefix = schemaPrefixes[j];
|
|
|
|
if (result.id.substring(0, schemaPrefix.length) == schemaPrefix) {
|
|
|
|
matched = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matched) {
|
|
|
|
entries1.push(result);
|
|
|
|
} else {
|
|
|
|
entries2.push(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data.result = entries1.concat(entries2);
|
2010-03-03 00:48:21 +01:00
|
|
|
};
|
|
|
|
|
2010-03-05 20:28:35 +01:00
|
|
|
/*
|
|
|
|
* Property suggest
|
|
|
|
*/
|
2010-03-03 00:48:21 +01:00
|
|
|
$.suggest(
|
|
|
|
"suggestP",
|
|
|
|
$.extend(
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
$.suggest.suggest.prototype,
|
|
|
|
{
|
2010-03-08 21:56:04 +01:00
|
|
|
request: function(val, start) {
|
|
|
|
if (this.ac_xhr) {
|
|
|
|
this.ac_xhr.abort();
|
|
|
|
this.ac_xhr = null;
|
2010-03-03 00:48:21 +01:00
|
|
|
}
|
2010-03-11 22:19:51 +01:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var o = this.options;
|
|
|
|
|
2010-03-08 21:56:04 +01:00
|
|
|
var data = {
|
2010-04-27 22:34:36 +02:00
|
|
|
query: val
|
2010-03-08 21:56:04 +01:00
|
|
|
};
|
|
|
|
if (start) {
|
|
|
|
data.start = start;
|
|
|
|
}
|
2010-04-27 22:34:36 +02:00
|
|
|
if ("schema" in o) {
|
|
|
|
data.schema = o.schema;
|
|
|
|
}
|
2010-03-08 21:56:04 +01:00
|
|
|
|
|
|
|
$.extend(data, o.ac_param);
|
|
|
|
|
2010-05-08 07:52:32 +02:00
|
|
|
var baseUrl = Gridworks.gridworksHelperService + "suggest_property";
|
2010-03-08 21:56:04 +01:00
|
|
|
var url = baseUrl + "?" + $.param(data),
|
2010-04-27 22:34:36 +02:00
|
|
|
|
2010-03-08 21:56:04 +01:00
|
|
|
cached = $.suggest.cache[url];
|
|
|
|
if (cached) {
|
|
|
|
this.response(cached, start ? start : -1, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearTimeout(this.request.timeout);
|
|
|
|
this.request.timeout =
|
|
|
|
setTimeout(function() {
|
|
|
|
self.ac_xhr = $.ajax({
|
|
|
|
url: baseUrl,
|
|
|
|
data: data,
|
|
|
|
beforeSend: function() {
|
|
|
|
var calls = self.input.data("request.count.suggest") || 0;
|
|
|
|
if (!calls) {
|
|
|
|
self.trackEvent(self.name, "start_session");
|
|
|
|
}
|
|
|
|
calls += 1;
|
|
|
|
self.trackEvent(self.name, "request", "count", calls);
|
|
|
|
self.input.data("request.count.suggest", calls);
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2010-04-27 22:34:36 +02:00
|
|
|
self.response(data, start ? start : -1);
|
2010-03-08 21:56:04 +01:00
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
self.trackEvent(self.name, "request", "error", {url:this.url, response: xhr ? xhr.responseText : ''});
|
|
|
|
},
|
|
|
|
complete: function(xhr) {
|
|
|
|
if (xhr) {
|
|
|
|
self.trackEvent(self.name, "request", "tid", xhr.getResponseHeader("X-Metaweb-TID"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
dataType: "jsonp",
|
|
|
|
cache: true
|
|
|
|
});
|
|
|
|
}, o.xhr_delay);
|
2010-03-03 00:48:21 +01:00
|
|
|
},
|
|
|
|
create_item: function(data, response_data) {
|
|
|
|
var css = this.options.css;
|
|
|
|
|
|
|
|
var li = $("<li>").addClass(css.item);
|
|
|
|
|
|
|
|
var name = $("<div>")
|
|
|
|
.addClass(css.item_name)
|
|
|
|
.append(
|
2010-03-11 22:19:51 +01:00
|
|
|
$("<label>").append($.suggest.strongify(data.name || data.guid, response_data.prefix)));
|
|
|
|
|
2010-03-03 00:48:21 +01:00
|
|
|
data.name = name.text(); // this converts html escaped strings like "&" back to "&"
|
|
|
|
li.append(name);
|
|
|
|
|
|
|
|
name.prepend($("<div>").addClass(css.item_type).text(data.id));
|
|
|
|
|
|
|
|
return li;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$.extend(
|
|
|
|
$.suggest.suggestP,
|
|
|
|
{
|
|
|
|
defaults: $.extend(
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
$.suggest.suggest.defaults, {
|
2010-03-05 20:28:35 +01:00
|
|
|
css: { pane: "fbs-pane fbs-pane-property" }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Type suggest
|
|
|
|
*/
|
|
|
|
$.suggest(
|
|
|
|
"suggestT",
|
|
|
|
$.extend(
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
$.suggest.suggest.prototype,
|
|
|
|
{
|
|
|
|
create_item: function(data, response_data) {
|
|
|
|
var css = this.options.css;
|
|
|
|
|
|
|
|
var li = $("<li>").addClass(css.item);
|
|
|
|
|
|
|
|
var name = $("<div>")
|
|
|
|
.addClass(css.item_name)
|
|
|
|
.append(
|
|
|
|
$("<label>")
|
|
|
|
.append($.suggest.strongify(data.name || data.guid, response_data.prefix)));
|
|
|
|
|
|
|
|
data.name = name.text(); // this converts html escaped strings like "&" back to "&"
|
|
|
|
li.append(name);
|
|
|
|
|
|
|
|
name.prepend($("<div>").addClass(css.item_type).text(data.id));
|
|
|
|
|
|
|
|
return li;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$.extend(
|
|
|
|
$.suggest.suggestT,
|
|
|
|
{
|
|
|
|
defaults: $.extend(
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
$.suggest.suggest.defaults, {
|
|
|
|
css: { pane: "fbs-pane fbs-pane-type" }
|
2010-03-03 00:48:21 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
})();
|