| 1 |
function fv_t_resize(t, is_sel) { |
| 2 |
var cbox = t.get('panelNode'); |
| 3 |
var fv_tv = document['fv_tv']; |
| 4 |
|
| 5 |
var w = fv_tv.get('width') - 2; |
| 6 |
var lh = cbox.ancestor().ancestor().one('.yui3-tabview-list').get('clientHeight'); |
| 7 |
var h = fv_tv.get('height') - lh; |
| 8 |
|
| 9 |
if (is_sel) { |
| 10 |
if (cbox['g_table_h'] == h && cbox['g_table_w'] == w) { |
| 11 |
return; |
| 12 |
} |
| 13 |
} |
| 14 |
cbox['g_table_h'] = h |
| 15 |
cbox['g_table_w'] = w |
| 16 |
|
| 17 |
var table = cbox['g_table']; |
| 18 |
var dv = cbox['g_dv']; |
| 19 |
if (!table) { |
| 20 |
return; |
| 21 |
} |
| 22 |
table.draw(dv, { |
| 23 |
height: h, |
| 24 |
width: w, |
| 25 |
page : 'enable', |
| 26 |
pageSize : 200, |
| 27 |
}); |
| 28 |
} |
| 29 |
|
| 30 |
function fv_tv_cur_tab() { |
| 31 |
var fv_tv = document['fv_tv']; |
| 32 |
if (!fv_tv.size()) { |
| 33 |
return null; |
| 34 |
} |
| 35 |
return fv_tv.get('selection'); |
| 36 |
} |
| 37 |
|
| 38 |
function fv_tv_resize(e) { |
| 39 |
var t = fv_tv_cur_tab(); |
| 40 |
if (!t) { |
| 41 |
return; |
| 42 |
} |
| 43 |
fv_t_resize(t); |
| 44 |
} |
| 45 |
|
| 46 |
function fv_tv_resize_sel(e) { |
| 47 |
var t = fv_tv_cur_tab(); |
| 48 |
if (!t) { |
| 49 |
return; |
| 50 |
} |
| 51 |
fv_t_resize(t, true); |
| 52 |
} |
| 53 |
|
| 54 |
function flist_query() { |
| 55 |
var fv_tv = document['fv_tv']; |
| 56 |
var targs = { |
| 57 |
label : 'files', |
| 58 |
content : '<div id="fvTbl"> </div>', |
| 59 |
}; |
| 60 |
fv_tv.add(targs); |
| 61 |
var inx = fv_tv.size() - 1; |
| 62 |
fv_tv.selectChild(inx); |
| 63 |
} |
| 64 |
|
| 65 |
function flist_filter_cb(fargs) { |
| 66 |
var t = fv_tv_cur_tab(); |
| 67 |
var cbox = t.get('panelNode'); |
| 68 |
var dt = cbox['g_dt']; |
| 69 |
var dv = cbox['g_dv']; |
| 70 |
|
| 71 |
var col_arr = ['file', 'path']; |
| 72 |
fargs.col = col_arr.indexOf(fargs.col_name); |
| 73 |
var row_list = filter_table(dt, fargs); |
| 74 |
if (row_list.length) { |
| 75 |
dv.hideRows(row_list); |
| 76 |
fv_tv_resize(null); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
function flist_show_all_cb() { |
| 81 |
var t = fv_tv_cur_tab(); |
| 82 |
var cbox = t.get('panelNode'); |
| 83 |
var dt = cbox['g_dt']; |
| 84 |
var dv = cbox['g_dv']; |
| 85 |
|
| 86 |
var num_rows = dt.getNumberOfRows(); |
| 87 |
if (num_rows) { |
| 88 |
dv.setRows(0, num_rows -1); |
| 89 |
} |
| 90 |
fv_tv_resize(null); |
| 91 |
} |
| 92 |
|
| 93 |
function flist_remove_item_cb(row) { |
| 94 |
if (row == -1) { |
| 95 |
return; |
| 96 |
} |
| 97 |
var t = fv_tv_cur_tab(); |
| 98 |
var cbox = t.get('panelNode'); |
| 99 |
var dt = cbox['g_dt']; |
| 100 |
var dv = cbox['g_dv']; |
| 101 |
|
| 102 |
dv.hideRows([row]); |
| 103 |
fv_tv_resize(null); |
| 104 |
} |
| 105 |
|
| 106 |
function flist_ctx_menu_cb(cargs) { |
| 107 |
|
| 108 |
if (cargs.choice == 'filter') { |
| 109 |
var col_arr = ['file', 'path']; |
| 110 |
var col_name = col_arr[cargs.col]; |
| 111 |
flist_filt_dlg_show(flist_filter_cb, col_name); |
| 112 |
} else if(cargs.choice == 'show_all') { |
| 113 |
flist_show_all_cb(); |
| 114 |
} else if (cargs.choice == 'remove_item') { |
| 115 |
flist_remove_item_cb(cargs.row); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
function createFvTable(t) { |
| 120 |
var cbox = t.get('panelNode'); |
| 121 |
var dt = new google.visualization.DataTable(); |
| 122 |
dt.addColumn('string', 'file'); |
| 123 |
dt.addColumn('string', 'path'); |
| 124 |
|
| 125 |
dt.addRows(1); |
| 126 |
dt.setCell(0, 0, 'fetching file list...'); |
| 127 |
|
| 128 |
var dv = new google.visualization.DataView(dt); |
| 129 |
var table = new google.visualization.Table(cbox.getDOMNode()); |
| 130 |
|
| 131 |
cbox['g_dt'] = dt; |
| 132 |
cbox['g_dv'] = dv; |
| 133 |
cbox['g_table'] = table; |
| 134 |
|
| 135 |
fv_t_resize(t); |
| 136 |
} |
| 137 |
|
| 138 |
function populateFvTable(t, res) { |
| 139 |
var cbox = t.get('panelNode'); |
| 140 |
var dt = google.visualization.arrayToDataTable(res); |
| 141 |
var dv = new google.visualization.DataView(dt); |
| 142 |
cbox['g_dt'] = dt; |
| 143 |
cbox['g_dv'] = dv; |
| 144 |
|
| 145 |
fv_t_resize(t); |
| 146 |
|
| 147 |
var table = cbox['g_table']; |
| 148 |
google.visualization.events.addListener(table, 'select', function() { |
| 149 |
var sel = table.getSelection(); |
| 150 |
if (sel.length == 0) { |
| 151 |
return |
| 152 |
} |
| 153 |
var row = sel[0].row; |
| 154 |
|
| 155 |
var dv = cbox['g_dv']; |
| 156 |
var file = dv.getValue(row, 1); |
| 157 |
var line = 1 |
| 158 |
ed_show_file_line(file, line); |
| 159 |
}); |
| 160 |
} |
| 161 |
|
| 162 |
YUI().use('datasource-get', 'datasource-jsonschema', |
| 163 |
'tabview', 'escape', 'plugin', 'node', function(Y) { |
| 164 |
|
| 165 |
var ResAddable = function(config) { |
| 166 |
ResAddable.superclass.constructor.apply(this, arguments); |
| 167 |
}; |
| 168 |
|
| 169 |
ResAddable.NAME = 'addableTabs'; |
| 170 |
ResAddable.NS = 'addable'; |
| 171 |
|
| 172 |
Y.extend(ResAddable, Y.Plugin.Base, { |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
initializer: function(config) { |
| 177 |
var tabview = this.get('host'); |
| 178 |
tabview.after('render', this.afterRender, this); |
| 179 |
tabview.get('contentBox').delegate('click', this.onAddClick, '.yui3-tab-add', this); |
| 180 |
|
| 181 |
tabview.after('tab:render', this.afterTabRender, this); |
| 182 |
|
| 183 |
|
| 184 |
tabview.get('listNode').setStyle('border-width', '0 0 0px'); |
| 185 |
tabview.get('panelNode').setStyle('padding', '0em'); |
| 186 |
}, |
| 187 |
|
| 188 |
afterRender: function(e) { |
| 189 |
var tabview = this.get('host'); |
| 190 |
|
| 191 |
}, |
| 192 |
|
| 193 |
onAddClick: function(e) { |
| 194 |
e.stopPropagation(); |
| 195 |
var tabview = this.get('host'), |
| 196 |
input = this.getTabInput(); |
| 197 |
tabview.add(input); |
| 198 |
tabview.selectChild(tabview.size() - 1); |
| 199 |
}, |
| 200 |
|
| 201 |
afterTabRender: function(e) { |
| 202 |
var t = e.target; |
| 203 |
var cbox = t.get('panelNode'); |
| 204 |
|
| 205 |
var fvTblNode = cbox.one('#fvTbl'); |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
if (fvTblNode) { |
| 211 |
createFvTable(t); |
| 212 |
|
| 213 |
var src = new Y.DataSource.Get({ |
| 214 |
source : document['server_info'].url, |
| 215 |
}); |
| 216 |
src.plug(Y.Plugin.DataSourceJSONSchema, { |
| 217 |
schema : { |
| 218 |
resultListLocator : 'res', |
| 219 |
} |
| 220 |
}); |
| 221 |
|
| 222 |
var request = '?' + to_query_string({ |
| 223 |
project : document['project'], |
| 224 |
cmd_type : 'query', |
| 225 |
cmd_str : 'FLIST', |
| 226 |
}); |
| 227 |
|
| 228 |
src.sendRequest({ |
| 229 |
request : request, |
| 230 |
callback : { |
| 231 |
success: function (e) { |
| 232 |
var res = e.response.results; |
| 233 |
populateFvTable(t, res); |
| 234 |
}, |
| 235 |
failure: function (e) { |
| 236 |
cbox['g_dt'].setCell(0, 0, e.error.message); |
| 237 |
cbox['g_table'].draw(cbox['g_dv']); |
| 238 |
alert(e.error.message); |
| 239 |
}, |
| 240 |
}, |
| 241 |
}); |
| 242 |
} |
| 243 |
} |
| 244 |
}); |
| 245 |
|
| 246 |
var Removeable = function(config) { |
| 247 |
Removeable.superclass.constructor.apply(this, arguments); |
| 248 |
}; |
| 249 |
|
| 250 |
Removeable.NAME = 'removeableTabs'; |
| 251 |
Removeable.NS = 'removeable'; |
| 252 |
|
| 253 |
Y.extend(Removeable, Y.Plugin.Base, { |
| 254 |
REMOVE_TEMPLATE: '<a class="yui3-tab-remove" title="remove tab">x</a>', |
| 255 |
|
| 256 |
initializer: function(config) { |
| 257 |
var tabview = this.get('host'), |
| 258 |
cb = tabview.get('contentBox'); |
| 259 |
|
| 260 |
cb.addClass('yui3-tabview-removeable'); |
| 261 |
cb.delegate('click', this.onRemoveClick, '.yui3-tab-remove', this); |
| 262 |
|
| 263 |
|
| 264 |
tabview.after('tab:render', this.afterTabRender, this); |
| 265 |
}, |
| 266 |
|
| 267 |
afterTabRender: function(e) { |
| 268 |
|
| 269 |
e.target.get('boundingBox').append(this.REMOVE_TEMPLATE); |
| 270 |
}, |
| 271 |
|
| 272 |
onRemoveClick: function(e) { |
| 273 |
e.stopPropagation(); |
| 274 |
var tab = Y.Widget.getByNode(e.target); |
| 275 |
tab.remove(); |
| 276 |
} |
| 277 |
}); |
| 278 |
|
| 279 |
var fv_tv = new Y.TabView({ |
| 280 |
children: [], |
| 281 |
plugins: [ResAddable, Removeable] |
| 282 |
}); |
| 283 |
|
| 284 |
flist_tbl_pop_dlg_setup(flist_ctx_menu_cb); |
| 285 |
|
| 286 |
fv_tv.after('heightChange', fv_tv_resize); |
| 287 |
fv_tv.after('widthChange', fv_tv_resize); |
| 288 |
fv_tv.after("selectionChange", function(e) { |
| 289 |
Y.later(0, null, fv_tv_resize_sel, e); |
| 290 |
}); |
| 291 |
|
| 292 |
fv_tv.after('removeChild', function(e) { |
| 293 |
flist_query(); |
| 294 |
}); |
| 295 |
|
| 296 |
document['fv_tv'] = fv_tv; |
| 297 |
fv_tv.render('#fvTabs'); |
| 298 |
}); |