-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
233 lines (207 loc) · 7.59 KB
/
index.html
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<link rel="stylesheet" media="screen" href="fw/omnigrid/omnigrid.css" type="text/css">
<script type="text/javascript" src="fw/mootools/mootools-core-1.6.0.js"></script>
<script type="text/javascript" src="fw/mootools/mootools-more-1.6.0.js"></script>
<script type="text/javascript" src="fw/omnigrid/omnigrid.js"></script>
<script type="text/javascript">
//@Class NickDetailsProvier
function NickDetailsProvider(strDetail)
{
this.detail = JSON.parse(strDetail);
//dataProvider method - suppose details was pre-build in php side
this.loadData = function(param)
{
//first version ignore omnigrid parameter (page, pagination, sorty..)
return this.detail;
}
}
function onGridSelect(evt)
{
var str = 'row: '+evt.row+' indices: '+evt.indices;
/*
str += ' id: '+evt.target.getDataByRow(evt.row).id;
evt.target.editable = true;
alert( str );
*/
}
//at omnigrid.js this.options.accordionRenderer({parent:li2, row:r, grid:this, rowdata: rowdata});
function accordionFcn(data)
{
var detailProvider = new NickDetailsProvider(data.rowdata.detail);
var n_contacts = detailProvider.detail.data.length;
var li;
var iDiv;
var cmu = [
{
header: "Kind",
dataIndex: 'kind',
dataType:'string',
width:'100',
editable:true
},
{
header: "Contact",
dataIndex: 'contact',
dataType:'string',
width:'200',
editable:true
}];
iDiv = document.createElement('div');
iDiv.id = 'griddetail-' + data.rowdata.nick;
data.parent.appendChild(iDiv);
detailgrid = new omniGrid(iDiv.id,
{
columnModel: cmu,
// buttons : [
// {name: 'Add', bclass: 'add', onclick : gridButtonClick},
// {name: 'Delete', bclass: 'delete', onclick : gridButtonClick}
// ],
// url:"api/Namesbook.php",
// dataProvider: detailProvider,
perPageOptions: [10,20,50,100,200],
perPage:10,
page:1,
editable:true,
editondblclick:true,
pagination:false,
serverSort:true,
showHeader: data.row==0,
alternaterows: false,
sortHeader:false,
resizeColumns:true,
selectable:false,
multipleSelection:false,
accordion:false,
autoSectionToggle:false,
openAccordionOnDblClick:false,
showtoggleicon:false,
width:'100%',
height:'100%'
});
detailgrid.setOptions(detailgrid.getDefaultOptions(),
{
perPageOptions: [10,20,50,100,200],
perPage:10,
page:1,
editable:true,
editondblclick:true,
pagination:false,
serverSort:true,
showHeader: false,
alternaterows: false,
sortHeader:data.row==0,
resizeColumns:true,
selectable:false,
multipleSelection:false,
accordion:false,
autoSectionToggle:false,
openAccordionOnDblClick:false,
showtoggleicon:false,
width:'100%',
height:'100%'
});
detailgrid.setData(detailProvider.detail);
n_contacts += data.row==0 ? 3 : 1;
n_contacts *= 20;
data.parent.style.height = n_contacts + "px";
}
// function gridButtonClick(button, grid)
function gridButtonClick(evt)
{
//alert(evt.target.className);
if (!datagrid.options.url)
return;
var param = {namesBookAction: evt.target.className};
switch(evt.target.className) {
case 'add':
param.newNickname = 'test04'; //datagrid.selected.data.rowdata.nick;
param.newEmail = 'email-test4'; //datagrid.selected.data.rowdata.email;
param.firstName = 'test04'; //datagrid.selected.data.rowdata.nick;
param.middleName = 't04'; //datagrid.selected.data.rowdata.email;
param.lastName = 'html'; //datagrid.selected.data.rowdata.nick;
param.detail = ''; //datagrid.selected.data.rowdata.email;
break;
case 'edit':
param.oldEmail = datagrid.selected.data.rowdata.email;
param.newNickname = datagrid.selected.data.rowdata.nick;
break;
case 'delete':
param.oldEmail = 'email-test4'; //datagrid.selected.data.rowdata.email;
break;
}
//datagrid.showLoader();
var url = datagrid.options.url;
var request = new Request.JSON({ url: url, data: param, onSuccess: function(actionResult){
datagrid.hideLoader();
if(actionResult)
datagrid.refresh();
}});
request.addEvent("complete", function(){ datagrid.container.getElement('.bDiv').scrollTop = 0}.bind(datagrid) ) ; request.addEvent("complete", datagrid.onLoadData.bind(datagrid) ) ; request.get();
datagrid.refresh();
}
var cmu = [
{
header: "Nick",
dataIndex: 'nick',
dataType:'string',
editable:true
},
{
header: "email",
dataIndex: 'email',
dataType:'string',
width:200
}];
window.addEvent("domready", function()
{
datagrid = new omniGrid('mygrid', {
columnModel: cmu,
buttons : [
{name: 'Add', bclass: 'add', onclick : gridButtonClick},
{name: 'Delete', bclass: 'delete', onclick : gridButtonClick},
{separator: true},
{name: 'Edit', bclass: 'edit', onclick : gridButtonClick}
],
url:"api/Namesbook.php",
perPageOptions: [10,20,50,100,200],
perPage:10,
page:1,
editable:true,
editondblclick:true,
pagination:true,
serverSort:true,
showHeader: true,
// alternaterows: true,
sortHeader:false,
resizeColumns:true,
// multipleSelection:true,
multipleSelection:false,
accordion:true,
accordionRenderer:accordionFcn,
autoSectionToggle:true,
openAccordionOnDblClick:false,
showtoggleicon:true,
width:600,
height: 400
});
datagrid.addEvent('click', onGridSelect);
var bt = document.getElementsByClassName("add");
if(bt) bt[0].addEventListener('click', gridButtonClick);
bt = document.getElementsByClassName("delete");
if(bt) bt[0].addEventListener('click', gridButtonClick);
bt = document.getElementsByClassName("edit");
if(bt) bt[0].addEventListener('click', gridButtonClick);
});
</script>
<div id="mygrid" ></div>
</body>
</html>