| 1 |
|
| 2 |
|
| 3 |
"use strict"; |
| 4 |
|
| 5 |
function prim2html(prim, limit) { |
| 6 |
switch(typeof prim) { |
| 7 |
case 'undefined': |
| 8 |
return 'undefined'; |
| 9 |
case 'boolean': |
| 10 |
return prim ? 'true' : 'false'; |
| 11 |
case 'number': |
| 12 |
return String(prim); |
| 13 |
case 'string': |
| 14 |
if (prim.length > limit) { |
| 15 |
prim = prim.substring(0, limit) + '...'; |
| 16 |
} |
| 17 |
return escapeHTML(prim); |
| 18 |
case 'array': |
| 19 |
case 'object': |
| 20 |
if (prim == null) { |
| 21 |
return 'null'; |
| 22 |
} else if ($.isArray(prim)) { |
| 23 |
return 'array'; |
| 24 |
} else { |
| 25 |
return 'object'; |
| 26 |
} |
| 27 |
default: |
| 28 |
return 'ERROR'; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
function escapeHTML(str) { |
| 33 |
return str.replace(/&/g, "&") |
| 34 |
.replace(/"/g, """) |
| 35 |
.replace(/</g, "<") |
| 36 |
.replace(/>/g, ">"); |
| 37 |
} |
| 38 |
var Groonga = { |
| 39 |
key_type_list: ['Int8', 'UInt8', 'Int16', 'UInt16', 'Int32', 'UInt32', |
| 40 |
'Int64', 'UInt64', 'Float', 'Time', 'ShortText', |
| 41 |
'TokyoGeoPoint', 'WGS84GeoPoint'], |
| 42 |
value_type_list: ['Object', 'Bool', |
| 43 |
'Int8', 'UInt8', 'Int16', 'UInt16', 'Int32', 'UInt32', |
| 44 |
'Int64', 'UInt64', 'Float', 'Time'], |
| 45 |
column_type_list: ['Object', 'Bool', |
| 46 |
'Int8', 'UInt8', 'Int16', 'UInt16', 'Int32', 'UInt32', |
| 47 |
'Int64', 'UInt64', 'Float', 'Time', 'ShortText', |
| 48 |
'Text', 'LongText', 'TokyoGeoPoint', 'WGS84GeoPoint'], |
| 49 |
tokenizer_list: ['TokenDelimit', 'TokenUnigram', 'TokenBigram', 'TokenTrigram', 'TokenMecab'], |
| 50 |
GRN_OBJ_PERSISTENT: (0x01<<15), |
| 51 |
|
| 52 |
GRN_OBJ_TABLE_TYPE_MASK: (0x07), |
| 53 |
GRN_OBJ_TABLE_HASH_KEY: (0x00), |
| 54 |
GRN_OBJ_TABLE_PAT_KEY: (0x01), |
| 55 |
GRN_OBJ_TABLE_NO_KEY: (0x03), |
| 56 |
|
| 57 |
GRN_OBJ_KEY_WITH_SIS: (0x01<<6), |
| 58 |
GRN_OBJ_KEY_NORMALIZE: (0x01<<7), |
| 59 |
|
| 60 |
GRN_OBJ_COLUMN_TYPE_MASK: (0x07), |
| 61 |
GRN_OBJ_COLUMN_SCALAR: (0x00), |
| 62 |
GRN_OBJ_COLUMN_VECTOR: (0x01), |
| 63 |
GRN_OBJ_COLUMN_INDEX: (0x02), |
| 64 |
|
| 65 |
GRN_OBJ_COMPRESS_MASK: (0x07<<4), |
| 66 |
GRN_OBJ_COMPRESS_NONE: (0x00<<4), |
| 67 |
GRN_OBJ_COMPRESS_ZLIB: (0x01<<4), |
| 68 |
GRN_OBJ_COMPRESS_LZO: (0x02<<4), |
| 69 |
|
| 70 |
GRN_OBJ_WITH_SECTION: (0x01<<7), |
| 71 |
GRN_OBJ_WITH_WEIGHT: (0x01<<8), |
| 72 |
GRN_OBJ_WITH_POSITION: (0x01<<9) |
| 73 |
}; |
| 74 |
|
| 75 |
$.widget("ui.paginate", { |
| 76 |
version: "1.0", |
| 77 |
options: { |
| 78 |
total: 0, |
| 79 |
nItemsPerPage: 10, |
| 80 |
currentPage: 0, |
| 81 |
nShowLinks: 10, |
| 82 |
callback: null |
| 83 |
}, |
| 84 |
_create: function() { |
| 85 |
var that = this; |
| 86 |
var element = this.element; |
| 87 |
element.addClass("pager"); |
| 88 |
|
| 89 |
var total = this.options.total; |
| 90 |
var nItemsPerPage = this.options.nItemsPerPage; |
| 91 |
var currentPage = this.options.currentPage; |
| 92 |
var nShowLinks = this.options.nShowLinks; |
| 93 |
var lastPage = Math.floor((total - 1) / nItemsPerPage) + 1; |
| 94 |
var start = currentPage - Math.floor(nShowLinks / 2); |
| 95 |
start = (start < 1) ? 1 : start; |
| 96 |
var end = start + nShowLinks - 1; |
| 97 |
end = (end > lastPage) ? lastPage : end; |
| 98 |
|
| 99 |
var callback = this.options.callback; |
| 100 |
if (start > 1) { |
| 101 |
element.append($('<span />') |
| 102 |
.addClass('pager') |
| 103 |
.append($('<a />') |
| 104 |
.attr('href', '#') |
| 105 |
.text('1') |
| 106 |
.click(function () {callback(0)}))); |
| 107 |
element.append($('<span />').text('....')); |
| 108 |
} |
| 109 |
for (var i = start; i <= end; i++) { |
| 110 |
var page = $('<span />').append($('<a />') |
| 111 |
.attr('href', '#') |
| 112 |
.text(String(i)) |
| 113 |
.click(function () { |
| 114 |
callback(Number($(this).text()) - 1); |
| 115 |
})); |
| 116 |
if (i == currentPage) { |
| 117 |
page.addClass('pager-current'); |
| 118 |
} else { |
| 119 |
page.addClass('pager'); |
| 120 |
} |
| 121 |
element.append(page); |
| 122 |
} |
| 123 |
if (end < lastPage) { |
| 124 |
element.append($('<span />') |
| 125 |
.text('....')); |
| 126 |
element.append($('<span />') |
| 127 |
.addClass('pager') |
| 128 |
.append($('<a />') |
| 129 |
.attr('href', '#') |
| 130 |
.text(String(lastPage)) |
| 131 |
.click(function () {callback(lastPage - 1);}))); |
| 132 |
} |
| 133 |
} |
| 134 |
}); |
| 135 |
|
| 136 |
function GroongaAdmin() { |
| 137 |
this.current_table = null; |
| 138 |
this.statusTimer = null; |
| 139 |
this.semaphore = new Array(); |
| 140 |
this.current_status = 0; |
| 141 |
this.reload_record_func = function(){}; |
| 142 |
|
| 143 |
var that = this; |
| 144 |
this._initializeTabs(); |
| 145 |
|
| 146 |
$('#tab-tablelist-link').click(function() { |
| 147 |
that.tablelist(); |
| 148 |
}); |
| 149 |
$('#tab-columnlist-link').click(function() { |
| 150 |
that.columnlist(that.current_table); |
| 151 |
}); |
| 152 |
$('#tab-createrecord-link').click(function() { |
| 153 |
that.update_createrecord(that.current_table); |
| 154 |
}); |
| 155 |
$('#tab-recordlist-link').click(function() { |
| 156 |
that.reload_record_func(); |
| 157 |
}); |
| 158 |
$('#createtable-add-table').click(function() { |
| 159 |
that.createtable(); |
| 160 |
}); |
| 161 |
$('#createrecord-add-record').click(function() { |
| 162 |
that.createrecord(); |
| 163 |
}); |
| 164 |
$('#createcolumn-add-column').click(function() { |
| 165 |
that.createcolumn(); |
| 166 |
}); |
| 167 |
$('#recordlist-remove-record').click(function() { |
| 168 |
that.removerecord(); |
| 169 |
}); |
| 170 |
$('#columnlist-remove-column').click(function() { |
| 171 |
that.removecolumn(); |
| 172 |
}); |
| 173 |
$('#tablelist-remove-table').click(function() { |
| 174 |
that.removetable(); |
| 175 |
}); |
| 176 |
$('#tab-recordlist-form').submit(function() { |
| 177 |
if ($('#table-tab-recordlist-full-checkbox').prop('checked')) { |
| 178 |
|
| 179 |
var d = { |
| 180 |
'table': that.current_table |
| 181 |
} |
| 182 |
$.each(that.SELECT_PARAMS, function(i, val) { |
| 183 |
var e = $('#tab-recordlist-' + val); |
| 184 |
if (e.val()) { |
| 185 |
d[val] = e.val(); |
| 186 |
} |
| 187 |
}); |
| 188 |
that.recordlist(d, true); |
| 189 |
} else { |
| 190 |
|
| 191 |
that.recordlist_simple( |
| 192 |
that.current_table, |
| 193 |
$('#tab-recordlist-simplequery').val(), |
| 194 |
$('#tab-recordlist-simplequerytype').val(), |
| 195 |
1); |
| 196 |
} |
| 197 |
return false; |
| 198 |
}); |
| 199 |
this._initializeSideMenu(); |
| 200 |
this.update_tablelist(); |
| 201 |
|
| 202 |
var e1 = $('#createtable-key-type-builtin'); |
| 203 |
$.each(Groonga.key_type_list, function(i, val) { |
| 204 |
e1.append($('<option />').val(val).text(val)); |
| 205 |
}); |
| 206 |
|
| 207 |
e1 = $('#createtable-value-type-builtin'); |
| 208 |
e1.append($('<option />').val('').text('なし')); |
| 209 |
$.each(Groonga.value_type_list, function(i, val) { |
| 210 |
e1.append($('<option />').val(val).text(val)); |
| 211 |
}); |
| 212 |
|
| 213 |
e1 = $('#createtable-default-tokenizer-builtin'); |
| 214 |
e1.append($('<option />').val('').text('なし')); |
| 215 |
$.each(Groonga.tokenizer_list, function(i, val) { |
| 216 |
e1.append($('<option />').val(val).text(val)); |
| 217 |
}); |
| 218 |
|
| 219 |
e1 = $('#createcolumn-type-builtin'); |
| 220 |
$.each(Groonga.column_type_list, function(i, val) { |
| 221 |
e1.append($('<option />').val(val).text(val)); |
| 222 |
}); |
| 223 |
|
| 224 |
$('#tab-recordlist-simplequerytype').change(function() { |
| 225 |
if ($(this).val() == 'scorer') { |
| 226 |
$('#tab-recordlist-incremental').hide(); |
| 227 |
$('#tab-recordlist-incremental-label').hide(); |
| 228 |
} else { |
| 229 |
$('#tab-recordlist-incremental').show(); |
| 230 |
$('#tab-recordlist-incremental-label').show(); |
| 231 |
} |
| 232 |
$('#tab-recordlist-incremental').change(); |
| 233 |
|
| 234 |
var selectedOption = $(this).find(':selected'); |
| 235 |
$('#tab-recordlist-simplequery').attr( |
| 236 |
'placeholder', selectedOption.data('placeholder') |
| 237 |
); |
| 238 |
}).change(); |
| 239 |
|
| 240 |
$('#table-tab-recordlist-full-checkbox').change(function() { |
| 241 |
if ($(this).prop('checked')) { |
| 242 |
$('#table-tab-recordlist-form-simple').hide(); |
| 243 |
$('#table-tab-recordlist-form-full').show(); |
| 244 |
} else { |
| 245 |
$('#table-tab-recordlist-form-simple').show(); |
| 246 |
$('#table-tab-recordlist-form-full').hide(); |
| 247 |
} |
| 248 |
}).change(); |
| 249 |
|
| 250 |
$('#tab-recordlist-incremental').change(function() { |
| 251 |
$('#tab-recordlist-simplequery').unbind('keyup'); |
| 252 |
if ($(this).prop('checked') && |
| 253 |
$('#tab-recordlist-simplequerytype').val() != 'scorer') { |
| 254 |
$('#tab-recordlist-simplequery').keyup(function(e) { |
| 255 |
that.recordlist_simple( |
| 256 |
that.current_table, |
| 257 |
$('#tab-recordlist-simplequery').val(), |
| 258 |
$('#tab-recordlist-simplequerytype').val(), |
| 259 |
1, |
| 260 |
true); |
| 261 |
}); |
| 262 |
} |
| 263 |
}).change(); |
| 264 |
|
| 265 |
$('#createcolumn-type').change(function(e) { |
| 266 |
var s = $('#createcolumn-type-table option:selected'); |
| 267 |
var cs = $('#createcolumn-source'); |
| 268 |
if (s.length > 0) { |
| 269 |
cs.empty().removeAttr('disabled'); |
| 270 |
that.showloading( |
| 271 |
$.ajax({ |
| 272 |
url: '/d/column_list', |
| 273 |
data: {'table': s.val()}, |
| 274 |
dataType: 'json', |
| 275 |
success: function(d) { |
| 276 |
if(that.validateajax(d) < 0) { return; } |
| 277 |
var idx; |
| 278 |
var b = d[1]; |
| 279 |
$.each(b[0], function(i, val) { |
| 280 |
if (val[0] == 'name') { idx = i; } |
| 281 |
}); |
| 282 |
if (idx) { |
| 283 |
b.shift(); |
| 284 |
$.each(b, function(i, val) { |
| 285 |
cs.append($('<option />').val(val[idx]).text(val[idx])); |
| 286 |
}); |
| 287 |
} |
| 288 |
that.hideloading(); |
| 289 |
}, |
| 290 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 291 |
that.errorloading(XMLHttpRequest); |
| 292 |
} |
| 293 |
}) |
| 294 |
); |
| 295 |
} else { |
| 296 |
cs.empty().attr('disabled', 'disabled'); |
| 297 |
} |
| 298 |
}); |
| 299 |
|
| 300 |
this.recordlist_count = 30; |
| 301 |
|
| 302 |
this.start_status_timer(); |
| 303 |
}; |
| 304 |
|
| 305 |
jQuery.extend(GroongaAdmin.prototype, { |
| 306 |
SELECT_PARAMS: [ |
| 307 |
'match_columns', 'query', 'filter', |
| 308 |
'scorer', |
| 309 |
'output_columns', |
| 310 |
'sortby', 'offset', 'limit', |
| 311 |
'drilldown', |
| 312 |
'drilldown_output_columns', |
| 313 |
'drilldown_sortby', 'drilldown_offset', 'drilldown_limit' |
| 314 |
], |
| 315 |
_initializeTabs: function() { |
| 316 |
this._initializeDatabaseTab(); |
| 317 |
this._initializeTableTab(); |
| 318 |
this._initializeSuggestTab(); |
| 319 |
this._selectTab("database"); |
| 320 |
}, |
| 321 |
_initializeDatabaseTab: function() { |
| 322 |
var that = this; |
| 323 |
|
| 324 |
this._$databaseTabs = $('#database-tabs').tabs({ |
| 325 |
activate: function(e, ui) { |
| 326 |
that.stop_status_timer(); |
| 327 |
if (ui.newPanel.attr('id') == 'database-tab-summary') { |
| 328 |
that.start_status_timer(); |
| 329 |
} |
| 330 |
} |
| 331 |
}); |
| 332 |
}, |
| 333 |
_initializeTableTab: function() { |
| 334 |
this._$tableTabs = $('#table-tabs').tabs({ |
| 335 |
activate: function(e, ui) { |
| 336 |
} |
| 337 |
}); |
| 338 |
}, |
| 339 |
_initializeSuggestTab: function() { |
| 340 |
var that = this; |
| 341 |
|
| 342 |
this._$suggestTabs = $('#suggest-tabs').tabs({ |
| 343 |
activate: function(e, ui) { |
| 344 |
} |
| 345 |
}); |
| 346 |
|
| 347 |
this._initializeSuggestDatasetComplete(); |
| 348 |
this._initializeSuggestQueryComplete(); |
| 349 |
this._initializeSuggestSubmit(); |
| 350 |
this._initializeSuggestResult(); |
| 351 |
}, |
| 352 |
_initializeSuggestDatasetComplete: function() { |
| 353 |
var that = this; |
| 354 |
var $dataset = $("#suggest-dataset"); |
| 355 |
this._$suggestDataset = $dataset; |
| 356 |
$dataset.autocomplete({ |
| 357 |
minLength: 0, |
| 358 |
source: function (request, response) { |
| 359 |
var datasets = []; |
| 360 |
$.each(that._tables, function(i, table_name) { |
| 361 |
var suggestTableMatch = /^item_(.+)$/.exec(table_name); |
| 362 |
if (suggestTableMatch) { |
| 363 |
var dataset = suggestTableMatch[1]; |
| 364 |
datasets.push(dataset); |
| 365 |
} |
| 366 |
}); |
| 367 |
|
| 368 |
datasets = $.ui.autocomplete.filter(datasets, request.term); |
| 369 |
response(datasets); |
| 370 |
} |
| 371 |
}); |
| 372 |
$dataset.focus(function (event) { |
| 373 |
$dataset.autocomplete("search", $dataset.val()); |
| 374 |
}); |
| 375 |
}, |
| 376 |
_suggestParameters: function(query, dataset, type) { |
| 377 |
var nItemsPerPage = 30; |
| 378 |
return { |
| 379 |
query: query, |
| 380 |
types: type, |
| 381 |
table: "item_" + dataset, |
| 382 |
column: "kana", |
| 383 |
offset: 0, |
| 384 |
limit: nItemsPerPage, |
| 385 |
}; |
| 386 |
}, |
| 387 |
_initializeSuggestQueryComplete: function() { |
| 388 |
var that = this; |
| 389 |
this._$suggestQuery = $("#suggest-query").autocomplete({ |
| 390 |
source: function (request, response) { |
| 391 |
var $dataset = $("#suggest-dataset"); |
| 392 |
var dataset = $dataset.val(); |
| 393 |
$("#suggest-submit").click(); |
| 394 |
$.ajax({ |
| 395 |
url: "/d/suggest", |
| 396 |
data: that._suggestParameters(request.term, dataset, "complete"), |
| 397 |
dataType: "jsonp", |
| 398 |
success: function (data, textStatus, jqXHR) { |
| 399 |
var completions = data[1]["complete"]; |
| 400 |
var items = []; |
| 401 |
if (completions && completions.length > 2) { |
| 402 |
completions.shift(); |
| 403 |
completions.shift(); |
| 404 |
$.each(completions, function(i, item) { |
| 405 |
var key = item[0]; |
| 406 |
items.push(key); |
| 407 |
if (items.length >= 3) { |
| 408 |
return false; |
| 409 |
} |
| 410 |
return true; |
| 411 |
}); |
| 412 |
} |
| 413 |
response(items); |
| 414 |
}, |
| 415 |
error: function(jqXHR, textStatus, errorThrown) { |
| 416 |
} |
| 417 |
}); |
| 418 |
} |
| 419 |
}); |
| 420 |
}, |
| 421 |
_initializeSuggestSubmit: function() { |
| 422 |
var that = this; |
| 423 |
$("#suggest-submit").click(function (event) { |
| 424 |
var dataset = $("#suggest-dataset").val(); |
| 425 |
var query = $("#suggest-query").val(); |
| 426 |
var type = that._suggestResultType; |
| 427 |
var parameters = that._suggestParameters(query, dataset, type); |
| 428 |
$.ajax({ |
| 429 |
url: "/d/suggest", |
| 430 |
data: parameters, |
| 431 |
dataType: "jsonp", |
| 432 |
success: function (data, textStatus, jqXHR) { |
| 433 |
var response = data[1][type]; |
| 434 |
response.shift(); |
| 435 |
var $result = $("#suggest-result-tab-" + type); |
| 436 |
$result |
| 437 |
.empty() |
| 438 |
.append($("<div/>").append(that._createResultTable(response))); |
| 439 |
}, |
| 440 |
error: function(jqXHR, textStatus, errorThrown) { |
| 441 |
} |
| 442 |
}); |
| 443 |
}); |
| 444 |
}, |
| 445 |
_initializeSuggestResult: function() { |
| 446 |
var that = this; |
| 447 |
$("#suggest-result-tabs").tabs({ |
| 448 |
activate: function (event, ui) { |
| 449 |
that._suggestResultType = ui.newPanel.attr('id').replace(/^suggest-result-tab-/, ""); |
| 450 |
$("#suggest-submit").click(); |
| 451 |
} |
| 452 |
}); |
| 453 |
}, |
| 454 |
_selectTab: function(name) { |
| 455 |
this.stop_status_timer(); |
| 456 |
this._$databaseTabs.hide(); |
| 457 |
this._$tableTabs.hide(); |
| 458 |
this._$suggestTabs.hide(); |
| 459 |
switch (name) { |
| 460 |
case "table": |
| 461 |
this._$tableTabs.show(); |
| 462 |
break; |
| 463 |
case "suggest": |
| 464 |
this._$suggestTabs.show(); |
| 465 |
break; |
| 466 |
case "database": |
| 467 |
default: |
| 468 |
this._$databaseTabs.show(); |
| 469 |
break; |
| 470 |
} |
| 471 |
}, |
| 472 |
_initializeSideMenu: function () { |
| 473 |
var that = this; |
| 474 |
$('#side-menu-summary').click(function() { |
| 475 |
that.current_table = null; |
| 476 |
that._selectTab("database"); |
| 477 |
that._$databaseTabs.tabs("option", "active", 0); |
| 478 |
that.stop_status_timer(); |
| 479 |
that.start_status_timer(); |
| 480 |
}); |
| 481 |
$('#side-menu-suggest').click(function() { |
| 482 |
that.current_table = null; |
| 483 |
that._selectTab("suggest"); |
| 484 |
}); |
| 485 |
}, |
| 486 |
start_status_timer: function() { |
| 487 |
var that = this; |
| 488 |
this.stop_status_timer(); |
| 489 |
this.status(); |
| 490 |
this.statusTimer = setInterval(function() {that.status()}, 1000); |
| 491 |
}, |
| 492 |
change_status_timer: function(time) { |
| 493 |
var that = this; |
| 494 |
this.stop_status_timer(); |
| 495 |
this.statusTimer = setInterval(function() {that.status()}, time); |
| 496 |
}, |
| 497 |
stop_status_timer: function() { |
| 498 |
if (this.statusTimer) { |
| 499 |
clearInterval(this.statusTimer); |
| 500 |
this.statusTimer = null; |
| 501 |
} |
| 502 |
}, |
| 503 |
_createResultTable: function (result, options) { |
| 504 |
var that = this; |
| 505 |
if (!options) { |
| 506 |
options = {}; |
| 507 |
} |
| 508 |
var table = $('<table class="records"/>'); |
| 509 |
if ($.isArray(result)) { |
| 510 |
var nEntries = result.length; |
| 511 |
if (nEntries >= 1) { |
| 512 |
var thead = $('<thead/>'); |
| 513 |
table.append(thead); |
| 514 |
var line = result[0]; |
| 515 |
if ($.isArray(line)) { |
| 516 |
var tr = $('<tr/>'); |
| 517 |
thead.append(tr); |
| 518 |
var m = line.length; |
| 519 |
if (options.check) { |
| 520 |
tr.append($('<th/>')); |
| 521 |
} |
| 522 |
for (var j = 0; j < m; j++) { |
| 523 |
var th = $('<th/>'); |
| 524 |
tr.append(th); |
| 525 |
th.append(prim2html(line[j][0], 128)); |
| 526 |
th.append($('<br />')); |
| 527 |
th.append(prim2html(line[j][1], 128)); |
| 528 |
} |
| 529 |
if (options.button) { |
| 530 |
tr.append($('<th/>')); |
| 531 |
} |
| 532 |
} |
| 533 |
var tbody = $('<tbody>'); |
| 534 |
table.append(tbody); |
| 535 |
for (var i = 1; i < nEntries; i++) { |
| 536 |
line = result[i]; |
| 537 |
if ($.isArray(line)) { |
| 538 |
var tr = $('<tr>'); |
| 539 |
table.append(tr); |
| 540 |
var m = line.length; |
| 541 |
switch(options.check) {ックスの値を何にするか |
| 542 |
case 1: レコード一覧の_id等) |
| 543 |
case 2: ブル・カラム一覧のname等) |
| 544 |
var td = $('<td/>'); |
| 545 |
tr.append(td); |
| 546 |
td.append($('<input/>') |
| 547 |
.attr("type", "checkbox") |
| 548 |
.attr("value", line[options.check-1])); |
| 549 |
break; |
| 550 |
} |
| 551 |
for (var j = 0; j < m; j++) { |
| 552 |
var td = $('<td/>'); |
| 553 |
tr.append(td); |
| 554 |
td.append(prim2html(line[j], 128)); |
| 555 |
} |
| 556 |
switch(options.button) { |
| 557 |
case 1: |
| 558 |
var td = $('<td/>'); |
| 559 |
tr.append(td); |
| 560 |
td.append($('<input/>') |
| 561 |
.attr("type", "button") |
| 562 |
.attr("value", "編集") |
| 563 |
.attr("data-record-id", line[0]) |
| 564 |
.click(function () { |
| 565 |
that.show_edit_record($(this).attr("data-record-id")); |
| 566 |
})); |
| 567 |
break; |
| 568 |
case 2: |
| 569 |
var td = $('<td/>'); |
| 570 |
tr.append(td); |
| 571 |
td.append($('<input/>') |
| 572 |
.attr("type", "button") |
| 573 |
.attr("value", "詳細") |
| 574 |
.attr("data-table-name", line[1]) |
| 575 |
.click(function () { |
| 576 |
var tableName = $(this).attr("data-table-name"); |
| 577 |
$("#side-menu-tablelist-link-" + tableName).click(); |
| 578 |
})); |
| 579 |
break; |
| 580 |
} |
| 581 |
} |
| 582 |
} |
| 583 |
} |
| 584 |
} |
| 585 |
return table; |
| 586 |
}, |
| 587 |
show_edit_record: function(id) { |
| 588 |
$('#table-tabs').tabs("option", "active", 2); |
| 589 |
this.update_createrecord(this.current_table, id); |
| 590 |
}, |
| 591 |
format_unix_time: function(unix_time) { |
| 592 |
var date = new Date(); |
| 593 |
date.setTime(unix_time * 1000); |
| 594 |
return date.toLocaleString(); |
| 595 |
}, |
| 596 |
format_duration: function(duration_in_seconds) { |
| 597 |
var duration = ""; |
| 598 |
var days = Math.floor(duration_in_seconds / 3600 / 24); |
| 599 |
var hours = Math.floor(duration_in_seconds / 3600 % 24); |
| 600 |
var minutes = Math.floor(duration_in_seconds / 60 % 60); |
| 601 |
var seconds = Math.floor(duration_in_seconds % 60); |
| 602 |
|
| 603 |
if (days > 0) { |
| 604 |
duration += days; |
| 605 |
if (days == 1) { |
| 606 |
duration += " day, "; |
| 607 |
} else { |
| 608 |
duration += " days, "; |
| 609 |
} |
| 610 |
} |
| 611 |
if (days > 0 || hours > 0) { |
| 612 |
duration += hours + ":" + minutes + ":" + seconds; |
| 613 |
} else if (minutes > 0) { |
| 614 |
duration += minutes + ":" + seconds; |
| 615 |
} else { |
| 616 |
duration += seconds; |
| 617 |
} |
| 618 |
|
| 619 |
return duration; |
| 620 |
}, |
| 621 |
maxThroughput: 0, |
| 622 |
lastNQueries: -1, |
| 623 |
keepLastNData: 100, |
| 624 |
throughputData: [], |
| 625 |
throughputChart: null, |
| 626 |
updateThroughputChart: function(statusData) { |
| 627 |
var maxThroughputUpdated = false; |
| 628 |
if (this.lastNQueries >= 0) { |
| 629 |
var throughput = statusData.n_queries - this.lastNQueries; |
| 630 |
this.throughputData.push(throughput); |
| 631 |
if (this.maxThroughput < throughput) { |
| 632 |
this.maxThroughput = throughput; |
| 633 |
maxThroughputUpdated = true; |
| 634 |
} |
| 635 |
} |
| 636 |
if (this.throughputData.length > this.keepLastNData) { |
| 637 |
this.throughputData.shift(); |
| 638 |
} |
| 639 |
if (!this.throughputChart) { |
| 640 |
this.throughputChart = $.plot($("#throughput-chart"), |
| 641 |
[[]], |
| 642 |
{xaxis: {min: -(this.keepLastNData - 1), |
| 643 |
max: 0}, |
| 644 |
yaxis: {min: 0}}); |
| 645 |
} |
| 646 |
var that = this; |
| 647 |
var chartSeries = $.map(this.throughputData, function(n, i) { |
| 648 |
return [[-(that.throughputData.length - i) + 1, n]]; |
| 649 |
}); |
| 650 |
this.throughputChart.setData([chartSeries]); |
| 651 |
if (maxThroughputUpdated) { |
| 652 |
this.throughputChart.setupGrid(); |
| 653 |
} |
| 654 |
this.throughputChart.draw(); |
| 655 |
this.lastNQueries = statusData.n_queries; |
| 656 |
}, |
| 657 |
status: function() { |
| 658 |
if (this.current_status > 0) { return; } |
| 659 |
this.current_status++; |
| 660 |
var that = this; |
| 661 |
$.ajax({ |
| 662 |
url: '/d/status', |
| 663 |
data: {}, |
| 664 |
dataType: 'json', |
| 665 |
success: function(b) { |
| 666 |
that.current_status--; |
| 667 |
if (!b) { |
| 668 |
that.change_status_timer(10000); |
| 669 |
return; |
| 670 |
} |
| 671 |
var d = b[1]; |
| 672 |
$('#status-starttime').text(that.format_unix_time(d.starttime)); |
| 673 |
$('#status-uptime').text(that.format_duration(d.uptime)); |
| 674 |
$('#status-n-queries').text(d.n_queries); |
| 675 |
$('#status-cache-hit-rate').text(d.cache_hit_rate); |
| 676 |
that.updateThroughputChart(d); |
| 677 |
that.change_status_timer(1000); |
| 678 |
}, |
| 679 |
error: function() { |
| 680 |
that.current_status--; |
| 681 |
that.change_status_timer(10000); |
| 682 |
} |
| 683 |
}); |
| 684 |
}, |
| 685 |
update_tablelist: function() { |
| 686 |
var that = this; |
| 687 |
this._tables = []; |
| 688 |
this.showloading( |
| 689 |
$.ajax({ |
| 690 |
url: '/d/table_list', |
| 691 |
data: {}, |
| 692 |
dataType: 'json', |
| 693 |
success: function(d) { |
| 694 |
if (that.validateajax(d) < 0) { return; } |
| 695 |
d.shift(); |
| 696 |
var tl = $('#side-menu-tablelist').empty(); |
| 697 |
var tt = $('#createtable-key-type-table').empty(); |
| 698 |
var vt = $('#createtable-value-type-table').empty(); |
| 699 |
var ct = $('#createcolumn-type-table').empty(); |
| 700 |
var b = d.shift(); |
| 701 |
b.shift(); |
| 702 |
$.each(b, function(i, val) { |
| 703 |
var table_name = val[1]; |
| 704 |
that._tables.push(table_name); |
| 705 |
tl.append( |
| 706 |
$('<li />').append( |
| 707 |
$('<a />') |
| 708 |
.attr('id', 'side-menu-tablelist-link-' + table_name) |
| 709 |
.attr('href', '#side-menu-tablelist-' + table_name) |
| 710 |
.text(table_name) |
| 711 |
.click(function() { |
| 712 |
that.current_table = table_name; |
| 713 |
$('#database-tabs').hide(); |
| 714 |
$('#suggest-tabs').hide(); |
| 715 |
that.stop_status_timer(); |
| 716 |
$('#table-tabs').show(); |
| 717 |
that.columnlist(table_name); |
| 718 |
$('#tab-recordlist-simplequery').val(''); |
| 719 |
that.recordlist_simple(table_name, null, null, 1); |
| 720 |
that.update_createrecord(that.current_table); |
| 721 |
}) |
| 722 |
) |
| 723 |
); |
| 724 |
tt.append($('<option />').val(val[1]).text(val[1])); |
| 725 |
vt.append($('<option />').val(val[1]).text(val[1])); |
| 726 |
ct.append($('<option />').val(val[1]).text(val[1])); |
| 727 |
}); |
| 728 |
that.hideloading(); |
| 729 |
}, |
| 730 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 731 |
that.errorloading(XMLHttpRequest); |
| 732 |
} |
| 733 |
}) |
| 734 |
); |
| 735 |
}, |
| 736 |
tablelist: function() { |
| 737 |
$('#tab-tablelist-table').empty(); |
| 738 |
var that = this; |
| 739 |
this.showloading( |
| 740 |
$.ajax({ |
| 741 |
url: '/d/table_list', |
| 742 |
data: {}, |
| 743 |
dataType: 'json', |
| 744 |
success: function(d) { |
| 745 |
if (that.validateajax(d) < 0) { return; } |
| 746 |
var b = d[1]; |
| 747 |
var table = that._createResultTable(b, {check: 2, button: 2}); |
| 748 |
$('#tab-tablelist-table').append($('<h1 />').text('テーブル一覧')).append(table); |
| 749 |
that.hideloading(); |
| 750 |
}, |
| 751 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 752 |
that.errorloading(XMLHttpRequest); |
| 753 |
} |
| 754 |
}) |
| 755 |
); |
| 756 |
}, |
| 757 |
recordlist_simple: function(table_name, simplequery, simplequery_type, page, hide_dialog) { |
| 758 |
var d = { |
| 759 |
'table': table_name, |
| 760 |
'offset': (page - 1) * this.recordlist_count, |
| 761 |
'limit': this.recordlist_count |
| 762 |
} |
| 763 |
switch (simplequery_type) { |
| 764 |
case 'query': |
| 765 |
case 'filter': |
| 766 |
case null: |
| 767 |
if (simplequery) { |
| 768 |
d[simplequery_type] = simplequery; |
| 769 |
} |
| 770 |
this.recordlist(d, true, hide_dialog); |
| 771 |
break; |
| 772 |
} |
| 773 |
}, |
| 774 |
recordlist: function(params, show_pager, hide_dialog) { |
| 775 |
var that = this; |
| 776 |
this.reload_record_func = function(){ |
| 777 |
that.recordlist(params, show_pager, hide_dialog); |
| 778 |
}; |
| 779 |
this.showloading( |
| 780 |
$.ajax({ |
| 781 |
url: '/d/select', |
| 782 |
data: params, |
| 783 |
dataType: 'json', |
| 784 |
success: function(d) { |
| 785 |
if (that.validateajax(d, hide_dialog) < 0) { return; } |
| 786 |
var rc = d.shift(); |
| 787 |
if (rc[0] != 0) { |
| 788 |
alert('error: ' + rc[3]); |
| 789 |
that.hideloading(); |
| 790 |
return false; |
| 791 |
} |
| 792 |
var body = d.shift(); |
| 793 |
var recs = body.shift(); |
| 794 |
var all_count = recs.shift()[0]; |
| 795 |
var pager; |
| 796 |
if (show_pager) { |
| 797 |
var offset = params['offset'] || 0; |
| 798 |
var rows = params['limit'] || 10; |
| 799 |
if (rows < 0){ |
| 800 |
rows = all_count + parseInt(rows) + 1; |
| 801 |
} |
| 802 |
if (rows != '' && !parseInt(rows)) { |
| 803 |
pager = $('<span />'); |
| 804 |
} else { |
| 805 |
pager = $("<div/>"); |
| 806 |
pager.paginate({ |
| 807 |
total: all_count, |
| 808 |
nItemsPerPage: rows, |
| 809 |
currentPage: Math.floor(offset/rows)+1, |
| 810 |
callback: function(page) { |
| 811 |
params['offset'] = page * rows; |
| 812 |
that.recordlist(params, true, false); |
| 813 |
return false; |
| 814 |
} |
| 815 |
}); |
| 816 |
} |
| 817 |
} else { |
| 818 |
pager = $('<span />'); |
| 819 |
} |
| 820 |
$('#tab-recordlist-table') |
| 821 |
.empty() |
| 822 |
.append($('<h1 />').text('レコード一覧: ' + params['table'])) |
| 823 |
.append($('<p />').text('総件数: ' + all_count)) |
| 824 |
.append(pager.clone(true)) |
| 825 |
.append($('<div />').append(that._createResultTable(recs, {check: 1, button: 1}))) |
| 826 |
.append(pager); |
| 827 |
that.hideloading(); |
| 828 |
}, |
| 829 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 830 |
that.errorloading(XMLHttpRequest, hide_dialog); |
| 831 |
} |
| 832 |
}) |
| 833 |
,hide_dialog); |
| 834 |
}, |
| 835 |
columnlist: function(table_name) { |
| 836 |
var that = this; |
| 837 |
$('#tab-columnlist-table').empty(); |
| 838 |
this.showloading( |
| 839 |
$.ajax({ |
| 840 |
url: '/d/column_list', |
| 841 |
data: {'table': table_name}, |
| 842 |
dataType: 'json', |
| 843 |
success: function(d) { |
| 844 |
if (that.validateajax(d) < 0) { return; } |
| 845 |
var b = d[1]; |
| 846 |
var table = that._createResultTable(b, {check: 2}); |
| 847 |
$('#tab-columnlist-table') |
| 848 |
.append($('<h1 />').text('カラム一覧: ' + table_name)) |
| 849 |
.append(table); |
| 850 |
that.hideloading(); |
| 851 |
}, |
| 852 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 853 |
that.errorloading(XMLHttpRequest); |
| 854 |
} |
| 855 |
}) |
| 856 |
); |
| 857 |
}, |
| 858 |
add_record_inputbox: function(type, value) { |
| 859 |
var inputbox = null; |
| 860 |
switch(type){ |
| 861 |
case "Bool": |
| 862 |
inputbox = $('<input />') |
| 863 |
.attr("type","checkbox") |
| 864 |
.attr("value","true"); |
| 865 |
if (value) { |
| 866 |
inputbox.attr("checked",""); |
| 867 |
} |
| 868 |
break; |
| 869 |
case "UInt8": |
| 870 |
case "UInt16": |
| 871 |
case "UInt32": |
| 872 |
case "UInt64": |
| 873 |
case "Int8": |
| 874 |
case "Int16": |
| 875 |
case "Int32": |
| 876 |
case "Int64": |
| 877 |
case "Float": |
| 878 |
inputbox = $('<input />') |
| 879 |
.attr("type", "text") |
| 880 |
.val(isNaN(value) ? "" : value); |
| 881 |
break; |
| 882 |
case "Text": |
| 883 |
case "ShortText": |
| 884 |
case "LongText": |
| 885 |
inputbox = $('<textarea />') |
| 886 |
.attr("cols", "50") |
| 887 |
.attr("rows", "2") |
| 888 |
.text(value ? value : ""); |
| 889 |
break; |
| 890 |
case "TokyoGeoPoint": |
| 891 |
case "WGS84GeoPoint": |
| 892 |
case "Time": |
| 893 |
inputbox = $('<input />') |
| 894 |
.attr("type", "text") |
| 895 |
.attr("size", "40") |
| 896 |
.val(value ? value : ""); |
| 897 |
break; |
| 898 |
case "Object": |
| 899 |
inputbox = $('<input />') |
| 900 |
.attr("type", "text") |
| 901 |
.attr("disabled", "disabled"); |
| 902 |
break; |
| 903 |
default: |
| 904 |
inputbox = $('<input />') |
| 905 |
.attr("type", "text") |
| 906 |
.val(value ? value : ""); |
| 907 |
} |
| 908 |
inputbox.addClass('column_values'); |
| 909 |
return inputbox; |
| 910 |
}, |
| 911 |
add_record_deletebutton: function(){ |
| 912 |
var ret = |
| 913 |
$('<span />') |
| 914 |
.append("[×]") |
| 915 |
.css('cursor', 'pointer') |
| 916 |
.click(function() { |
| 917 |
$(this).prev().remove(); |
| 918 |
$(this).next().remove(); |
| 919 |
$(this).remove(); |
| 920 |
}); |
| 921 |
return ret; |
| 922 |
}, |
| 923 |
update_createrecord_loadcomplete: function(d_sel, d_col) { |
| 924 |
var that = this; |
| 925 |
var b = d_sel[1][0]; |
| 926 |
var columns = $('<tbody />'); |
| 927 |
var listofs = b[1].length - (d_col[1].length - 1); |
| 928 |
for (var i = 1; i < b[1].length; i++) { |
| 929 |
var line = b[1][i]; |
| 930 |
var value = null; |
| 931 |
if (b[2]) value = b[2][i]; |
| 932 |
if ($.isArray(line)) { |
| 933 |
var tr = $('<tr/ >') |
| 934 |
.addClass('create-record-columns') |
| 935 |
.append( |
| 936 |
$('<td />') |
| 937 |
.addClass('columnname') |
| 938 |
.append(prim2html(line[0], 128)) |
| 939 |
) |
| 940 |
.append( |
| 941 |
$('<td />') |
| 942 |
.addClass('columntype') |
| 943 |
.append("(") |
| 944 |
.append($('<span />') |
| 945 |
.append(prim2html(line[1], 128)) |
| 946 |
) |
| 947 |
.append(")") |
| 948 |
); |
| 949 |
var inputtd = $('<td />').addClass('columnval'); |
| 950 |
if (i >= listofs && d_col[1][i - listofs + 1][4].indexOf("COLUMN_VECTOR") >= 0){ |
| 951 |
var type = line[1]; |
| 952 |
if (value != null) { |
| 953 |
for (var j = 0; j < value.length; j++) { |
| 954 |
inputtd |
| 955 |
.append(this.add_record_inputbox(line[1], value[j])) |
| 956 |
.append(this.add_record_deletebutton()) |
| 957 |
.append('<br />'); |
| 958 |
} |
| 959 |
} |
| 960 |
inputtd |
| 961 |
.append($('<span />') |
| 962 |
.append("[値を追加]") |
| 963 |
.css('cursor', 'pointer') |
| 964 |
.click(function() { |
| 965 |
var target = $(this).parent(); |
| 966 |
target |
| 967 |
.append(that.add_record_inputbox($(this).parent().prev().children().text())) |
| 968 |
.append(that.add_record_deletebutton()) |
| 969 |
.append("<br />"); |
| 970 |
$(this).appendTo(target); |
| 971 |
}) |
| 972 |
); |
| 973 |
} else { |
| 974 |
inputtd.append(this.add_record_inputbox(line[1], value)); |
| 975 |
if (line[0] == "_key" && value != null) { |
| 976 |
inputtd.children().attr("disabled", "disabled"); |
| 977 |
} |
| 978 |
} |
| 979 |
tr.append(inputtd); |
| 980 |
columns.append(tr); |
| 981 |
} |
| 982 |
} |
| 983 |
$("#table-createrecord").append(columns); |
| 984 |
this.hideloading(); |
| 985 |
}, |
| 986 |
update_createrecord: function(table_name, id) { |
| 987 |
var that = this; |
| 988 |
var d_sel = null; |
| 989 |
var d_col = null; |
| 990 |
var select_data = { |
| 991 |
'table' : table_name |
| 992 |
}; |
| 993 |
if (id) { |
| 994 |
select_data.query = '_id:' + id; |
| 995 |
select_data.limit = '1'; |
| 996 |
} else { |
| 997 |
select_data.limit = '0'; |
| 998 |
} |
| 999 |
$('#table-createrecord').empty(); |
| 1000 |
this.showloading( |
| 1001 |
$.ajax({ |
| 1002 |
url: '/d/select', |
| 1003 |
data: select_data, |
| 1004 |
dataType: 'json', |
| 1005 |
success: function(d) { |
| 1006 |
if (that.validateajax(d) < 0) { return; } |
| 1007 |
d_sel = d; |
| 1008 |
if (d_col) { |
| 1009 |
that.update_createrecord_loadcomplete(d_sel, d_col); |
| 1010 |
} |
| 1011 |
}, |
| 1012 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 1013 |
that.errorloading(XMLHttpRequest); |
| 1014 |
} |
| 1015 |
}) |
| 1016 |
); |
| 1017 |
this.showloading( |
| 1018 |
$.ajax({ |
| 1019 |
url: '/d/column_list', |
| 1020 |
data: { |
| 1021 |
'table' : table_name |
| 1022 |
}, |
| 1023 |
dataType: 'json', |
| 1024 |
success: function(d) { |
| 1025 |
if (that.validateajax(d) < 0) { return; } |
| 1026 |
d_col = d; |
| 1027 |
if (d_sel) { |
| 1028 |
that.update_createrecord_loadcomplete(d_sel, d_col); |
| 1029 |
} |
| 1030 |
}, |
| 1031 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 1032 |
that.errorloading(XMLHttpRequest); |
| 1033 |
} |
| 1034 |
}) |
| 1035 |
); |
| 1036 |
}, |
| 1037 |
createtable: function() { |
| 1038 |
var that = this; |
| 1039 |
var flags = 0; |
| 1040 |
$('#createtable-flags>input:checked').each(function() { |
| 1041 |
flags |= Groonga[$(this).val()]; |
| 1042 |
}); |
| 1043 |
flags |= Groonga[$('#createtable-key-index').val()]; |
| 1044 |
this.showloading( |
| 1045 |
$.ajax({ |
| 1046 |
url: '/d/table_create', |
| 1047 |
data: { |
| 1048 |
name: $('#createtable-name').val(), |
| 1049 |
'flags': flags, |
| 1050 |
key_type: $('#createtable-key-type').val(), |
| 1051 |
value_type: $('#createtable-value-type').val(), |
| 1052 |
default_tokenizer: $('#createtable-default-tokenizer').val() |
| 1053 |
}, |
| 1054 |
dataType: 'json', |
| 1055 |
success: function(d) { |
| 1056 |
if (that.validateajax(d) < 0) { return; } |
| 1057 |
that.hideloading(); |
| 1058 |
alert('テーブルを作成しました。'); |
| 1059 |
that.update_tablelist(); |
| 1060 |
}, |
| 1061 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 1062 |
that.errorloading(XMLHttpRequest); |
| 1063 |
} |
| 1064 |
}) |
| 1065 |
); |
| 1066 |
}, |
| 1067 |
createcolumn: function() { |
| 1068 |
var that = this; |
| 1069 |
var flags = 0; |
| 1070 |
$('#createcolumn-flags>input:checked').each(function() { |
| 1071 |
flags |= Groonga[$(this).val()]; |
| 1072 |
}); |
| 1073 |
$('#createcolumn-ii-flags>input:checked').each(function() { |
| 1074 |
flags |= Groonga[$(this).val()]; |
| 1075 |
}); |
| 1076 |
flags |= Groonga[$('#createcolumn-column-type').val()]; |
| 1077 |
flags |= Groonga[$('#createcolumn-column-compress').val()]; |
| 1078 |
var d = { |
| 1079 |
table: this.current_table, |
| 1080 |
name: $('#createcolumn-name').val(), |
| 1081 |
'flags': flags, |
| 1082 |
type: $('#createcolumn-type').val() |
| 1083 |
}; |
| 1084 |
if ($('#createcolumn-source').val()) { |
| 1085 |
d['source'] = $('#createcolumn-source').val(); |
| 1086 |
} |
| 1087 |
this.showloading( |
| 1088 |
$.ajax({ |
| 1089 |
url: '/d/column_create', |
| 1090 |
data: d, |
| 1091 |
dataType: 'json', |
| 1092 |
success: function(d) { |
| 1093 |
if (that.validateajax(d) < 0) { return; } |
| 1094 |
that.hideloading(); |
| 1095 |
alert('カラムを作成しました。'); |
| 1096 |
}, |
| 1097 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 1098 |
that.errorloading(XMLHttpRequest); |
| 1099 |
} |
| 1100 |
}) |
| 1101 |
); |
| 1102 |
}, |
| 1103 |
createrecord_getvalue: function(type, inputbox) { |
| 1104 |
switch(type){ |
| 1105 |
case "Bool": |
| 1106 |
if (inputbox.is('input:checked')) { |
| 1107 |
return true; |
| 1108 |
} else { |
| 1109 |
return false; |
| 1110 |
} |
| 1111 |
default: |
| 1112 |
return inputbox.val(); |
| 1113 |
} |
| 1114 |
}, |
| 1115 |
createrecord: function() { |
| 1116 |
var that = this; |
| 1117 |
var d = {}; |
| 1118 |
$('.create-record-columns').each(function() { |
| 1119 |
if (!$(this).children('.columnval').children().attr('disabled') |
| 1120 |
|| $(this).children('.columnname').text() == "_key") { |
| 1121 |
var type = $(this).children('.columntype').children().text(); |
| 1122 |
if ($(this).children('.columnval').children('span').length) { |
| 1123 |
var arr = []; |
| 1124 |
$(this).children('.columnval').children('.column_values').each(function() { |
| 1125 |
arr.push(that.createrecord_getvalue(type, $(this))); |
| 1126 |
}); |
| 1127 |
d[$(this).children('.columnname').text()] = arr; |
| 1128 |
} else { |
| 1129 |
d[$(this).children('.columnname').text()] = |
| 1130 |
that.createrecord_getvalue(type, $(this).children('.columnval').children()); |
| 1131 |
} |
| 1132 |
} |
| 1133 |
}); |
| 1134 |
this.showloading( |
| 1135 |
$.ajax({ |
| 1136 |
url: '/d/load', |
| 1137 |
data: { |
| 1138 |
"table" : this.current_table, |
| 1139 |
"input_type" : "json", |
| 1140 |
"output_type" : "json", |
| 1141 |
"values" : JSON.stringify([d]) |
| 1142 |
}, |
| 1143 |
dataType: 'json', |
| 1144 |
success: function(d) { |
| 1145 |
if (that.validateajax(d) < 0) { return; } |
| 1146 |
that.hideloading(); |
| 1147 |
alert('レコードを作成しました。'); |
| 1148 |
}, |
| 1149 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 1150 |
that.errorloading(XMLHttpRequest); |
| 1151 |
} |
| 1152 |
}) |
| 1153 |
); |
| 1154 |
}, |
| 1155 |
removerecord: function() { |
| 1156 |
var that = this; |
| 1157 |
var checklist = $("#tab-recordlist-table").find("input:checked"); |
| 1158 |
var completecount = checklist.length; |
| 1159 |
if (completecount > 0) { |
| 1160 |
$('<div />') |
| 1161 |
.append("選択した" + completecount + "件のレコードを削除しますか?") |
| 1162 |
.dialog({ |
| 1163 |
modal: true, |
| 1164 |
buttons: { |
| 1165 |
'いいえ': function() { |
| 1166 |
$(this).dialog('close'); |
| 1167 |
}, |
| 1168 |
'はい': function() { |
| 1169 |
$(this).dialog('close'); |
| 1170 |
checklist.each(function(i, val) { |
| 1171 |
that.showloading( |
| 1172 |
$.ajax({ |
| 1173 |
url: '/d/delete', |
| 1174 |
data: { |
| 1175 |
"table" : that.current_table, |
| 1176 |
"id" : val.value |
| 1177 |
}, |
| 1178 |
dataType: 'json', |
| 1179 |
success: function() { |
| 1180 |
if (--completecount == 0) { |
| 1181 |
$('#tab-recordlist-form').submit(); |
| 1182 |
alert('レコードを削除しました。'); |
| 1183 |
} else if (completecount < 0){ |
| 1184 |
that.hideloading(); |
| 1185 |
} |
| 1186 |
}, |
| 1187 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 1188 |
completecount = 0; |
| 1189 |
that.errorloading(XMLHttpRequest); |
| 1190 |
} |
| 1191 |
}) |
| 1192 |
); |
| 1193 |
}); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
}); |
| 1197 |
} |
| 1198 |
}, |
| 1199 |
removecolumn: function() { |
| 1200 |
var that = this; |
| 1201 |
var checklist = $("#tab-columnlist-table").find("input:checked"); |
| 1202 |
var completecount = checklist.length; |
| 1203 |
if (completecount) { |
| 1204 |
$('<div />') |
| 1205 |
.append("選択した" + completecount + "件のカラムを削除しますか?") |
| 1206 |
.dialog({ |
| 1207 |
modal: true, |
| 1208 |
buttons: { |
| 1209 |
'いいえ': function() { |
| 1210 |
$(this).dialog('close'); |
| 1211 |
}, |
| 1212 |
'はい': function() { |
| 1213 |
$(this).dialog('close'); |
| 1214 |
checklist.each(function(i, val) { |
| 1215 |
that.showloading( |
| 1216 |
$.ajax({ |
| 1217 |
url: '/d/column_remove', |
| 1218 |
data: { |
| 1219 |
"table" : that.current_table, |
| 1220 |
"name" : val.value |
| 1221 |
}, |
| 1222 |
dataType: 'json', |
| 1223 |
success: function() { |
| 1224 |
if (!(--completecount)) { |
| 1225 |
that.columnlist(that.current_table); |
| 1226 |
alert('カラムを削除しました。'); |
| 1227 |
} else if (completecount < 0){ |
| 1228 |
that.hideloading(); |
| 1229 |
} |
| 1230 |
}, |
| 1231 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 1232 |
completecount = 0; |
| 1233 |
that.errorloading(XMLHttpRequest); |
| 1234 |
} |
| 1235 |
}) |
| 1236 |
); |
| 1237 |
}); |
| 1238 |
} |
| 1239 |
} |
| 1240 |
}); |
| 1241 |
} |
| 1242 |
}, |
| 1243 |
removetable: function() { |
| 1244 |
var that = this; |
| 1245 |
var checklist = $("#tab-tablelist-table").find("input:checked"); |
| 1246 |
var completecount = checklist.length; |
| 1247 |
if (completecount > 0) { |
| 1248 |
$('<div />') |
| 1249 |
.append("選択した" + completecount + "件のテーブルを削除しますか?") |
| 1250 |
.dialog({ |
| 1251 |
modal: true, |
| 1252 |
buttons: { |
| 1253 |
'いいえ': function() { |
| 1254 |
$(this).dialog('close'); |
| 1255 |
}, |
| 1256 |
'はい': function() { |
| 1257 |
$(this).dialog('close'); |
| 1258 |
checklist.each(function(i, val) { |
| 1259 |
that.showloading( |
| 1260 |
$.ajax({ |
| 1261 |
url: '/d/table_remove', |
| 1262 |
data: { |
| 1263 |
"name" : val.value |
| 1264 |
}, |
| 1265 |
dataType: 'json', |
| 1266 |
success: function() { |
| 1267 |
if (--completecount == 0) { |
| 1268 |
that.tablelist(); |
| 1269 |
that.update_tablelist(); |
| 1270 |
alert('テーブルを削除しました。'); |
| 1271 |
} else if (completecount < 0){ |
| 1272 |
that.hideloading(); |
| 1273 |
} |
| 1274 |
}, |
| 1275 |
error: function(XMLHttpRequest, textStatus, errorThrown) { |
| 1276 |
completecount = 0; |
| 1277 |
that.errorloading(XMLHttpRequest); |
| 1278 |
} |
| 1279 |
}) |
| 1280 |
); |
| 1281 |
}); |
| 1282 |
} |
| 1283 |
} |
| 1284 |
}); |
| 1285 |
} |
| 1286 |
}, |
| 1287 |
showloading: function(obj, hide_dialog) { |
| 1288 |
var that = this; |
| 1289 |
if (obj == null) { return; } |
| 1290 |
this.semaphore[this.semaphore.length] = obj; |
| 1291 |
if ( $("#loadingdialog").length > 0 || hide_dialog) { return; } |
| 1292 |
$("<div />") |
| 1293 |
.attr("id", "loadingdialog") |
| 1294 |
.attr("style", "text-align: center;") |
| 1295 |
.append($("<div />").attr("id", "progressbar")) |
| 1296 |
.append(" Loading...") |
| 1297 |
.dialog({ |
| 1298 |
title: "", |
| 1299 |
width: 200, |
| 1300 |
height: 110, |
| 1301 |
minHeight: 110, |
| 1302 |
modal: true, |
| 1303 |
resizable: false, |
| 1304 |
draggable: false, |
| 1305 |
position: ["right", "bottom"], |
| 1306 |
autoOpen: false, |
| 1307 |
buttons: { |
| 1308 |
'中止': function() { |
| 1309 |
if (obj) { obj.abort(); } |
| 1310 |
that.hideloading(); |
| 1311 |
} |
| 1312 |
} |
| 1313 |
}); |
| 1314 |
$("#loadingdialog").parents(".ui-dialog").children(".ui-dialog-titlebar").remove(); |
| 1315 |
$("#progressbar").progressbar({value: false}); |
| 1316 |
$("#loadingdialog").dialog("open"); |
| 1317 |
$(".ui-widget-overlay").css("opacity", "0.0"); |
| 1318 |
}, |
| 1319 |
hideloading: function() { |
| 1320 |
for (var i = 0; i < this.semaphore.length; i++) { |
| 1321 |
if ( this.semaphore[i].readyState == 4) { |
| 1322 |
this.semaphore.splice(i, 1); |
| 1323 |
i--; |
| 1324 |
} |
| 1325 |
} |
| 1326 |
if ( this.semaphore.length == 0) { |
| 1327 |
$("#loadingdialog").dialog("close"); |
| 1328 |
$("#loadingdialog").remove(); |
| 1329 |
} |
| 1330 |
}, |
| 1331 |
errorloading: function(ajax, hide_dialog) { |
| 1332 |
var that = this; |
| 1333 |
var json = null; |
| 1334 |
if (ajax && ajax.responseText) { |
| 1335 |
json = JSON.parse(ajax.responseText); |
| 1336 |
} |
| 1337 |
this.hideloading(); |
| 1338 |
for (var i = 0; i < this.semaphore.length; i++) { |
| 1339 |
this.semaphore[i].abort(); |
| 1340 |
this.semaphore.splice(i, 1); |
| 1341 |
i--; |
| 1342 |
} |
| 1343 |
if ( $("#loadingdialog").length == 0 && !hide_dialog) { |
| 1344 |
var error_label; |
| 1345 |
var error_message; |
| 1346 |
if (json){ |
| 1347 |
error_label = "groongaでエラーが発生しました。"; |
| 1348 |
error_message = json[0][3] + "(" + json[0][0] + ")"; |
| 1349 |
} else if (ajax) { |
| 1350 |
error_label = "通信エラーが発生しました。"; |
| 1351 |
error_message = "" + ajax.status + ": " + ajax.statusText; |
| 1352 |
} else { |
| 1353 |
error_label = "通信エラーが発生しました。"; |
| 1354 |
error_message = ""; |
| 1355 |
} |
| 1356 |
$("<div />") |
| 1357 |
.append($("<div />").text(error_label)) |
| 1358 |
.append($("<div />").text(error_message)) |
| 1359 |
.attr("id", "loadingdialog") |
| 1360 |
.dialog({ |
| 1361 |
title: "", |
| 1362 |
width: 340, |
| 1363 |
height: 160, |
| 1364 |
minHeight: 160, |
| 1365 |
modal: true, |
| 1366 |
resizable: false, |
| 1367 |
draggable: false, |
| 1368 |
open: function() { |
| 1369 |
$(this).parents(".ui-dialog").children(".ui-dialog-titlebar").remove(); |
| 1370 |
}, |
| 1371 |
buttons: { OK: function() { that.hideloading(); } } |
| 1372 |
}); |
| 1373 |
} |
| 1374 |
}, |
| 1375 |
validateajax: function(d, hide_dialog) { |
| 1376 |
if (!d) { |
| 1377 |
this.errorloading(null, hide_dialog); |
| 1378 |
return -1; |
| 1379 |
} |
| 1380 |
return 0; |
| 1381 |
} |
| 1382 |
}); |