From b0f7006e467249d5cbff2b84febe0b658744b559 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Thu, 9 Aug 2012 19:06:02 -0400 Subject: Initial import of MyDashboard extension --- extensions/MyDashboard/web/js/mydashboard.js | 126 ++++++++++++++++++++++ extensions/MyDashboard/web/js/prod_comp_search.js | 85 +++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 extensions/MyDashboard/web/js/mydashboard.js create mode 100644 extensions/MyDashboard/web/js/prod_comp_search.js (limited to 'extensions/MyDashboard/web/js') diff --git a/extensions/MyDashboard/web/js/mydashboard.js b/extensions/MyDashboard/web/js/mydashboard.js new file mode 100644 index 000000000..64a421113 --- /dev/null +++ b/extensions/MyDashboard/web/js/mydashboard.js @@ -0,0 +1,126 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. + */ + +var showQuerySection = function () { + var query_select = YAHOO.util.Dom.get('query'); + var selected_value = ''; + for (var i = 0, l = query_select.options.length; i < l; i++) { + if (query_select.options[i].selected) { + selected_value = query_select.options[i].value; + } + } + for (var i = 0, l = full_query_list.length; i < l; i++) { + var query = full_query_list[i]; + if (selected_value == full_query_list[i]) { + YAHOO.util.Dom.removeClass(query + '_container', 'bz_default_hidden'); + } + else { + YAHOO.util.Dom.addClass(query + '_container', 'bz_default_hidden'); + } + } +} + +var query_column_defs = [ + { key:"id", label:"ID", sortable:true, sortOptions:{ sortFunction:sortBugIdLinks } }, + { key:"updated", label:"Updated", sortable:false }, + { key:"bug_status", label:"Status", sortable:true }, + { key:"summary", label:"Summary", sortable:true }, +]; +var query_fields = [ + { key:"id" }, + { key:"updated" }, + { key:"bug_status" }, + { key:"summary" } +]; + +function addStatListener (div_name, table_name, column_defs, fields, options) { + YAHOO.util.Event.addListener(window, "load", function() { + YAHOO.example.StatsFromMarkup = new function() { + this.myDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get(table_name)); + this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE; + this.myDataSource.responseSchema = { fields:fields }; + this.myDataTable = new YAHOO.widget.DataTable(div_name, column_defs, this.myDataSource, options); + this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow); + this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow); + }; + }); +} + +// Custom sort handler to sort by bug id inside an anchor tag +var sortBugIdLinks = function(a, b, desc) { + // Deal with empty values + if (!YAHOO.lang.isValue(a)) { + return (!YAHOO.lang.isValue(b)) ? 0 : 1; + } + else if(!YAHOO.lang.isValue(b)) { + return -1; + } + // Now we need to pull out the ID text and convert to Numbers + // First we do 'a' + var container = document.createElement("bug_id_link"); + container.innerHTML = a.getData("id"); + var anchors = container.getElementsByTagName("a"); + var text = anchors[0].textContent; + if (text === undefined) text = anchors[0].innerText; + var new_a = new Number(text); + // Then we do 'b' + container.innerHTML = b.getData("id"); + anchors = container.getElementsByTagName("a"); + text = anchors[0].textContent; + if (text == undefined) text = anchors[0].innerText; + var new_b = new Number(text); + + if (!desc) { + return YAHOO.util.Sort.compare(new_a, new_b); + } + else { + return YAHOO.util.Sort.compare(new_b, new_a); + } +} + +// Custom sort handler for bug severities +var sortBugSeverity = function(a, b, desc) { + // Deal with empty values + if (!YAHOO.lang.isValue(a)) { + return (!YAHOO.lang.isValue(b)) ? 0 : 1; + } + else if(!YAHOO.lang.isValue(b)) { + return -1; + } + + var new_a = new Number(severities[YAHOO.lang.trim(a.getData('bug_severity'))]); + var new_b = new Number(severities[YAHOO.lang.trim(b.getData('bug_severity'))]); + + if (!desc) { + return YAHOO.util.Sort.compare(new_a, new_b); + } + else { + return YAHOO.util.Sort.compare(new_b, new_a); + } +} + +// Custom sort handler for bug priorities +var sortBugPriority = function(a, b, desc) { + // Deal with empty values + if (!YAHOO.lang.isValue(a)) { + return (!YAHOO.lang.isValue(b)) ? 0 : 1; + } + else if(!YAHOO.lang.isValue(b)) { + return -1; + } + + var new_a = new Number(priorities[YAHOO.lang.trim(a.getData('priority'))]); + var new_b = new Number(priorities[YAHOO.lang.trim(b.getData('priority'))]); + + if (!desc) { + return YAHOO.util.Sort.compare(new_a, new_b); + } + else { + return YAHOO.util.Sort.compare(new_b, new_a); + } +} diff --git a/extensions/MyDashboard/web/js/prod_comp_search.js b/extensions/MyDashboard/web/js/prod_comp_search.js new file mode 100644 index 000000000..06b4c601f --- /dev/null +++ b/extensions/MyDashboard/web/js/prod_comp_search.js @@ -0,0 +1,85 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. + */ + +YAHOO.bugzilla.prodCompSearch = { + counter : 0, + format : '', + cloned_bug_id : '', + dataSource : null, + autoComplete: null, + generateRequest : function (enteredText) { + YAHOO.bugzilla.prodCompSearch.counter = YAHOO.bugzilla.prodCompSearch.counter + 1; + YAHOO.util.Connect.setDefaultPostHeader('application/json', true); + var json_object = { + method : "MyDashboard.prod_comp_search", + id : YAHOO.bugzilla.prodCompSearch.counter, + params : [ { + search : decodeURIComponent(enteredText) + } ] + }; + YAHOO.util.Dom.removeClass('prod_comp_throbber', 'hidden'); + return YAHOO.lang.JSON.stringify(json_object); + }, + resultListFormat : function(oResultData, enteredText, sResultMatch) { + return YAHOO.lang.escapeHTML(oResultData[0]) + " :: " + + YAHOO.lang.escapeHTML(oResultData[1]); + }, + init_ds : function(){ + this.dataSource = new YAHOO.util.XHRDataSource("jsonrpc.cgi"); + this.dataSource.connTimeout = 30000; + this.dataSource.connMethodPost = true; + this.dataSource.connXhrMode = "cancelStaleRequests"; + this.dataSource.maxCacheEntries = 5; + this.dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; + this.dataSource.responseSchema = { + resultsList : "result.products", + metaFields : { error: "error", jsonRpcId: "id"}, + fields : [ "product", "component" ] + }; + }, + init : function(field, container, format, cloned_bug_id) { + if (this.dataSource == null) + this.init_ds(); + this.format = format; + this.cloned_bug_id = cloned_bug_id; + this.autoComplete = new YAHOO.widget.AutoComplete(field, container, this.dataSource); + this.autoComplete.generateRequest = this.generateRequest; + this.autoComplete.formatResult = this.resultListFormat; + this.autoComplete.minQueryLength = 3; + this.autoComplete.autoHighlight = false; + this.autoComplete.queryDelay = 0.05; + this.autoComplete.useIFrame = true; + this.autoComplete.maxResultsDisplayed = 25; + this.autoComplete.suppressInputUpdate = true; + this.autoComplete.doBeforeLoadData = function(sQuery, oResponse, oPayload) { + YAHOO.util.Dom.addClass('prod_comp_throbber', 'hidden'); + return true; + }; + this.autoComplete.textboxFocusEvent.subscribe(function () { + var input = YAHOO.util.Dom.get(field); + if (input.value && input.value.length > 3) { + this.sendQuery(input.value); + } + }); + this.autoComplete.itemSelectEvent.subscribe(function (e, args) { + var oData = args[2]; + var url = "enter_bug.cgi?product=" + encodeURIComponent(oData[0]) + + "&component=" + encodeURIComponent(oData[1]); + var format = YAHOO.bugzilla.prodCompSearch.format; + if (format) + url += "&format=" + encodeURIComponent(format); + var cloned_bug_id = YAHOO.bugzilla.prodCompSearch.cloned_bug_id; + if (cloned_bug_id) + url += "&cloned_bug_id=" + encodeURIComponent(cloned_bug_id); + window.location.href = url; + }); + this.autoComplete.dataReturnEvent.subscribe(function(type, args) { + args[0].autoHighlight = args[2].length == 1; + }); + } +} -- cgit v1.2.3-24-g4f1b