Bug 131574 - Add AJAX function with callback and some code refactoring
git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@1822 6955db30-a419-402b-8a0d-67ecbb4d7f56master
parent
323693b4dd
commit
3baff646a1
22
js/bug.js
22
js/bug.js
|
@ -365,18 +365,9 @@ addListener(window, 'load', function() {
|
||||||
function showEditComment(comment_id) {
|
function showEditComment(comment_id) {
|
||||||
var el_container = document.getElementById("bz_textarea_"+comment_id);
|
var el_container = document.getElementById("bz_textarea_"+comment_id);
|
||||||
|
|
||||||
var x;
|
var u = window.location.href.replace(/[^\/]+$/, '');
|
||||||
if (window.XMLHttpRequest)
|
u += 'xml.cgi?method=Bug.comments&output=json&comment_ids=' + comment_id;
|
||||||
x = new XMLHttpRequest();
|
AjaxLoader(u, function(x) {
|
||||||
else
|
|
||||||
{
|
|
||||||
try { x = new ActiveXObject("Msxml2.XMLHTTP"); }
|
|
||||||
catch (e) { x = new ActiveXObject("Microsoft.XMLHTTP"); }
|
|
||||||
}
|
|
||||||
x.onreadystatechange = function()
|
|
||||||
{
|
|
||||||
if (x.readyState == 4)
|
|
||||||
{
|
|
||||||
var r = {};
|
var r = {};
|
||||||
try { eval('r = '+x.responseText+';'); } catch (e) { return; }
|
try { eval('r = '+x.responseText+';'); } catch (e) { return; }
|
||||||
if (r.status == 'ok')
|
if (r.status == 'ok')
|
||||||
|
@ -390,11 +381,6 @@ function showEditComment(comment_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
|
||||||
var u = window.location.href.replace(/[^\/]+$/, '');
|
|
||||||
u += 'xml.cgi?method=Bug.comments&output=json&comment_ids=' + comment_id;
|
|
||||||
x.open('GET', u);
|
|
||||||
x.send(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
82
js/global.js
82
js/global.js
|
@ -142,18 +142,14 @@ function userAutocomplete(hint, emptyOptions)
|
||||||
hint.replaceItems(null);
|
hint.replaceItems(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var x;
|
|
||||||
if (window.XMLHttpRequest)
|
var u = window.location.href.replace(/[^\/]+$/, '');
|
||||||
x = new XMLHttpRequest();
|
u += 'xml.cgi?method=User.get&output=json&maxusermatches=20&excludedisabled=1';
|
||||||
else
|
var l = hint.input.value.split(/[\s,]*,[\s,]*/);
|
||||||
{
|
for (var i = 0; i < l.length; i++)
|
||||||
try { x = new ActiveXObject("Msxml2.XMLHTTP"); }
|
u += '&match='+encodeURI(l[i]);
|
||||||
catch (e) { x = new ActiveXObject("Microsoft.XMLHTTP"); }
|
|
||||||
}
|
AjaxLoader(u, function(x) {
|
||||||
x.onreadystatechange = function()
|
|
||||||
{
|
|
||||||
if (x.readyState == 4)
|
|
||||||
{
|
|
||||||
var r = {};
|
var r = {};
|
||||||
try { eval('r = '+x.responseText+';'); } catch (e) { return; }
|
try { eval('r = '+x.responseText+';'); } catch (e) { return; }
|
||||||
if (r.status == 'ok')
|
if (r.status == 'ok')
|
||||||
|
@ -166,15 +162,7 @@ function userAutocomplete(hint, emptyOptions)
|
||||||
hint.emptyText = 'No users found';
|
hint.emptyText = 'No users found';
|
||||||
hint.replaceItems(data);
|
hint.replaceItems(data);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
|
||||||
var u = window.location.href.replace(/[^\/]+$/, '');
|
|
||||||
u += 'xml.cgi?method=User.get&output=json&maxusermatches=20&excludedisabled=1';
|
|
||||||
var l = hint.input.value.split(/[\s,]*,[\s,]*/);
|
|
||||||
for (var i = 0; i < l.length; i++)
|
|
||||||
u += '&match='+encodeURI(l[i]);
|
|
||||||
x.open('GET', u);
|
|
||||||
x.send(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,18 +192,13 @@ function keywordAutocomplete(hint, emptyOptions)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var x;
|
var u = window.location.href.replace(/[^\/]+$/, '');
|
||||||
if (window.XMLHttpRequest)
|
u += 'xml.cgi?method=Keyword.get&output=json&maxkeywordmatches=20';
|
||||||
x = new XMLHttpRequest();
|
var l = hint.input.value.split(/[\s,]*,[\s,]*/);
|
||||||
else
|
for (var i = 0; i < l.length; i++)
|
||||||
{
|
u += '&match='+encodeURI(l[i]);
|
||||||
try { x = new ActiveXObject("Msxml2.XMLHTTP"); }
|
|
||||||
catch (e) { x = new ActiveXObject("Microsoft.XMLHTTP"); }
|
AjaxLoader(u, function(x) {
|
||||||
}
|
|
||||||
x.onreadystatechange = function()
|
|
||||||
{
|
|
||||||
if (x.readyState == 4)
|
|
||||||
{
|
|
||||||
var r = {};
|
var r = {};
|
||||||
try { eval('r = '+x.responseText+';'); } catch (e) { return; }
|
try { eval('r = '+x.responseText+';'); } catch (e) { return; }
|
||||||
if (r.status == 'ok')
|
if (r.status == 'ok')
|
||||||
|
@ -228,33 +211,15 @@ function keywordAutocomplete(hint, emptyOptions)
|
||||||
hint.emptyText = 'No keywords found';
|
hint.emptyText = 'No keywords found';
|
||||||
hint.replaceItems(data);
|
hint.replaceItems(data);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
|
||||||
|
|
||||||
var u = window.location.href.replace(/[^\/]+$/, '');
|
|
||||||
u += 'xml.cgi?method=Keyword.get&output=json&maxkeywordmatches=20';
|
|
||||||
var l = hint.input.value.split(/[\s,]*,[\s,]*/);
|
|
||||||
for (var i = 0; i < l.length; i++)
|
|
||||||
u += '&match='+encodeURI(l[i]);
|
|
||||||
x.open('GET', u);
|
|
||||||
x.send(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data loader for field in buglist autocomplete
|
// Data loader for field in buglist autocomplete
|
||||||
function fieldBuglistAutocomplete(hint, field, emptyOptions)
|
function fieldBuglistAutocomplete(hint, field, emptyOptions)
|
||||||
{
|
{
|
||||||
var x;
|
var u = window.location.href.replace(/[^\/]+$/, '');
|
||||||
if (window.XMLHttpRequest)
|
u += 'xml.cgi?method=Field.get_values&output=json&field=' + field;
|
||||||
x = new XMLHttpRequest();
|
AjaxLoader(u, function(x) {
|
||||||
else
|
|
||||||
{
|
|
||||||
try { x = new ActiveXObject("Msxml2.XMLHTTP"); }
|
|
||||||
catch (e) { x = new ActiveXObject("Microsoft.XMLHTTP"); }
|
|
||||||
}
|
|
||||||
x.onreadystatechange = function()
|
|
||||||
{
|
|
||||||
if (x.readyState == 4)
|
|
||||||
{
|
|
||||||
var r = {};
|
var r = {};
|
||||||
try { eval('r = '+x.responseText+';'); } catch (e) { return; }
|
try { eval('r = '+x.responseText+';'); } catch (e) { return; }
|
||||||
if (r.status == 'ok')
|
if (r.status == 'ok')
|
||||||
|
@ -262,12 +227,7 @@ function fieldBuglistAutocomplete(hint, field, emptyOptions)
|
||||||
var data = convertSimpleList(r.values);
|
var data = convertSimpleList(r.values);
|
||||||
hint.replaceItems(data);
|
hint.replaceItems(data);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
|
||||||
var u = window.location.href.replace(/[^\/]+$/, '');
|
|
||||||
u += 'xml.cgi?method=Field.get_values&output=json&field=' + field;
|
|
||||||
x.open('GET', u);
|
|
||||||
x.send(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showFullComment(el_link, oper_id)
|
function showFullComment(el_link, oper_id)
|
||||||
|
|
21
js/util.js
21
js/util.js
|
@ -433,3 +433,24 @@ if (!String.prototype.trim)
|
||||||
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function AjaxLoader(url, callback)
|
||||||
|
{
|
||||||
|
var x;
|
||||||
|
if (window.XMLHttpRequest)
|
||||||
|
x = new XMLHttpRequest();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try { x = new ActiveXObject("Msxml2.XMLHTTP"); }
|
||||||
|
catch (e) { x = new ActiveXObject("Microsoft.XMLHTTP"); }
|
||||||
|
}
|
||||||
|
x.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (x.readyState == 4)
|
||||||
|
{
|
||||||
|
callback(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
x.open('GET', url, true);
|
||||||
|
x.send(null);
|
||||||
|
}
|
Loading…
Reference in New Issue