treeview.html
4.66 KB
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
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Treeview Example</title>
<link rel="stylesheet" href="../assets/css/bootstrap.css" />
<link rel="stylesheet" href="../assets/css/font-awesome.css" />
<!-- fonts -->
<link rel="stylesheet" href="../assets/css/ace-fonts.css" />
<link rel="stylesheet" href="../assets/css/ace.css" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="../assets/css/ace-ie.css" />
<![endif]-->
</head>
<body>
<div class="main-container">
<div class="page-content">
<div class="row">
<div class="center" style="width:400px; margin:12px;">
<div class="widget-box align-left transparent">
<div class="widget-header">
<h4 class="lighter smaller">Tree element loading data from server <br /> pre-selecting some items randomly</h4>
</div>
<div class="widget-body">
<div class="widget-main padding-8">
<div id="treeview" class="tree"></div>
<div class="hr"></div>
<button id="submit-button" type="button" class="btn btn-sm btn-primary pull-right">
<i class="ace-icon fa fa-check"></i>
Submit
</button>
</div>
</div>
</div>
</div>
</div>
<div id="modal-tree-items" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="blue bigger">Treeview selection</h4>
</div>
<div class="modal-body">
<div class="row-fluid">
Content can be put inside a hidden input and sent to server
</div>
<div class="space-6"></div>
<div class="row-fluid">
<textarea spellcheck="false" id="tree-value"></textarea>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> Cancel</button>
<button class="btn btn-sm btn-primary"><i class="ace-icon fa fa-check"></i> OK</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- basic scripts -->
<!--[if !IE]> -->
<script type="text/javascript">
window.jQuery || document.write("<script src='../assets/js/jquery.js'>"+"<"+"/script>");
</script>
<!-- <![endif]-->
<!--[if IE]>
<script type="text/javascript">
window.jQuery || document.write("<script src='../assets/js/jquery-1.10.2.js'>"+"<"+"/script>");
</script>
<![endif]-->
<script src="../assets/js/bootstrap.js"></script>
<script src="../assets/js/fuelux/fuelux.tree.js"></script>
<!-- ace scripts -->
<script src="../assets/js/ace-elements.js"></script>
<script src="../assets/js/ace.js"></script>
<script type="text/javascript">
$(function() {
//construct the data source object to be used by tree
var remoteUrl = 'treeview.php';
var remoteDateSource = function(options, callback) {
var parent_id = null
if( !('text' in options || 'type' in options) ){
parent_id = 0;//load first level data
}
else if('type' in options && options['type'] == 'folder') {//it has children
if('additionalParameters' in options && 'children' in options.additionalParameters)
parent_id = options.additionalParameters['id']
}
if(parent_id !== null) {
$.ajax({
url: remoteUrl,
data: 'id='+parent_id,
type: 'POST',
dataType: 'json',
success : function(response) {
if(response.status == "OK")
callback({ data: response.data })
},
error: function(response) {
//console.log(response);
}
})
}
}
$('#treeview').ace_tree({
dataSource: remoteDateSource ,
multiSelect: true,
loadingHTML: '<div class="tree-loading"><i class="ace-icon fa fa-refresh fa-spin blue"></i></div>',
'open-icon' : 'ace-icon tree-minus',
'close-icon' : 'ace-icon tree-plus',
'selectable' : true,
'selected-icon' : 'ace-icon fa fa-check',
'unselected-icon' : 'ace-icon fa fa-times',
cacheItems: true,
folderSelect: false
});
//show selected items inside a modal
$('#submit-button').on('click', function() {
var output = '';
var items = $('#treeview').tree('selectedItems');
for(var i in items) if (items.hasOwnProperty(i)) {
var item = items[i];
output += item.additionalParameters['id'] + ":"+ item.text+"\n";
}
$('#modal-tree-items').modal('show');
$('#tree-value').css({'width':'98%', 'height':'200px'}).val(output);
});
if(location.protocol == 'file:') alert("For retrieving data from server, you should access this page using a webserver.");
});
</script>
</body>
</html>