This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
/
browse.selectitem.js
157 lines (133 loc) · 4.94 KB
/
browse.selectitem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
/* global itemSelectionCallback */
/* global sliceFileName */
/* global trimName */
$("#moveTable").treeTable({
pageLength: 99999
});
$("img.tableLoading").hide();
$("table#moveTable").show();
$('.uploadApplet').hide();
if ($('#selectElements') !== undefined) {
$('#selectElements').click(function () {
'use strict';
$('#destinationUpload').html($('#selectedDestination').html());
$('#destinationId').val($('#selectedDestinationHidden').val());
$('.destinationUpload').html($('#selectedDestination').html());
$('.destinationId').val($('#selectedDestinationHidden').val());
$("div.MainDialog").dialog('close');
$('.uploadApplet').show();
if (typeof itemSelectionCallback == 'function') {
itemSelectionCallback($('#selectedDestination').html(), $('#selectedDestinationHidden').val());
}
return false;
});
}
// dependence: common/browser.js
var ajaxSelectRequest = '';
function callbackSelect(node) {
'use strict';
if (node.attr('type') == 'item') {
var selectedElement = node.find('span:eq(0)').html();
$('#selectedDestinationHidden').val(node.attr('element'));
$('#selectedDestination').html(sliceFileName(selectedElement, 40));
$('#selectElements').removeAttr('disabled');
}
}
$('img.infoLoading').show();
$('div.ajaxInfoElement').html('');
function callbackDblClick(node) {
'use strict';
// genericCallbackDblClick(node);
}
function callbackCheckboxes(node) {
'use strict';
// genericCallbackCheckboxes(node);
}
function callbackCustomElements(node, elements, first) {
'use strict';
var i = 1;
var id = node.attr('id');
elements['folders'] = $.makeArray(elements['folders']);
var padding = parseInt(node.find('td:first').css('padding-left').slice(0, -2));
var html = '';
$.each(elements['folders'], function (index, value) {
html += "<tr id='" + id + "-" + i + "' class='parent child-of-" + id + "' ajax='" + value['folder_id'] + "'type='folder' policy='" + value['policy'] + "' element='" + value['folder_id'] + "'>";
html += " <td><span class='folder'>" + trimName(value['name'], padding) + "</span></td>";
html += "</tr>";
i++;
});
$.each(elements['items'], function (index, value) {
html += "<tr id='" + id + "-" + i + "' class='child-of-" + id + "' privacy='" + value['privacy_status'] + "' type='item' policy='" + value['policy'] + "' element='" + value['item_id'] + "'>";
html += " <td><span class='file'>" + trimName(value['name'], padding) + "</span></td>";
html += "</tr>";
i++;
});
return html;
}
// Live search
$.widget("custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function (ul, items) {
'use strict';
var self = this,
currentCategory = "";
$.each(items, function (index, item) {
if (item.category != currentCategory) {
ul.append('<li class="search-category">' + item.category + "</li>");
currentCategory = item.category;
}
self._renderItemData(ul, item);
});
}
});
var cacheSearchSelectItem = {},
lastXhr;
$("#live_search_item").catcomplete({
minLength: 2,
delay: 10,
source: function (request, response) {
'use strict';
var term = request.term;
if (term in cacheSearchSelectItem) {
response(cacheSearchSelectItem[term]);
return;
}
$("#searchloadingSelectItem").show();
lastXhr = $.getJSON($('.webroot').val() + "/search/live?itemSearch=true", request, function (data, status, xhr) {
$("#searchloadingSelectItem").hide();
cacheSearchSelectItem[term] = data;
if (xhr === lastXhr) {
itemselected = false;
response(data);
}
});
}, // end source
select: function (event, ui) {
'use strict';
itemselected = true;
$('#selectedDestinationHidden').val(ui.item.itemid);
$('#selectedDestination').html(ui.item.value);
$('#selectElements').removeAttr('disabled');
}
});
$('#live_search_item').focus(function () {
'use strict';
if ($('#live_search_item_value').val() == 'init') {
$('#live_search_item_value').val($('#live_search_item').val());
$('#live_search_item').val('');
}
});
$('#live_search_item').focusout(function () {
'use strict';
if ($('#live_search_item').val() == '') {
$('#live_search_item').val($('#live_search_item_value').val());
$('#live_search_item_value').val('init');
}
});
$('#live_search_item').keyup(function (e) {
'use strict';
if (e.keyCode == 13 && !itemselected) // enter key has been pressed
{
window.location = $('.webroot').val() + '/search/' + encodeURIComponent($('#live_search_item').val());
}
});