git_sitools_idoc / Module_ProjectTimeline_sitools2 / projectTimeline_byday.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_byday = Ext.extend(Ext.Panel, { |
32 |
layout : "border", |
33 |
|
34 |
initComponent : function () { |
35 |
|
36 |
var myDataView = new Ext.DataView({ |
37 |
id : "line_byday", |
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 |
method : "GET", |
47 |
success : function(response, opts) { |
48 |
var activityList = new Array(); |
49 |
var data= Ext.decode(response.responseText);
|
50 |
var i=0; |
51 |
var nb=15; |
52 |
var selecteddata=null; |
53 |
var actdata=null; |
54 |
Ext.DomHelper.append(Ext.get('line_byday'),"<div id='searchbox'/>"); |
55 |
Ext.DomHelper.append(Ext.get('searchbox'),"<div id='startbox'/>"); |
56 |
Ext.DomHelper.append(Ext.get('startbox')," From <input type='text' id='start'/> "); |
57 |
Ext.DomHelper.append(Ext.get('searchbox'),"<div id='endbox'/>"); |
58 |
Ext.DomHelper.append(Ext.get('endbox')," To <input type='text' id='end'/> "); |
59 |
Ext.DomHelper.append(Ext.get('searchbox')," <button id='search' type='button'> GO </button> "); |
60 |
Ext.DomHelper.append(Ext.get('searchbox'),"<div id='data'/>"); |
61 |
Ext.DomHelper.append(Ext.get('data'),"<button id='all' >Show all the activities</button>"); |
62 |
Ext.DomHelper.append(Ext.get('data'),"<button id='withdata'>Show the activities with data</button>"); |
63 |
Ext.get('all').on("click", function () { |
64 |
var start=document.getElementById('start').value; |
65 |
var end=document.getElementById('end').value; |
66 |
actdata=false;
|
67 |
select(start,end,actdata); |
68 |
}); |
69 |
Ext.get('withdata').on("click", function () { |
70 |
var start=document.getElementById('start').value; |
71 |
var end=document.getElementById('end').value; |
72 |
actdata=true;
|
73 |
select(start,end,actdata); |
74 |
}); |
75 |
Ext.get('search').on("click", function () { |
76 |
var start=document.getElementById('start').value; |
77 |
var end=document.getElementById('end').value; |
78 |
select(start,end); |
79 |
}); |
80 |
|
81 |
i=getactivity(i,nb); |
82 |
sitools.user.modules.timeline.prepareTimeline('line_byday',activityList);
|
83 |
activityList = new Array();
|
84 |
var appendTo = Ext.get('timeline'); |
85 |
Ext.get(Ext.DomHelper.append(appendTo,"<button id='more' type='button'> more </button>"));
|
86 |
var more=Ext.get('more'); |
87 |
more.on("click", function () { |
88 |
if(selecteddata==null){ |
89 |
i=getactivity(i,nb); |
90 |
sitools.user.modules.timeline.addTimeline(activityList); |
91 |
activityList = new Array();
|
92 |
} |
93 |
else {
|
94 |
i=getactivity(i,nb,selecteddata); |
95 |
sitools.user.modules.timeline.addTimeline(activityList); |
96 |
activityList = new Array();
|
97 |
} |
98 |
}); |
99 |
|
100 |
function select(start,end){ |
101 |
var actdata=arguments[2]?arguments[2]:false; |
102 |
var i=0; |
103 |
activityList = new Array();
|
104 |
Ext.get('timeline').remove();
|
105 |
var selecteddata=selectdate(start,end);
|
106 |
i=getactivity(i,nb,selecteddata,actdata); |
107 |
console.log(activityList); |
108 |
sitools.user.modules.timeline.prepareTimeline('line_byday',activityList);
|
109 |
activityList = new Array();
|
110 |
var appendTo = Ext.get('timeline'); |
111 |
Ext.get(Ext.DomHelper.append(appendTo,"<button id='more' type='button'> more </button>"));
|
112 |
more=Ext.get('more');
|
113 |
more.on("click", function () { |
114 |
if(selecteddata==null) { |
115 |
i=getactivity(i,nb); |
116 |
} |
117 |
else {
|
118 |
if(actdata){
|
119 |
i=getactivity(i,nb,selecteddata,actdata); |
120 |
sitools.user.modules.timeline.addTimeline(activityList); |
121 |
activityList = new Array();
|
122 |
}else{
|
123 |
i=getactivity(i,nb,selecteddata); |
124 |
sitools.user.modules.timeline.addTimeline(activityList); |
125 |
activityList = new Array();
|
126 |
} |
127 |
} |
128 |
}); |
129 |
} |
130 |
function getactivity(i,nb){ |
131 |
var selected=arguments[2]?arguments[2]:data.timeline; |
132 |
var actdata=arguments[3]?arguments[3]:false; |
133 |
var count=0; |
134 |
while(selected[i]){
|
135 |
if((selected[i].data&&actdata)||!actdata){
|
136 |
var activity=new sitools.user.modules.timeline.createActivity(selected[i]); |
137 |
if(activityList[0]){ |
138 |
if(activity.getDayCount()!=activityList[activityList.length-1].getDayCount()){ |
139 |
if(count==nb-1){ |
140 |
return i;
|
141 |
}else{
|
142 |
activityList.push(activity); |
143 |
i++; |
144 |
count++; |
145 |
} |
146 |
}else{
|
147 |
activityList.push(activity); |
148 |
i++; |
149 |
} |
150 |
}else{
|
151 |
activityList.push(activity); |
152 |
i++; |
153 |
} |
154 |
}else{
|
155 |
i++; |
156 |
} |
157 |
} |
158 |
return i;
|
159 |
} |
160 |
|
161 |
function selectdate(startdate,enddate){ |
162 |
var start=null; |
163 |
var end=null; |
164 |
if(startdate==''&&enddate==''){ |
165 |
return data.timeline;
|
166 |
} |
167 |
for(var n=0;n<data.timeline.length;n++){ |
168 |
if(start!=null&&end!=null) {break;} |
169 |
if(data.timeline[n].date>=startdate){
|
170 |
if(n==0){ |
171 |
start=n; |
172 |
}else{
|
173 |
if(data.timeline[n-1].date<startdate) |
174 |
start=n; |
175 |
} |
176 |
} |
177 |
if(data.timeline[n].date<=enddate){
|
178 |
if(n==data.timeline.length-1){ |
179 |
end=n; |
180 |
}else{
|
181 |
if(data.timeline[n+1].date>enddate){ |
182 |
end=n; |
183 |
} |
184 |
} |
185 |
} |
186 |
} |
187 |
if(start==null||end==null){ |
188 |
alert('Wrong date!');
|
189 |
return data.timeline;
|
190 |
} |
191 |
if(start>end){
|
192 |
alert('Wrong date!');
|
193 |
return data.timeline;
|
194 |
} |
195 |
//console.log(data.timeline.slice(start,end+1));
|
196 |
return data.timeline.slice(start,end+1); |
197 |
|
198 |
} |
199 |
} , |
200 |
failure : function(response, opts) { |
201 |
alert("Error while loading data : "+response.responseText);
|
202 |
} |
203 |
}); |
204 |
|
205 |
sitools.user.modules.projectTimeline_byday.superclass.initComponent.call(this);
|
206 |
}, |
207 |
|
208 |
afterRender : function () { |
209 |
sitools.user.modules.projectTimeline_byday.superclass.afterRender.apply(this, arguments); |
210 |
|
211 |
}, |
212 |
/**
|
213 |
* method called when trying to save preference
|
214 |
* @returns
|
215 |
*/
|
216 |
_getSettings : function () { |
217 |
return {
|
218 |
preferencesPath : "/modules", |
219 |
preferencesFileName : this.id |
220 |
}; |
221 |
|
222 |
} |
223 |
|
224 |
}); |
225 |
Ext.reg('sitools.user.modules.projectTimeline_byday', sitools.user.modules.projectTimeline_byday);
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|