git_sitools_idoc / Module_ProjectTimeline_sitools2 / projectTimeline.js @ 20ff13ec
1 |
/***************************************
|
---|---|
2 |
* Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
|
3 |
*
|
4 |
* This file is part of SITools2.
|
5 |
*
|
6 |
* SITools2 is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* SITools2 is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with SITools2. If not, see <http://www.gnu.org/licenses/>.
|
18 |
***************************************/
|
19 |
/*global Ext, sitools, projectGlobal, commonTreeUtils, showResponse, document, i18n, loadUrl, SITOOLS_DEFAULT_PROJECT_IMAGE_URL, SitoolsDesk*/
|
20 |
/*
|
21 |
* @include "../../env.js"
|
22 |
*/
|
23 |
Ext.namespace('sitools.user.modules');
|
24 |
|
25 |
/**
|
26 |
* Dataset Explorer Module.
|
27 |
* Displays each dataset of the Project.
|
28 |
* @class sitools.user.modules.datasetExplorerDataView
|
29 |
* @extends Ext.tree.TreePanel
|
30 |
*/
|
31 |
sitools.user.modules.projectTimeline = Ext.extend(Ext.Panel, { |
32 |
layout : "border", |
33 |
|
34 |
initComponent : function () { |
35 |
|
36 |
var myDataView = new Ext.DataView({ |
37 |
id : "line", |
38 |
region : 'center', |
39 |
singleSelect : true, |
40 |
autoScroll : true, |
41 |
}); |
42 |
this.items = [myDataView];
|
43 |
var projectAttachment = projectGlobal.sitoolsAttachementForUsers;
|
44 |
Ext.Ajax.request( { |
45 |
//url : '../js/modules/projectTimeline/timeline_picard.json',
|
46 |
url: "/sitools/upload/timeline_picard.json", |
47 |
method : "GET", |
48 |
success : function(response, opts) { |
49 |
var activityList = new Array(); |
50 |
var weekList=new Array(); |
51 |
var data= Ext.decode(response.responseText);
|
52 |
var i=0; |
53 |
var nb=15; |
54 |
var nbweek=30; |
55 |
var selecteddata=null; |
56 |
var actdata=null; |
57 |
Ext.DomHelper.append(Ext.get('line'),"<div id='searchbox'/>"); |
58 |
Ext.DomHelper.append(Ext.get('searchbox'),"<div id='startbox'/>"); |
59 |
Ext.DomHelper.append(Ext.get('startbox')," From <input type='text' id='start' placeholder='first day: 2010/10/01'/> "); |
60 |
Ext.DomHelper.append(Ext.get('searchbox'),"<div id='endbox'/>"); |
61 |
Ext.DomHelper.append(Ext.get('endbox')," To <input type='text' id='end' placeholder='last day: 2014/03/06'/> "); |
62 |
Ext.DomHelper.append(Ext.get('searchbox')," <button id='search' type='button'> GO </button> "); |
63 |
/*Ext.DomHelper.append(Ext.get('searchbox'),"<div id='data'/>");
|
64 |
Ext.DomHelper.append(Ext.get('data'),"<button id='all' >Show all the activities</button>");
|
65 |
Ext.DomHelper.append(Ext.get('data'),"<button id='withdata'>Show the activities with data</button>");
|
66 |
Ext.get('all').on("click", function () {
|
67 |
var start=document.getElementById('start').value;
|
68 |
var end=document.getElementById('end').value;
|
69 |
actdata=false;
|
70 |
select(start,end,actdata);
|
71 |
});
|
72 |
Ext.get('withdata').on("click", function () {
|
73 |
var start=document.getElementById('start').value;
|
74 |
var end=document.getElementById('end').value;
|
75 |
actdata=true;
|
76 |
select(start,end,actdata);
|
77 |
});*/
|
78 |
Ext.get('search').on("click", function () { |
79 |
var start=document.getElementById('start').value; |
80 |
var end=document.getElementById('end').value; |
81 |
select(start,end); |
82 |
}); |
83 |
i=getweeks(i,nbweek); |
84 |
//console.log(weekList);
|
85 |
sitools.user.modules.weekTimeline.prepareWeekTimeline('line',weekList);
|
86 |
weekList=new Array();
|
87 |
var appendTo = Ext.get('timeline'); |
88 |
Ext.get(Ext.DomHelper.append(appendTo,"<button id='more' type='button'> more </button>"));
|
89 |
var more=Ext.get('more'); |
90 |
more.on("click", function () { |
91 |
if(selecteddata==null){ |
92 |
i=getweeks(i,nbweek); |
93 |
sitools.user.modules.weekTimeline.addWeekTimeline(weekList); |
94 |
weekList=new Array();
|
95 |
} |
96 |
else {
|
97 |
i=getweeks(i,nbweek,selecteddata); |
98 |
sitools.user.modules.weekTimeline.addWeekTimeline(weekList); |
99 |
weekList=new Array();
|
100 |
} |
101 |
}); |
102 |
function getweeks(i,nbweek){ |
103 |
var selected=arguments[2]?arguments[2]:data.timeline; |
104 |
var actdata=arguments[3]?arguments[3]:false; |
105 |
var count=0; |
106 |
var list=new Array(); |
107 |
var monday=0.0; |
108 |
while(selected[i]){
|
109 |
if(count==nbweek){
|
110 |
return i;
|
111 |
} |
112 |
else{
|
113 |
if(list.length==0){ |
114 |
monday=getMonday(selected[i]); |
115 |
} |
116 |
while(selected[i]&&selected[i].daynum-monday<7.0){ |
117 |
list.push(selected[i]); |
118 |
i++; |
119 |
} |
120 |
//console.log(list);
|
121 |
var week=new sitools.user.modules.weekTimeline.createWeek(list); |
122 |
list=new Array();
|
123 |
weekList.push(week); |
124 |
if(selected[i]){
|
125 |
monday=getMonday(selected[i]); |
126 |
} |
127 |
count++; |
128 |
} |
129 |
} |
130 |
} |
131 |
function getMonday(day){ |
132 |
var monday=0.0; |
133 |
|
134 |
switch(day.day){
|
135 |
case "Monday": |
136 |
monday=day.daynum; |
137 |
break;
|
138 |
case "Tuesday": |
139 |
monday=day.daynum-1.0;
|
140 |
break;
|
141 |
case "Wednesday": |
142 |
monday=day.daynum-2.0;
|
143 |
break;
|
144 |
case "Thursday": |
145 |
monday=day.daynum-3.0;
|
146 |
break;
|
147 |
case "Friday": |
148 |
monday=day.daynum-4.0;
|
149 |
break;
|
150 |
case "Saturday": |
151 |
monday=day.daynum-5.0;
|
152 |
break;
|
153 |
case "Sunday": |
154 |
monday=day.daynum-6.0;
|
155 |
break;
|
156 |
} |
157 |
return monday;
|
158 |
} |
159 |
function select(start,end){ |
160 |
var actdata=arguments[2]?arguments[2]:false; |
161 |
var i=0; |
162 |
activityList = new Array();
|
163 |
Ext.get('timeline').remove();
|
164 |
var selecteddata=selectdate(start,end);
|
165 |
i=getweeks(i,nbweek,selecteddata,actdata); |
166 |
//console.log(weekList);
|
167 |
sitools.user.modules.weekTimeline.prepareWeekTimeline('line',weekList);
|
168 |
weekList=new Array();
|
169 |
var appendTo = Ext.get('timeline'); |
170 |
Ext.get(Ext.DomHelper.append(appendTo,"<button id='more' type='button'> more </button>"));
|
171 |
more=Ext.get('more');
|
172 |
more.on("click", function () { |
173 |
if(selecteddata==null) { |
174 |
i=getweeks(i,nbweek); |
175 |
} |
176 |
else {
|
177 |
if(actdata){
|
178 |
//i=getactivity(i,nb,selecteddata,actdata);
|
179 |
//sitools.user.modules.timeline.addTimeline(activityList);
|
180 |
//activityList = new Array();
|
181 |
}else{
|
182 |
i=getweeks(i,nbweek,selecteddata); |
183 |
sitools.user.modules.weekTimeline.addWeekTimeline(weekList); |
184 |
weekList=new Array();
|
185 |
} |
186 |
} |
187 |
}); |
188 |
} |
189 |
function checkDate(d){ |
190 |
var dateArray = d.split('/'); |
191 |
if(dateArray.length!=3) return false; |
192 |
var date = new Date(parseInt(dateArray[0]),parseInt(dateArray[1]-1),parseInt(dateArray[2])); |
193 |
if ( Object.prototype.toString.call(date) !== "[object Date]" ) |
194 |
return false; |
195 |
else return true; |
196 |
} |
197 |
|
198 |
function selectdate(startdate,enddate){ |
199 |
var start=null; |
200 |
var end=null; |
201 |
if(startdate==''&&enddate==''){ |
202 |
return data.timeline;
|
203 |
} |
204 |
if(startdate==''){ |
205 |
start = 0;
|
206 |
}else{
|
207 |
if(!checkDate(startdate)){
|
208 |
alert('Wrong date for date begin!');
|
209 |
return data.timeline;
|
210 |
} |
211 |
} |
212 |
if(enddate==''){ |
213 |
end = data.timeline.length-1;
|
214 |
}else{
|
215 |
if(!checkDate(enddate)){
|
216 |
alert('Wrong date for date end!');
|
217 |
return data.timeline;
|
218 |
} |
219 |
} |
220 |
for(var n=0;n<data.timeline.length;n++){ |
221 |
if(start!=null&&end!=null) {break;} |
222 |
if(start==null){ |
223 |
if(data.timeline[n].date>=startdate){
|
224 |
if(n==0){ |
225 |
start=n; |
226 |
}else{
|
227 |
if(data.timeline[n-1].date<startdate) |
228 |
start=n; |
229 |
} |
230 |
}} |
231 |
if(end==null){ |
232 |
if(data.timeline[n].date<=enddate){
|
233 |
if(n==data.timeline.length-1){ |
234 |
end=n; |
235 |
}else{
|
236 |
if(data.timeline[n+1].date>enddate){ |
237 |
end=n; |
238 |
} |
239 |
} |
240 |
}} |
241 |
} |
242 |
if(start==null||end==null){ |
243 |
alert('Wrong date!');
|
244 |
return data.timeline;
|
245 |
} |
246 |
if(start>end){
|
247 |
alert('Wrong date!');
|
248 |
return data.timeline;
|
249 |
} |
250 |
//console.log(data.timeline.slice(start,end+1));
|
251 |
return data.timeline.slice(start,end+1); |
252 |
|
253 |
} |
254 |
} , |
255 |
failure : function(response, opts) { |
256 |
alert("Error while loading data : "+response.responseText);
|
257 |
} |
258 |
}); |
259 |
|
260 |
sitools.user.modules.projectTimeline.superclass.initComponent.call(this);
|
261 |
}, |
262 |
|
263 |
afterRender : function () { |
264 |
sitools.user.modules.projectTimeline.superclass.afterRender.apply(this, arguments); |
265 |
|
266 |
}, |
267 |
/**
|
268 |
* method called when trying to save preference
|
269 |
* @returns
|
270 |
*/
|
271 |
_getSettings : function () { |
272 |
return {
|
273 |
preferencesPath : "/modules", |
274 |
preferencesFileName : this.id |
275 |
}; |
276 |
|
277 |
} |
278 |
|
279 |
}); |
280 |
Ext.reg('sitools.user.modules.projectTimeline', sitools.user.modules.projectTimeline);
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|