Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.14 KB | None | 0 0
  1. <apex:page controller="GanttChartController" sidebar="false" id="thePage" docType="html-5.0">
  2.  
  3. <apex:includeScript id="a" value="https://www.google.com/jsapi" />
  4. <apex:includeScript value="{!$Resource.GanttChart}"/>
  5. <apex:includeScript value="{!URLFOR($Resource.GanttChart, '/timeline.js')}" />
  6. <apex:stylesheet value="{!URLFOR($Resource.GanttChart, '/timeline.css')}" />
  7.  
  8. <script type="text/javascript">
  9.  
  10. google.load("visualization", "1");
  11.  
  12. // Set callback to run when API is loaded
  13. google.setOnLoadCallback(drawVisualization);
  14.  
  15. var timeline ;
  16.  
  17. // Called when the Visualization API is loaded.
  18. function drawVisualization() {
  19.  
  20. // specify options
  21. var cenas = {!tableOptions};
  22. var options = [];
  23. options.push(cenas);
  24.  
  25. var cenascenas = {!jsonTabela};
  26. var data = [];
  27. data.push(cenascenas);
  28.  
  29.  
  30. // Instantiate our timeline object.
  31. timeline = new links.Timeline(document.getElementById('mytimeline'));
  32.  
  33.  
  34. //Event Functions
  35. // Make a callback function for the select event
  36. var onselect = function (event) {
  37. var row = undefined;
  38. var sel = timeline.getSelection();
  39. if (sel.length) {
  40. if (sel[0].row != undefined) {
  41. var row = sel[0].row;
  42. }
  43. }
  44.  
  45. if (row != undefined) {
  46. var content = data.getValue(row, 2);
  47. document.getElementById("txtContent").value = content;
  48.  
  49. //INSERT AJAX HERE!
  50. //alert("cenas1");
  51. //document.getElementById("info").innerHTML += "event " + row + " selected<br>";
  52.  
  53. }
  54. };
  55.  
  56. // callback function for the change event
  57. var onchange = function () {
  58. var sel = timeline.getSelection();
  59. if (sel.length) {
  60. if (sel[0].row != undefined) {
  61. var row = sel[0].row;
  62.  
  63. //INSERT AJAX HERE!
  64. //alert("cenas2");
  65. //document.getElementById("info").innerHTML += "event " + row + " changed<br>";
  66. }
  67. }
  68. };
  69.  
  70.  
  71. // Draw our timeline with the created data and options
  72. timeline.setOptions(cenas);
  73. timeline.draw(cenascenas);
  74.  
  75. google.visualization.events.addListener(timeline, 'select', onselect);
  76. google.visualization.events.addListener(timeline, 'change', onchange);
  77.  
  78. var newStartDate = dateFormat({!dataInicioJson});
  79. var newEndDate = dateFormat({!dataFimJson});
  80. timeline.setVisibleChartRange(newStartDate, newEndDate, true);
  81.  
  82. }
  83.  
  84. function updateChart(paramOne){
  85.  
  86. var optionsTmp = {!tableOptions};
  87. var options = [];
  88. options.push(optionsTmp);
  89.  
  90. var dataTmp = [{ "start" : new Date(2015,01,16,00,00,01), "end" : new Date(2015,01,28,23,59,59), "content" : "Sprint 4", "group" : "Sprint3" }];
  91. //var dataTmp = paramOne;
  92. var data = [];
  93. data.push(dataTmp);
  94.  
  95. alert(data + '');
  96.  
  97. timeline = new links.Timeline(document.getElementById('mytimeline'));
  98.  
  99. var newStartDate = dateFormat({!dataInicioJson});
  100. var newEndDate = dateFormat({!dataFimJson});
  101.  
  102. //timeline.setData(data);
  103. //timeline.setVisibleChartRange(newStartDate, newEndDate, true);
  104.  
  105. //timeline.setOptions(options);
  106. //timeline.redraw();
  107. document.getElementById('mytimeline') = timeline;
  108.  
  109. //actualizarTextojs();
  110. }
  111.  
  112. // Format given date as "yyyy-mm-dd hh:ii:ss"
  113. // @param datetime A Date object.
  114. function dateFormat(date) {
  115. var datetime = date.getFullYear() + "-" +
  116. ((date.getMonth() < 9) ? "0" : "") + (date.getMonth()) + "-" +
  117. ((date.getDate() < 10) ? "0" : "") + date.getDate() + " " +
  118. ((date.getHours() < 10) ? "0" : "") + date.getHours() + ":" +
  119. ((date.getMinutes() < 10) ? "0" : "") + date.getMinutes() + ":" +
  120. ((date.getSeconds() < 10) ? "0" : "") + date.getSeconds();
  121. return datetime;
  122. }
  123.  
  124. function setTime() {
  125. if (!timeline) return;
  126.  
  127. var newStartDate = new Date(document.getElementById('startDate').value);
  128. var newEndDate = new Date(document.getElementById('endDate').value);
  129. timeline.setVisibleChartRange(newStartDate, newEndDate);
  130. }
  131. </script>
  132.  
  133. <apex:form >
  134.  
  135. <apex:actionFunction name="actualizarTextojs" reRender="timelinePanel" />
  136.  
  137. <apex:actionFunction name="activatePopupOne" reRender="popupOneId" >
  138. <apex:param name="idPopup" value=""/>
  139. </apex:actionFunction>
  140. <apex:pageBlock >
  141. <apex:pageBlockSection title="Filtros" columns="1">
  142. <apex:commandButton value="Update" action="{!configureTableOptions}" oncomplete="updateChart('{!jsonTabela}');"/>
  143.  
  144. </apex:pageBlockSection>
  145. </apex:pageBlock>
  146.  
  147. <apex:pageBlock >
  148. <apex:outputPanel id="timelinePanel" >
  149. <div id="mytimeline">
  150. </div>
  151. <apex:outputText value="{!jsonTabela}" />
  152. </apex:outputPanel>
  153. </apex:pageBlock>
  154.  
  155. </apex:form>
  156.  
  157. public with sharing class GanttChartController {
  158.  
  159. public String jsonTabela {get; set;}
  160. public String tableOptions {get; set;}
  161.  
  162. private map<String, Sprint__c> mapIdESprint;
  163. public list<String> lstSprintSelecionados {get; set;}
  164. public list<SelectOption> lstSprintPicklist {get; set;}
  165.  
  166. private static String queryBaseSprint = 'SELECT Data_fim__c,Data_inicio__c,Grupo_Sprint__c,Id,Name,Observacoes__c,OwnerId,Status__c,Total_Balance__c,Total_Points__c,Total_Remaining_Availability__c,Total_Remaining__c,Total_Resource_Availability__c,Total_Spent__c FROM Sprint__c';
  167.  
  168.  
  169. public GanttChartController() {
  170.  
  171. //Sprints
  172. list<Sprint__c> lstSprintsAux = Database.query(queryBaseSprint + ' ORDER BY Name ASC NULLS LAST');
  173. mapIdESprint = new map<String, Sprint__c>();
  174. lstSprintSelecionados = new list<String>();
  175. lstSprintSelecionados.add('all');
  176. lstSprintPicklist = new list<SelectOption>();
  177. lstSprintPicklist.add(new SelectOption('all','All'));
  178. for(Sprint__c sprintAux : lstSprintsAux){
  179. mapIdESprint.put(sprintAux.Id, sprintAux);
  180. lstSprintPicklist.add(new SelectOption(sprintAux.Id,sprintAux.Name));
  181. }
  182.  
  183. configureTableOptions();
  184.  
  185.  
  186. }
  187.  
  188. public void configureTableOptions(){
  189.  
  190. tableOptions = '{ "width": "99%", "editable": true, "layout": "box", "stackEvents" : false, "groupsOrder" : false, "axisOnTop" : true}';
  191.  
  192. jsonTabela = '[' ;
  193.  
  194. //Inserir o sprint
  195. String jasonSprints = '';
  196. if(lstSprintSelecionados != null && !lstSprintSelecionados.isEmpty()){
  197. System.debug(lstSprintSelecionados);
  198. if(lstSprintSelecionados.get(0) == 'all'){
  199. //jsonTabela += ',';
  200. for(Sprint__c sprintAux : mapIdESprint.Values()){
  201. String content = ' <button > ' + sprintAux.Name + ' </button>';
  202.  
  203.  
  204. jasonSprints += '{ "start" : new Date('+ this.convertDate(sprintAux.Data_inicio__c) + ',00,00,01), "end" : new Date(' + this.convertDate(sprintAux.Data_fim__c) + ',23,59,59), "content" : "' + content + '", "group" : "Sprint" , "editable" : false },';
  205. }
  206. }else{
  207. Sprint__c sprintTmp = null;
  208. for(String strSprintAux : lstSprintSelecionados){
  209. if(mapIdESprint.containsKey(strSprintAux)){
  210. sprintTmp = mapIdESprint.get(strSprintAux);
  211. jasonSprints += '{ "start" : new Date('+ this.convertDate(sprintTmp.Data_inicio__c) + ',00,00,01), "end" : new Date(' + this.convertDate(sprintTmp.Data_fim__c) + ',23,59,59), "content" : "' + sprintTmp.Name + '", "group" : "Sprint", "editable" : false },';
  212. }
  213. }
  214. }
  215. }
  216. if(jasonSprints != ''){
  217. jsonTabela += jasonSprints.substring(0, jasonSprints.length() - 1) + '';
  218. }
  219.  
  220. jsonTabela += ']';
  221.  
  222. }
  223.  
  224. public void atualizarTexto(){
  225.  
  226. }
  227.  
  228. public String convertDate(Date d){
  229. String dt = d.year() + ',';
  230. Integer month = d.month() - 1;
  231. if(month < 10){
  232. dt += '0' + month + ',';
  233. }else{
  234. dt += month + ',';
  235. }
  236.  
  237. Integer day = d.day();
  238. if(day<10){
  239. dt += '0' + day;
  240. }else{
  241. dt += day;
  242. }
  243.  
  244. return dt;
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement