| 1 |
function res_t_resize(t, is_sel) { |
| 2 |
var res_tv = document['res_tv']; |
| 3 |
|
| 4 |
var cbox = t.get('panelNode'); |
| 5 |
var table = cbox['g_table']; |
| 6 |
|
| 7 |
var lh = cbox.ancestor().ancestor().one('.yui3-tabview-list').get('clientHeight'); |
| 8 |
var w = res_tv.get('width') - 2; |
| 9 |
var h = res_tv.get('height') - lh; |
| 10 |
|
| 11 |
if (is_sel) { |
| 12 |
if (cbox['g_table_h'] == h && cbox['g_table_w'] == w) { |
| 13 |
return; |
| 14 |
} |
| 15 |
} |
| 16 |
cbox['g_table_h'] = h |
| 17 |
cbox['g_table_w'] = w |
| 18 |
|
| 19 |
var dv = cbox['g_dv']; |
| 20 |
table.draw(dv, { |
| 21 |
height: h, |
| 22 |
width: w, |
| 23 |
page : 'enable', |
| 24 |
pageSize : 200, |
| 25 |
}); |
| 26 |
} |
| 27 |
|
| 28 |
function res_tv_cur_tab() { |
| 29 |
var res_tv = document['res_tv']; |
| 30 |
if (!res_tv.size()) { |
| 31 |
return; |
| 32 |
} |
| 33 |
return res_tv.get('selection'); |
| 34 |
} |
| 35 |
|
| 36 |
function res_tv_resize(e) { |
| 37 |
var t = res_tv_cur_tab(); |
| 38 |
if (!t) { |
| 39 |
return; |
| 40 |
} |
| 41 |
res_t_resize(t); |
| 42 |
} |
| 43 |
|
| 44 |
function res_tv_resize_sel(e) { |
| 45 |
var t = res_tv_cur_tab(); |
| 46 |
if (!t) { |
| 47 |
return; |
| 48 |
} |
| 49 |
res_t_resize(t, true); |
| 50 |
} |
| 51 |
|
| 52 |
function start_query(qargs) { |
| 53 |
var res_tv = document['res_tv']; |
| 54 |
|
| 55 |
var label = qargs.symbol; |
| 56 |
if (qargs.opt.indexOf('substring') >= 0) { |
| 57 |
if (qargs.qtype == 'FIL') { |
| 58 |
label = '*' + label + '*' |
| 59 |
} else { |
| 60 |
label = '.*' + label + '.*' |
| 61 |
} |
| 62 |
} |
| 63 |
label = qargs.qtype + ' ' + label; |
| 64 |
|
| 65 |
var targs = { |
| 66 |
label : label, |
| 67 |
content : |
| 68 |
|
| 69 |
|
| 70 |
'<div id="errLbl" align="right" style="display:none; width=100%; color:black; background-color:Yellow;"></div>' + |
| 71 |
|
| 72 |
|
| 73 |
'<div id="resTbl"> </div>', |
| 74 |
|
| 75 |
|
| 76 |
}; |
| 77 |
res_tv['qargs'] = qargs; |
| 78 |
res_tv.add(targs); |
| 79 |
var inx = res_tv.size() - 1; |
| 80 |
res_tv.selectChild(inx); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
function res_filter_cb(fargs) { |
| 87 |
var t = res_tv_cur_tab(); |
| 88 |
var cbox = t.get('panelNode'); |
| 89 |
var dt = cbox['g_dt']; |
| 90 |
var dv = cbox['g_dv']; |
| 91 |
|
| 92 |
var col_arr = ['tag', 'file', 'line', 'text']; |
| 93 |
fargs.col = col_arr.indexOf(fargs.col_name); |
| 94 |
var row_list = filter_table(dt, fargs); |
| 95 |
if (row_list.length) { |
| 96 |
dv.hideRows(row_list); |
| 97 |
res_tv_resize(null); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
function res_show_all_cb() { |
| 102 |
var t = res_tv_cur_tab(); |
| 103 |
var cbox = t.get('panelNode'); |
| 104 |
var dt = cbox['g_dt']; |
| 105 |
var dv = cbox['g_dv']; |
| 106 |
|
| 107 |
var num_rows = dt.getNumberOfRows(); |
| 108 |
if (num_rows) { |
| 109 |
dv.setRows(0, num_rows -1); |
| 110 |
} |
| 111 |
res_tv_resize(null); |
| 112 |
} |
| 113 |
|
| 114 |
function res_remove_item_cb(row) { |
| 115 |
if (row == -1) { |
| 116 |
return; |
| 117 |
} |
| 118 |
var t = res_tv_cur_tab(); |
| 119 |
var cbox = t.get('panelNode'); |
| 120 |
var dt = cbox['g_dt']; |
| 121 |
var dv = cbox['g_dv']; |
| 122 |
|
| 123 |
dv.hideRow([row]); |
| 124 |
res_tv_resize(null); |
| 125 |
} |
| 126 |
|
| 127 |
function res_ctx_menu_cb(cargs) { |
| 128 |
|
| 129 |
if (cargs.choice == 'filter') { |
| 130 |
var col_arr = ['tag', 'file', 'line', 'text']; |
| 131 |
var col_name = col_arr[cargs.col]; |
| 132 |
res_filt_dlg_show(res_filter_cb, col_name); |
| 133 |
} else if(cargs.choice == 'show_all') { |
| 134 |
res_show_all_cb(); |
| 135 |
} else if (cargs.choice == 'remove_item') { |
| 136 |
res_remove_item_cb(cargs.row); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
function createResTable(t) { |
| 142 |
var cbox = t.get('panelNode'); |
| 143 |
var dt = new google.visualization.DataTable(); |
| 144 |
dt.addColumn('string', 'tag'); |
| 145 |
dt.addColumn('string', 'file'); |
| 146 |
dt.addColumn('string', 'line'); |
| 147 |
dt.addColumn('string', 'text'); |
| 148 |
|
| 149 |
dt.addRows(1); |
| 150 |
dt.setCell(0, 0, 'running query...'); |
| 151 |
|
| 152 |
var dv = new google.visualization.DataView(dt); |
| 153 |
var table = new google.visualization.Table(cbox.one('#resTbl').getDOMNode()); |
| 154 |
|
| 155 |
cbox['g_dt'] = dt; |
| 156 |
cbox['g_dv'] = dv; |
| 157 |
cbox['g_table'] = table; |
| 158 |
|
| 159 |
res_t_resize(t); |
| 160 |
} |
| 161 |
|
| 162 |
function populateResTable(t, res) { |
| 163 |
var cbox = t.get('panelNode'); |
| 164 |
var dt = cbox['g_dt']; |
| 165 |
dt.removeRow(0); |
| 166 |
|
| 167 |
dt.addRows(res); |
| 168 |
|
| 169 |
cbox['g_table_h'] = 0; |
| 170 |
res_t_resize(t); |
| 171 |
|
| 172 |
if (res.length == 1) { |
| 173 |
var dv = cbox['g_dv']; |
| 174 |
var row = 0; |
| 175 |
var file = dv.getValue(row, 1); |
| 176 |
var line = dv.getValue(row, 2); |
| 177 |
ed_show_file_line(file, line); |
| 178 |
} |
| 179 |
|
| 180 |
var table = cbox['g_table']; |
| 181 |
google.visualization.events.addListener(table, 'select', function(e) { |
| 182 |
var sel = table.getSelection() |
| 183 |
if (sel.length == 0) { |
| 184 |
return |
| 185 |
} |
| 186 |
var row = sel[0].row; |
| 187 |
|
| 188 |
var dv = cbox['g_dv']; |
| 189 |
var file = dv.getValue(row, 1); |
| 190 |
var line = dv.getValue(row, 2); |
| 191 |
ed_show_file_line(file, line); |
| 192 |
}); |
| 193 |
} |
| 194 |
|
| 195 |
YUI().use('datasource-get', 'datasource-jsonschema', |
| 196 |
'node-event-delegate', 'event-key', |
| 197 |
'tabview', 'escape', 'plugin', 'node', function(Y) { |
| 198 |
|
| 199 |
var ResAddable = function(config) { |
| 200 |
ResAddable.superclass.constructor.apply(this, arguments); |
| 201 |
}; |
| 202 |
|
| 203 |
ResAddable.NAME = 'addableTabs'; |
| 204 |
ResAddable.NS = 'addable'; |
| 205 |
|
| 206 |
Y.extend(ResAddable, Y.Plugin.Base, { |
| 207 |
ADD_TEMPLATE: '<li class="yui3-tab" title="add a tab">' + |
| 208 |
'<a class="yui3-tab-label yui3-tab-add">+</a></li>', |
| 209 |
|
| 210 |
initializer: function(config) { |
| 211 |
var tabview = this.get('host'); |
| 212 |
tabview.after('render', this.afterRender, this); |
| 213 |
tabview.get('contentBox').delegate('click', this.onAddClick, '.yui3-tab-add', this); |
| 214 |
|
| 215 |
tabview.after('tab:render', this.afterTabRender, this); |
| 216 |
|
| 217 |
|
| 218 |
tabview.get('listNode').setStyle('border-width', '0 0 0px'); |
| 219 |
tabview.get('panelNode').setStyle('padding', '0em'); |
| 220 |
}, |
| 221 |
|
| 222 |
afterRender: function(e) { |
| 223 |
var tv = this.get('host'); |
| 224 |
tv.get('contentBox').one('> ul').append(this.ADD_TEMPLATE); |
| 225 |
}, |
| 226 |
|
| 227 |
onAddClick: function(e) { |
| 228 |
e.stopPropagation(); |
| 229 |
qry_dlg_show(start_query); |
| 230 |
}, |
| 231 |
|
| 232 |
afterTabRender: function(e) { |
| 233 |
var t = e.target; |
| 234 |
var cbox = t.get('panelNode'); |
| 235 |
var resTblNode = cbox.one('#resTbl'); |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
if (resTblNode) { |
| 241 |
createResTable(t); |
| 242 |
|
| 243 |
var url = document['server_info'].url; |
| 244 |
var src = new Y.DataSource.Get({ |
| 245 |
source : url, |
| 246 |
}); |
| 247 |
src.plug(Y.Plugin.DataSourceJSONSchema, { |
| 248 |
schema : { |
| 249 |
|
| 250 |
resultFields : ['res', 'err_data'], |
| 251 |
} |
| 252 |
}); |
| 253 |
|
| 254 |
var tv = this.get('host'); |
| 255 |
|
| 256 |
var qargs = tv['qargs']; |
| 257 |
tv['qargs'] = null; |
| 258 |
|
| 259 |
var rd = { |
| 260 |
project : document['project'], |
| 261 |
cmd_type : 'query', |
| 262 |
cmd_str : qargs.qtype, |
| 263 |
req : qargs.symbol, |
| 264 |
opt : qargs.opt.join(','), |
| 265 |
} |
| 266 |
var hint_file = ed_get_cur_file(); |
| 267 |
if (hint_file) { |
| 268 |
rd.hint_file = hint_file; |
| 269 |
} |
| 270 |
var request = '?' + to_query_string(rd); |
| 271 |
|
| 272 |
src.sendRequest({ |
| 273 |
request : request, |
| 274 |
callback : { |
| 275 |
success: function (e) { |
| 276 |
var err_data = e.data.err_data; |
| 277 |
if (err_data) { |
| 278 |
var node = cbox.one('#errLbl'); |
| 279 |
node.setHTML(err_data); |
| 280 |
node.show(); |
| 281 |
node.after('click', function(e) { |
| 282 |
node.hide(); |
| 283 |
}); |
| 284 |
} |
| 285 |
|
| 286 |
var res = e.data.res; |
| 287 |
populateResTable(t, res); |
| 288 |
}, |
| 289 |
failure: function (e) { |
| 290 |
cbox['g_dt'].setCell(0, 0, e.error.message); |
| 291 |
cbox['g_table'].draw(cbox['g_dv']); |
| 292 |
}, |
| 293 |
}, |
| 294 |
}); |
| 295 |
} |
| 296 |
} |
| 297 |
}); |
| 298 |
|
| 299 |
var Removeable = function(config) { |
| 300 |
Removeable.superclass.constructor.apply(this, arguments); |
| 301 |
}; |
| 302 |
|
| 303 |
Removeable.NAME = 'removeableTabs'; |
| 304 |
Removeable.NS = 'removeable'; |
| 305 |
|
| 306 |
Y.extend(Removeable, Y.Plugin.Base, { |
| 307 |
REMOVE_TEMPLATE: '<a class="yui3-tab-remove" title="remove tab">x</a>', |
| 308 |
|
| 309 |
initializer: function(config) { |
| 310 |
var tabview = this.get('host'), |
| 311 |
cb = tabview.get('contentBox'); |
| 312 |
|
| 313 |
cb.addClass('yui3-tabview-removeable'); |
| 314 |
cb.delegate('click', this.onRemoveClick, '.yui3-tab-remove', this); |
| 315 |
|
| 316 |
|
| 317 |
tabview.after('tab:render', this.afterTabRender, this); |
| 318 |
}, |
| 319 |
|
| 320 |
afterTabRender: function(e) { |
| 321 |
|
| 322 |
e.target.get('boundingBox').append(this.REMOVE_TEMPLATE); |
| 323 |
}, |
| 324 |
|
| 325 |
onRemoveClick: function(e) { |
| 326 |
e.stopPropagation(); |
| 327 |
var tab = Y.Widget.getByNode(e.target); |
| 328 |
tab.remove(); |
| 329 |
} |
| 330 |
}); |
| 331 |
|
| 332 |
var res_tv = new Y.TabView({ |
| 333 |
children: [], |
| 334 |
plugins: [ResAddable, Removeable] |
| 335 |
}); |
| 336 |
|
| 337 |
res_tab_list_pop_dlg_setup(function(cargs) { |
| 338 |
if (cargs.choice == 'close_all') { |
| 339 |
res_tv.removeAll(); |
| 340 |
} |
| 341 |
}); |
| 342 |
res_tbl_pop_dlg_setup(res_ctx_menu_cb); |
| 343 |
|
| 344 |
res_tv.after('heightChange', res_tv_resize); |
| 345 |
res_tv.after('widthChange', res_tv_resize); |
| 346 |
res_tv.after("selectionChange", function(e) { |
| 347 |
Y.later(0, null, res_tv_resize_sel, e); |
| 348 |
}); |
| 349 |
|
| 350 |
document['res_tv'] = res_tv; |
| 351 |
res_tv.render('#resTabs'); |
| 352 |
}); |