[6945] | 1 | function activityDetails( objActivity, decoded, path, isMail, repeat){ |
---|
[6881] | 2 | |
---|
[6945] | 3 | tasks = {length: 0}; |
---|
[6881] | 4 | |
---|
| 5 | if(path == undefined) |
---|
| 6 | path = ""; |
---|
| 7 | |
---|
| 8 | if( !decoded ) |
---|
[6945] | 9 | objActivity = DataLayer.decode( "schedulable:group", objActivity ); |
---|
[6881] | 10 | |
---|
| 11 | if(!isMail) |
---|
[6945] | 12 | objActivity = DataLayer.encode( "schedulable:activity", objActivity ); |
---|
| 13 | |
---|
| 14 | /** |
---|
[6977] | 15 | * canDiscardActivityDialog deve ser true se não houver alterações no evento |
---|
| 16 | */ |
---|
[6951] | 17 | canDiscardActivityDialog = true; |
---|
[6945] | 18 | /** |
---|
[6974] | 19 | * zebraDiscardActivityDialog é uma flag indicando que uma janela de confirmação (Zebra_Dialog) |
---|
| 20 | * já está aberta na tela, uma vez que não é possivel acessar o evento ESC utilizado para fechá-la |
---|
[6945] | 21 | */ |
---|
[6951] | 22 | zebraDiscardActivityDialog = false; |
---|
[6881] | 23 | |
---|
| 24 | var html = DataLayer.render( path+'templates/activity_add.ejs', { |
---|
[6945] | 25 | activity:objActivity |
---|
[6881] | 26 | }); |
---|
| 27 | |
---|
| 28 | if (!UI.dialogs.addActivity) { |
---|
| 29 | |
---|
| 30 | UI.dialogs.addActivity = jQuery('#sandbox').append('<div title="Criar Atividade" class="new-activity-win active"> <div>').find('.new-activity-win.active').html(html).dialog({ |
---|
[6945] | 31 | resizable: false, |
---|
| 32 | modal:true, |
---|
| 33 | autoOpen: false, |
---|
[6959] | 34 | width:735, |
---|
[6945] | 35 | position: 'center', |
---|
| 36 | close: function(event, ui) { |
---|
| 37 | /** |
---|
| 38 | * Remove tooltip possivelmente existente |
---|
| 39 | */ |
---|
| 40 | if ($('.qtip.qtip-blue.qtip-active').length) |
---|
| 41 | $('.qtip.qtip-blue.qtip-active').qtip('destroy'); |
---|
| 42 | |
---|
| 43 | attendees = {}; |
---|
| 44 | }, |
---|
| 45 | beforeClose: function(event, ui) { |
---|
| 46 | |
---|
[6951] | 47 | if (!canDiscardActivityDialog && !zebraDiscardActivityDialog) { |
---|
| 48 | zebraDiscardActivityDialog = true; |
---|
[6945] | 49 | window.setTimeout(function() { |
---|
[6951] | 50 | $.Zebra_Dialog('Suas alterações na atividade não foram salvas. Deseja descartar as alterações?', { |
---|
[6945] | 51 | 'type': 'question', |
---|
| 52 | 'overlay_opacity': '0.5', |
---|
[6951] | 53 | 'buttons': ['Descartar alterações', 'Continuar editando'], |
---|
[6945] | 54 | 'onClose': function(clicked) { |
---|
[6951] | 55 | if(clicked == 'Descartar alterações') { |
---|
| 56 | canDiscardActivityDialog = true; |
---|
[6945] | 57 | /** |
---|
[6951] | 58 | *Remoção dos anexos do eventos caso seja cancelado a edição |
---|
[6945] | 59 | */ |
---|
| 60 | DataLayer.rollback(); |
---|
[6881] | 61 | |
---|
[6945] | 62 | var ids = false; |
---|
| 63 | $.each($('.attachment-list input'), function (i, input) { |
---|
| 64 | DataLayer.put('attachment', {id: ''+input.value}); |
---|
| 65 | DataLayer.remove('attachment', ''+input.value); |
---|
| 66 | ids = true; |
---|
| 67 | }); |
---|
| 68 | if(ids) |
---|
| 69 | DataLayer.commit(); |
---|
[6881] | 70 | |
---|
[6945] | 71 | UI.dialogs.addActivity.dialog('close'); |
---|
| 72 | }else{ |
---|
[6951] | 73 | zebraDiscardActivityDialog = false; |
---|
[6945] | 74 | } |
---|
| 75 | |
---|
| 76 | /** |
---|
[6951] | 77 | * Uma vez aberta uma janela de confirmação (Zebra_Dialog), ao fechá-la |
---|
| 78 | * com ESC, para que o evento ESC não seja propagado para fechamento da |
---|
| 79 | * janela de edição de eventos, deve ser setada uma flag indicando que |
---|
| 80 | * já existe uma janela de confirmação aberta. |
---|
[6945] | 81 | */ |
---|
| 82 | if (!clicked) { |
---|
| 83 | window.setTimeout(function() { |
---|
[6951] | 84 | zebraDiscardActivityDialog = false; |
---|
[6945] | 85 | }, 200); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | }); |
---|
| 89 | |
---|
| 90 | }, 300); |
---|
| 91 | } |
---|
| 92 | //DataLayer.rollback(); |
---|
[6951] | 93 | return canDiscardActivityDialog; |
---|
[6945] | 94 | }, |
---|
| 95 | dragStart: function(event, ui) { |
---|
[6974] | 96 | if ($('.qtip.qtip-blue.qtip-active').length) |
---|
| 97 | $('.qtip.qtip-blue.qtip-active').qtip('destroy'); |
---|
[6945] | 98 | } |
---|
| 99 | }); |
---|
[6881] | 100 | |
---|
| 101 | } else { |
---|
| 102 | UI.dialogs.addActivity.html(html); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | var tabs = UI.dialogs.addActivity.children('.content').tabs({ |
---|
| 106 | select: function(event, ui) { |
---|
| 107 | if ($('.qtip.qtip-blue.qtip-active').length) |
---|
| 108 | $('.qtip.qtip-blue.qtip-active').qtip('destroy'); |
---|
| 109 | } |
---|
| 110 | }); |
---|
[6945] | 111 | |
---|
| 112 | var group = DataLayer.get('calendar', objActivity.group); |
---|
[6881] | 113 | |
---|
[6945] | 114 | if (group.timezone != objActivity.timezone){ |
---|
| 115 | UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').find('option[value="'+objActivity.timezone+'"]').attr('selected','selected').trigger('change'); |
---|
| 116 | UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').addClass('hidden'); |
---|
| 117 | $('.group-addevent-details-txt-timezone').removeClass('hidden'); |
---|
[6881] | 118 | |
---|
| 119 | } |
---|
| 120 | |
---|
[6945] | 121 | UI.dialogs.addActivity.find('.group_addactivity_details_lnk_timezone').click(function(e){ |
---|
[6881] | 122 | $(this).addClass('hidden'); |
---|
[6945] | 123 | $('.group-addactivity-details-txt-timezone').removeClass('hidden'); |
---|
[6881] | 124 | e.preventDefault(); |
---|
| 125 | }); |
---|
| 126 | |
---|
[6945] | 127 | UI.dialogs.addActivity.find('.button.remove').button({ |
---|
| 128 | text:false, |
---|
| 129 | icons:{ |
---|
| 130 | primary:'ui-icon-close' |
---|
| 131 | } |
---|
| 132 | }).click(function(el){ |
---|
| 133 | var id; |
---|
| 134 | if( id = $(this).parent().find('input[name="alarmId[]"]').val()) |
---|
| 135 | DataLayer.remove('alarm', id); |
---|
| 136 | $(this).parent().remove().find('li').is(':empty'); |
---|
| 137 | }); |
---|
[6881] | 138 | |
---|
[6945] | 139 | UI.dialogs.addActivity.find('.button-add-alarms').click(function(){ |
---|
[7269] | 140 | DataLayer.render( 'templates/alarms_add_itemlist.ejs', {type: 2}, function( template ){ |
---|
[6945] | 141 | jQuery('.activity-alarms-list').append(template) |
---|
| 142 | .find('.number').numeric().end() |
---|
| 143 | .find('.button.remove').button({ |
---|
| 144 | text:false, |
---|
| 145 | icons:{ |
---|
| 146 | primary:'ui-icon-close' |
---|
| 147 | } |
---|
| 148 | }).click(function(el) { |
---|
| 149 | $(this).parent().remove(); |
---|
| 150 | }); |
---|
| 151 | }); |
---|
| 152 | }); |
---|
[6881] | 153 | |
---|
[6951] | 154 | /*Seleciona a agenda padrão para visualização/edição de um evento*/ |
---|
[6945] | 155 | if(objActivity.id) |
---|
[6954] | 156 | UI.dialogs.addActivity.find('select[name="group"] option[value="'+objActivity.group+'"]').attr('selected','selected').trigger('change'); |
---|
[6881] | 157 | |
---|
| 158 | UI.dialogs.addActivity.find('.button').button(); |
---|
[6945] | 159 | UI.dialogs.addActivity.find('.button.add').button({ |
---|
| 160 | icons: { |
---|
| 161 | secondary: "ui-icon-plus" |
---|
| 162 | } |
---|
[6881] | 163 | }); |
---|
| 164 | |
---|
[6954] | 165 | todoStatus('addActivity', (objActivity.activityStatus != undefined) ? objActivity.activityStatus : 1); |
---|
| 166 | |
---|
[6958] | 167 | UI.dialogs.addActivity.find('select[name="activityStatus"]').attr('disabled', 'disabled'); |
---|
| 168 | |
---|
[6881] | 169 | // ==== validation events ==== |
---|
[6958] | 170 | UI.dialogs.addActivity.find(".input-group .h1").Watermark("Atividade sem título"); |
---|
[6945] | 171 | |
---|
[6881] | 172 | UI.dialogs.addActivity.find(".number").numeric(); |
---|
[6945] | 173 | |
---|
[6881] | 174 | User.preferences.dateFormat.indexOf('-') > 0 ? |
---|
| 175 | UI.dialogs.addActivity.find(".date").mask("99-99-9999", { |
---|
| 176 | completed:function(){ |
---|
| 177 | updateMap(); |
---|
| 178 | } |
---|
| 179 | }) : |
---|
[6945] | 180 | |
---|
[6881] | 181 | UI.dialogs.addActivity.find(".date").mask("99/99/9999", { |
---|
| 182 | completed:function(){ |
---|
| 183 | updateMap(); |
---|
| 184 | } |
---|
| 185 | }); |
---|
| 186 | |
---|
[6945] | 187 | UI.dialogs.addActivity.find(".menu-addactivity") |
---|
[6881] | 188 | .children(".delete").click(function(){ |
---|
| 189 | $.Zebra_Dialog('Tem certeza que deseja excluir a atividade?', { |
---|
| 190 | 'type': 'question', |
---|
| 191 | 'overlay_opacity': '0.5', |
---|
[6951] | 192 | 'buttons': ['Sim', 'Não'], |
---|
[6881] | 193 | 'onClose': function(clicked) { |
---|
| 194 | if(clicked == 'Sim'){ |
---|
[6951] | 195 | canDiscardActivityDialog = true; |
---|
[6881] | 196 | /* Remove por filtro */ |
---|
[6974] | 197 | DataLayer.removeFilter('schedulable', {filter: ['AND', ['=', 'id', objActivity.id], ['=', 'calendar', objActivity.group], ['=','user',(objActivity.me.user ? objActivity.me.user.id : objActivity.me.id)], ['=', 'type', '2']]}); |
---|
[6881] | 198 | Calendar.rerenderView(true); |
---|
| 199 | /********************/ |
---|
| 200 | UI.dialogs.addActivity.dialog("close"); |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | }); |
---|
| 204 | }).end() |
---|
| 205 | |
---|
| 206 | .children(".cancel").click(function(){ |
---|
| 207 | UI.dialogs.addActivity.dialog("close"); |
---|
| 208 | }).end() |
---|
| 209 | |
---|
| 210 | .children(".save").click(function(){ |
---|
[6951] | 211 | /* Validação |
---|
[6881] | 212 | var msg = false; |
---|
| 213 | if(msg = validDateEvent()){ |
---|
[6945] | 214 | $(".new-activity-win.active").find('.messages-validation').removeClass('hidden').find('.message label').html(msg); |
---|
| 215 | return false; |
---|
[6881] | 216 | } |
---|
[6945] | 217 | */ |
---|
[7011] | 218 | UI.dialogs.addActivity.find('select[name="activityStatus"], input[name="allDay"]').removeAttr('disabled'); |
---|
[6951] | 219 | canDiscardActivityDialog = true; |
---|
[7008] | 220 | |
---|
[6945] | 221 | UI.dialogs.addActivity.children().find('form.form-addactivity').submit(); |
---|
| 222 | UI.dialogs.addActivity.dialog("close"); |
---|
[6881] | 223 | |
---|
| 224 | }).end() |
---|
| 225 | |
---|
| 226 | .children(".export").click(function(){ |
---|
| 227 | UI.dialogs.addActivity.children().find(".form-export").submit(); |
---|
| 228 | }); |
---|
| 229 | |
---|
[6945] | 230 | var task_activityHtml = DataLayer.render( path+'templates/task_activity_add.ejs', { activity: objActivity}); |
---|
| 231 | var blkAddTask = UI.dialogs.addActivity.find('#group_addactivity_details8').append(task_activityHtml); |
---|
[6881] | 232 | |
---|
| 233 | var dates = UI.dialogs.addActivity.find('input.date').datepicker({ |
---|
| 234 | dateFormat: User.preferences.dateFormat.replace(/M/g, 'm').replace(/yyyy/g, 'yy'), |
---|
| 235 | onSelect : function( selectedDate ){ |
---|
| 236 | updateMap(); |
---|
| 237 | } |
---|
| 238 | }); |
---|
| 239 | |
---|
[6945] | 240 | blkAddTask.find('.add-activity-search .ui-icon-search').click(function(event) { |
---|
| 241 | blkAddTask.find('.add-activity-search input').keydown(); |
---|
[6881] | 242 | }); |
---|
| 243 | |
---|
| 244 | |
---|
[6945] | 245 | blkAddTask.find('.add-activity-search input').keydown(function(event) { |
---|
[6881] | 246 | |
---|
| 247 | if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') { |
---|
| 248 | // Fazer get das tarefas |
---|
[6945] | 249 | var filter = |
---|
| 250 | { |
---|
| 251 | filter: |
---|
| 252 | ['AND', |
---|
| 253 | ['=', 'type', '2'], |
---|
| 254 | ['>=','startTime', $.now()], |
---|
| 255 | ['in', 'calendar', |
---|
| 256 | [$('div.new-activity-win.active select[name="groupFilter"]').val()] |
---|
| 257 | ] |
---|
| 258 | ], criteria: {'filterTasks': true} |
---|
| 259 | }; |
---|
| 260 | if($(this).val() != ''){ |
---|
| 261 | filter['filter'].push(['OR', |
---|
| 262 | ["i*", "summary", $(this).val()], |
---|
| 263 | ["i*", "description", $(this).val()] |
---|
| 264 | ]); |
---|
| 265 | } |
---|
[6881] | 266 | |
---|
[6945] | 267 | var result = DataLayer.get('schedulable:taskSearch', filter, true) |
---|
[6881] | 268 | /** |
---|
[6951] | 269 | * TODO: trocar por template |
---|
| 270 | */ |
---|
[6945] | 271 | blkAddTask.find('ul.search-result-list').empty().css('overflow', 'hidden'); |
---|
[6881] | 272 | if (!result) { |
---|
[6945] | 273 | blkAddTask.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>'); |
---|
| 274 | }else{ |
---|
| 275 | for(i=0; i<result.length; i++) |
---|
| 276 | result[i].enabled = (blkAddTask.find('dd.task-activity-list ul.task-activity-list input[value="' + result[i].id + '"]').length) ? false : true; |
---|
| 277 | |
---|
| 278 | blkAddTask.find('ul.search-result-list').append(DataLayer.render( path+'templates/task_search_itemlist.ejs', result)); |
---|
[6881] | 279 | |
---|
[6945] | 280 | /* TODO - Verificar id da aitividade*/ |
---|
| 281 | blkAddTask.find('ul.search-result-list li').click(function(event, ui){ |
---|
| 282 | if ($(event.target).is('input')) { |
---|
| 283 | old_item = $(event.target).parents('li'); |
---|
[6881] | 284 | |
---|
[6945] | 285 | tasks[old_item.find('[name="id"]').val()] = { |
---|
| 286 | startDate: old_item.find('[name="taskStartDate"]').val(), |
---|
| 287 | startHour: old_item.find('[name="taskStartHour"]').val(), |
---|
| 288 | endDate: old_item.find('[name="taskEndDate"]').val(), |
---|
| 289 | endHour: old_item.find('[name="taskEndHour"]').val(), |
---|
| 290 | dueDate: old_item.find('[name="taskDueDate"]').val(), |
---|
| 291 | dueTime: old_item.find('[name="taskDueTime"]').val(), |
---|
| 292 | allDay: old_item.find('[name="taskAllDay"]').val(), |
---|
[6954] | 293 | percentage: old_item.find('[name="taskPercentage"]').val(), |
---|
| 294 | status: old_item.find('[name="taskStatus"]').val() |
---|
[6945] | 295 | }; |
---|
[6881] | 296 | |
---|
[6945] | 297 | tasks.length += 1; |
---|
| 298 | |
---|
[6951] | 299 | blkAddTask.find('dd.task-activity-list ul.task-activity-list') |
---|
| 300 | .append(DataLayer.render(path+'templates/task_add_itemlist.ejs', [{ |
---|
[7075] | 301 | idTask: old_item.find('[name="id"]').val(), |
---|
| 302 | description: old_item.find('.description').html(), |
---|
| 303 | isWrite: false, |
---|
| 304 | summary: old_item.find('[name="taskSummary"]').val(), |
---|
| 305 | dueDate: old_item.find('[name="taskDueDate"]').val(), |
---|
| 306 | dueTime: old_item.find('[name="taskDueTime"]').val(), |
---|
| 307 | startDate: old_item.find('[name="taskStartDate"]').val(), |
---|
| 308 | startHour: old_item.find('[name="taskStartHour"]').val(), |
---|
| 309 | percentage: old_item.find('[name="taskPercentage"]').val(), |
---|
| 310 | priority: old_item.find('[name="taskPriority"]').val() |
---|
[6951] | 311 | }])) |
---|
[6945] | 312 | .scrollTo('max'); |
---|
[7008] | 313 | callbackTask(false, path); |
---|
[6945] | 314 | registerStatus(); |
---|
| 315 | blkAddTask.find('.not-activity').addClass('hidden'); |
---|
| 316 | old_item.remove(); |
---|
| 317 | } |
---|
| 318 | }); |
---|
| 319 | } |
---|
[6951] | 320 | event.preventDefault(); |
---|
[6881] | 321 | } |
---|
| 322 | }); |
---|
| 323 | |
---|
[6951] | 324 | /*Carrega as tarefas já existentes em uma atividade*/ |
---|
[6945] | 325 | if(objActivity.tasks.length){ |
---|
| 326 | tasks = objActivity.tasks; |
---|
| 327 | |
---|
| 328 | for(var i in objActivity.tasks){ |
---|
| 329 | if(i != 'length') |
---|
| 330 | blkAddTask.find('dd.task-activity-list ul.task-activity-list') |
---|
| 331 | .append(DataLayer.render(path+'templates/task_add_itemlist.ejs', [{ |
---|
| 332 | idTask: i, |
---|
| 333 | description: tasks[i].description, |
---|
[6977] | 334 | idTaskToActivity: tasks[i].taskToActivity, |
---|
[7075] | 335 | isWrite: true, |
---|
| 336 | summary: tasks[i].summary, |
---|
| 337 | dueDate: tasks[i].dueDate, |
---|
| 338 | dueTime: tasks[i].dueTime, |
---|
| 339 | startDate: tasks[i].startDate, |
---|
| 340 | startHour: tasks[i].startHour, |
---|
| 341 | percentage: tasks[i].percentage, |
---|
| 342 | priority: tasks[i].priority |
---|
[6945] | 343 | }])) |
---|
| 344 | .scrollTo('max'); |
---|
| 345 | } |
---|
| 346 | |
---|
[7008] | 347 | callbackTask(false, path); |
---|
[6945] | 348 | registerStatus(); |
---|
| 349 | blkAddTask.find('.not-activity').addClass('hidden'); |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | UI.dialogs.addActivity.find('.row.fileupload-buttonbar-activity .button').filter('.delete').button({ |
---|
[6881] | 353 | icons: { |
---|
[6945] | 354 | primary: "ui-icon-close" |
---|
[6881] | 355 | }, |
---|
| 356 | text: 'Excluir' |
---|
| 357 | }).click(function () { |
---|
| 358 | $.Zebra_Dialog('Tem certeza que deseja excluir todos anexos?', { |
---|
| 359 | 'type': 'question', |
---|
| 360 | 'overlay_opacity': '0.5', |
---|
[6951] | 361 | 'buttons': ['Sim', 'Não'], |
---|
[6881] | 362 | 'onClose': function(clicked) { |
---|
| 363 | if(clicked == 'Sim'){ |
---|
| 364 | |
---|
| 365 | var ids = []; |
---|
| 366 | $.each($('.attachment-list input'), function (i, input) { |
---|
| 367 | DataLayer.remove('schedulableToAttachment', { |
---|
| 368 | filter: ['=', 'id', ''+input.value] |
---|
| 369 | }); |
---|
| 370 | }); |
---|
[6981] | 371 | $('div.new-activity-win .attachment-list input').remove(); |
---|
| 372 | $('div.new-activity-win .row.fileupload-buttonbar-activity .attachments-list p').remove(); |
---|
| 373 | $('div.new-activity-win .btn-danger.delete').addClass('hidden'); |
---|
[6881] | 374 | } |
---|
| 375 | }}); |
---|
| 376 | }).end() |
---|
| 377 | .filter('.close').button({ |
---|
| 378 | icons: { |
---|
[6945] | 379 | primary: "ui-icon-close" |
---|
[6881] | 380 | }, |
---|
| 381 | text: false |
---|
| 382 | }).click(function () { |
---|
| 383 | DataLayer.remove('schedulableToAttachment', $(this).parents('p').find('input[name="fileId[]"]').val()); |
---|
| 384 | $(this).parents('p').remove(); |
---|
| 385 | }).end() |
---|
| 386 | .filter('.downlaod-archive').button({ |
---|
| 387 | icons: { |
---|
[6945] | 388 | primary: "ui-icon-arrowthickstop-1-s" |
---|
[6881] | 389 | }, |
---|
| 390 | text: false |
---|
| 391 | }); |
---|
| 392 | |
---|
[6981] | 393 | extendsFileupload('activity', path); |
---|
[6881] | 394 | |
---|
[6951] | 395 | UI.dialogs.addActivity.find(':input').change(function(event){ |
---|
| 396 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
| 397 | canDiscardActivityDialog = false; |
---|
| 398 | }).keydown(function(event){ |
---|
| 399 | if (event.keyCode != '27' && event.keyCode != '13') |
---|
| 400 | canDiscardActivityDialog = false; |
---|
| 401 | }); |
---|
| 402 | |
---|
[6881] | 403 | UI.dialogs.addActivity.dialog('open'); |
---|
[6977] | 404 | } |
---|
| 405 | |
---|
| 406 | function refreshTaskActivity(){ |
---|
| 407 | updateActivity = false; |
---|
| 408 | |
---|
| 409 | var objActivity = DataLayer.get('schedulable:activity', UI.dialogs.addActivity.find('input[name="idActivity"]').val()); |
---|
| 410 | var blkAddTask = UI.dialogs.addActivity.find('#group_addactivity_details8'); |
---|
| 411 | var blkAuto = UI.dialogs.addActivity.find('#group_addactivity_details1'); |
---|
| 412 | |
---|
| 413 | tasks = objActivity.tasks; |
---|
| 414 | blkAddTask.find('dd.task-activity-list ul.task-activity-list').html(''); |
---|
| 415 | |
---|
| 416 | for(var i in tasks) |
---|
| 417 | DataLayer.remove('schedulable', i, false); |
---|
| 418 | |
---|
| 419 | for(var i in objActivity.tasks){ |
---|
| 420 | if(i != 'length') |
---|
| 421 | blkAddTask.find('dd.task-activity-list ul.task-activity-list') |
---|
| 422 | .append(DataLayer.render('templates/task_add_itemlist.ejs', [{ |
---|
| 423 | idTask: i, |
---|
| 424 | description: tasks[i].description, |
---|
| 425 | idTaskToActivity: tasks[i].taskToActivity, |
---|
[7075] | 426 | isWrite: true, |
---|
| 427 | summary: tasks[i].summary, |
---|
| 428 | dueDate: tasks[i].dueDate, |
---|
| 429 | dueTime: tasks[i].dueTime, |
---|
| 430 | startDate: tasks[i].startDate, |
---|
| 431 | startHour: tasks[i].startHour, |
---|
| 432 | percentage: tasks[i].percentage, |
---|
| 433 | priority: tasks[i].priority |
---|
[6977] | 434 | }])) |
---|
| 435 | .scrollTo('max'); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | callbackTask(blkAddTask); |
---|
| 439 | registerStatus(blkAuto); |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | function registerStatus(blkAuto){ |
---|
| 443 | if(!blkAuto) |
---|
| 444 | blkAuto = UI.dialogs.addActivity.find('#group_addactivity_details1'); |
---|
| 445 | |
---|
| 446 | var startDate = false; |
---|
| 447 | var endDate = new Date; |
---|
| 448 | var dueDate = new Date; |
---|
| 449 | var percentage = 0; |
---|
| 450 | var statusTasks = {1: 0, 2: 0, 3: 0, 4: 0}; |
---|
| 451 | var allDay = true; |
---|
| 452 | |
---|
| 453 | var formatString = User.preferences.dateFormat + " " + User.preferences.hourFormat; |
---|
| 454 | |
---|
| 455 | if(tasks.length == 0){ |
---|
| 456 | |
---|
| 457 | startDate = new Date(); |
---|
| 458 | var configData = (startDate.toString('mm') < 30) ? {minutes: (30 - parseInt(startDate.toString('mm')))} : {hours: 1, minutes: '-'+startDate.toString('mm')}; |
---|
| 459 | startDate.add(configData); |
---|
| 460 | |
---|
| 461 | endDate = new Date(dateCalendar.decodeRange(startDate, (!!User.preferences.defaultCalendar ? ( !!Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration ? (Calendar.signatureOf[User.preferences.defaultCalendar].calendar.defaultDuration) : (User.preferences.defaultDuration)) : (User.preferences.defaultDuration)))); |
---|
| 462 | |
---|
| 463 | blkAuto.find('input[name="startDate"]').val(startDate.toString(User.preferences.dateFormat )); |
---|
| 464 | blkAuto.find('input[name="startHour"]').val(startDate.toString(User.preferences.hourFormat )); |
---|
| 465 | |
---|
| 466 | blkAuto.find('input[name="endDate"]').val(endDate.toString(User.preferences.dateFormat )); |
---|
| 467 | blkAuto.find('input[name="endHour"]').val(endDate.toString(User.preferences.hourFormat )); |
---|
| 468 | |
---|
| 469 | blkAuto.find('input[name="dueDate"]').val(''); |
---|
| 470 | blkAuto.find('input[name="dueHour"]').val(''); |
---|
| 471 | |
---|
| 472 | blkAuto.find('input[name="percentage"]').val(percentage); |
---|
| 473 | |
---|
| 474 | todoStatus('addActivity', 1); |
---|
| 475 | |
---|
| 476 | UI.dialogs.addActivity.find('select[name="activityStatus"] option[value="'+1+'"]').attr('selected','selected'); |
---|
| 477 | |
---|
| 478 | blkAuto.find('input[name="allDay"]').attr('checked', false); |
---|
| 479 | |
---|
| 480 | return true; |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | for (var i in tasks){ |
---|
| 484 | |
---|
[7012] | 485 | if(i == 'length') |
---|
| 486 | continue; |
---|
[6977] | 487 | |
---|
[7012] | 488 | statusTasks[tasks[i].status]++; |
---|
[6977] | 489 | |
---|
[7012] | 490 | var stTime = Date.parseExact( tasks[i].startDate + " "+$.trim( tasks[i].startHour) , formatString); |
---|
| 491 | var enTime = Date.parseExact( tasks[i].endDate + " "+$.trim( tasks[i].endHour), formatString ); |
---|
[6977] | 492 | |
---|
[7012] | 493 | startDate = (startDate && startDate.compareTo(stTime) == -1) ? startDate : stTime; |
---|
| 494 | endDate = endDate.compareTo(enTime) == -1 ? enTime : endDate; |
---|
[6977] | 495 | |
---|
[7012] | 496 | if(tasks[i].dueDate != ''){ |
---|
| 497 | var pvTime = Date.parseExact( tasks[i].dueDate + " "+$.trim( tasks[i].dueTime), formatString ); |
---|
| 498 | dueDate = dueDate.compareTo(pvTime) == -1 ? pvTime : dueDate; |
---|
| 499 | } |
---|
[6977] | 500 | |
---|
[7012] | 501 | percentage += parseInt(tasks[i].percentage); |
---|
[6977] | 502 | } |
---|
[7012] | 503 | |
---|
| 504 | |
---|
| 505 | if((percentage > 0) && (tasks.length > 0)) |
---|
| 506 | percentage = parseInt(percentage / tasks.length); |
---|
| 507 | |
---|
[6977] | 508 | var statusActivity = 1; |
---|
| 509 | |
---|
| 510 | if(statusTasks[4] != 0) |
---|
| 511 | statusActivity = 4; |
---|
| 512 | else if(statusTasks[2] != 0) |
---|
| 513 | statusActivity = 2; |
---|
| 514 | else if(statusTasks[3] == tasks.length) |
---|
| 515 | statusActivity = 3; |
---|
| 516 | else if(statusTasks[1] == tasks.length) |
---|
| 517 | statusActivity = 1; |
---|
| 518 | else |
---|
| 519 | statusActivity = 2; |
---|
| 520 | |
---|
| 521 | todoStatus('addActivity', statusActivity); |
---|
| 522 | |
---|
| 523 | UI.dialogs.addActivity.find('select[name="activityStatus"] option[value="'+statusActivity+'"]').attr('selected','selected'); |
---|
| 524 | |
---|
| 525 | dueDate = dueDate.compareTo(endDate) == -1 ? endDate : dueDate; |
---|
| 526 | |
---|
| 527 | blkAuto.find('input[name="startDate"]').val(startDate.toString(User.preferences.dateFormat )); |
---|
| 528 | blkAuto.find('input[name="startHour"]').val(startDate.toString(User.preferences.hourFormat )); |
---|
| 529 | |
---|
| 530 | blkAuto.find('input[name="endDate"]').val(endDate.toString(User.preferences.dateFormat )); |
---|
| 531 | blkAuto.find('input[name="endHour"]').val(endDate.toString(User.preferences.hourFormat )); |
---|
| 532 | |
---|
| 533 | blkAuto.find('input[name="dueDate"]').val(dueDate.toString(User.preferences.dateFormat )); |
---|
| 534 | blkAuto.find('input[name="dueHour"]').val(dueDate.toString(User.preferences.hourFormat )); |
---|
| 535 | |
---|
| 536 | blkAuto.find('input[name="percentage"]').val(percentage); |
---|
| 537 | |
---|
| 538 | blkAuto.find('input[name="allDay"]').attr('checked', (!!(startDate.compareTo(endDate) == 0) || (startDate.toString('HH:mm') == endDate.toString('HH:mm')) ? true : false)); |
---|
| 539 | } |
---|
| 540 | |
---|
[7008] | 541 | function callbackTask(blkAddTask, path){ |
---|
| 542 | |
---|
| 543 | path = path ? path : ''; |
---|
| 544 | |
---|
[6977] | 545 | if(!blkAddTask) |
---|
| 546 | blkAddTask = UI.dialogs.addActivity.find('#group_addactivity_details8'); |
---|
| 547 | |
---|
| 548 | blkAddTask.find("li .button").filter(".close.new").button({ |
---|
| 549 | icons: { |
---|
| 550 | primary: "ui-icon-close" |
---|
| 551 | }, |
---|
| 552 | text: false |
---|
| 553 | }).click(function () { |
---|
| 554 | |
---|
| 555 | delete tasks[$(this).parents('li').find('input[name="idtask[]"]').val()] |
---|
| 556 | tasks.length += -1; |
---|
| 557 | |
---|
| 558 | idTaskToActivity = $(this).parents('li').find('input[name="idTaskToActivity[]"]').val() |
---|
| 559 | |
---|
| 560 | if(idTaskToActivity != '') |
---|
| 561 | DataLayer.remove('taskToActivity', idTaskToActivity); |
---|
| 562 | |
---|
| 563 | $(this).parents('li').remove(); |
---|
| 564 | |
---|
| 565 | if(blkAddTask.find(".task-activity-list li").length == 1) |
---|
| 566 | blkAddTask.find("li.not-activity ").removeClass('hidden'); |
---|
| 567 | |
---|
| 568 | registerStatus(); |
---|
| 569 | }) |
---|
| 570 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 571 | .removeClass('new').end() |
---|
| 572 | |
---|
| 573 | .filter(".info.new").button({ |
---|
| 574 | icons: { |
---|
| 575 | primary: "ui-icon-notice" |
---|
| 576 | }, |
---|
| 577 | text: false |
---|
| 578 | }).click(function () { |
---|
| 579 | var positionY = $(this).parents("li").offset().top; |
---|
| 580 | |
---|
[7075] | 581 | var summary = $(this).parents('li').find("div").find(".summary").val(); |
---|
| 582 | var startDate = $(this).parents('li').find("div").find(".startDate").val(); |
---|
| 583 | var startHour = $(this).parents('li').find("div").find(".startHour").val(); |
---|
| 584 | var dueDate = $(this).parents('li').find("div").find(".dueDate").val(); |
---|
| 585 | var dueTime = $(this).parents('li').find("div").find(".dueTime").val(); |
---|
| 586 | var percentage = $(this).parents('li').find("div").find(".percentage").val(); |
---|
| 587 | var priority = $(this).parents('li').find("div").find(".priority").val(); |
---|
[6977] | 588 | var email = $(this).parents('li').find("div").find(".mail").text() |
---|
| 589 | |
---|
| 590 | if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ |
---|
| 591 | $(this).qtip({ |
---|
| 592 | show: { |
---|
| 593 | ready: true, |
---|
| 594 | solo: true, |
---|
| 595 | when: { |
---|
| 596 | event: 'click' |
---|
| 597 | } |
---|
| 598 | }, |
---|
| 599 | hide: false, |
---|
| 600 | content: { |
---|
| 601 | text: $('<div></div>').html( DataLayer.render( path + 'templates/activity_information_task.ejs', { |
---|
[7075] | 602 | 'summary' : summary, |
---|
| 603 | 'startDate' : startDate, |
---|
| 604 | 'startHour' : startHour, |
---|
| 605 | 'dueDate' : dueDate, |
---|
| 606 | 'dueTime' : dueTime, |
---|
| 607 | 'percentage' : percentage, |
---|
| 608 | 'priority' : priority |
---|
[6977] | 609 | } ) ), |
---|
| 610 | title: { |
---|
| 611 | text:'Informações', |
---|
| 612 | button: '<a class="button close" href="#">close</a>' |
---|
| 613 | } |
---|
| 614 | }, |
---|
| 615 | style: { |
---|
| 616 | name: 'blue', |
---|
| 617 | tip: { |
---|
| 618 | }, |
---|
| 619 | border: { |
---|
| 620 | width: 4, |
---|
| 621 | radius: 8 |
---|
| 622 | }, |
---|
| 623 | width: { |
---|
| 624 | min: 230, |
---|
| 625 | max:230 |
---|
| 626 | } |
---|
| 627 | }, |
---|
| 628 | position: { |
---|
| 629 | corner: { |
---|
| 630 | target: 'rightMiddle', |
---|
| 631 | tooltip: 'leftMiddle' |
---|
| 632 | }, |
---|
| 633 | adjust: { |
---|
| 634 | x: 30, |
---|
| 635 | y: 0 |
---|
| 636 | } |
---|
| 637 | } |
---|
| 638 | }) |
---|
| 639 | .qtip("api").onShow = function(arg0) { |
---|
| 640 | $('.qtip-active .button.close').button({ |
---|
| 641 | icons: { |
---|
| 642 | primary: "ui-icon-close" |
---|
| 643 | }, |
---|
| 644 | text: false |
---|
| 645 | }) |
---|
| 646 | .click(function(){ |
---|
[7405] | 647 | blkAddTask.find('dd.task-activity-list').qtip('destroy'); |
---|
[6977] | 648 | }); |
---|
| 649 | |
---|
| 650 | $('.qtip-active .button.cancel').button().click(function(){ |
---|
[7405] | 651 | blkAddTask.find('dd.activity-list [type=checkbox]').attr('checked', false); |
---|
| 652 | blkAddTask.find('dd.activity-list').qtip('destroy'); |
---|
[6977] | 653 | }); |
---|
| 654 | |
---|
| 655 | $('.qtip .button').button(); |
---|
| 656 | |
---|
| 657 | }; |
---|
| 658 | } |
---|
| 659 | }) |
---|
| 660 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 661 | .removeClass('new').end() |
---|
| 662 | .filter(".edit.new").button({ |
---|
| 663 | icons: { |
---|
| 664 | primary: "ui-icon-pencil" |
---|
| 665 | }, |
---|
| 666 | text: false |
---|
| 667 | }).click(function () { |
---|
| 668 | var task = DataLayer.get('schedulable:task', $(this).parents('li').find('input[name="idtask[]"]').val()); |
---|
| 669 | taskDetails(task, true, '',true, null, true); |
---|
| 670 | }) |
---|
| 671 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 672 | .removeClass('new').end() |
---|
| 673 | |
---|
| 674 | UI.dialogs.addActivity.find('.task-activity-list li').hover( |
---|
| 675 | function () { |
---|
| 676 | $(this).addClass("hover-attendee"); |
---|
| 677 | $(this).find('.button').removeClass('disable ui-button-disabled ui-state-disabled').end() |
---|
| 678 | .find('.activity-options').addClass('hover-attendee'); |
---|
| 679 | }, |
---|
| 680 | function () { |
---|
| 681 | $(this).removeClass("hover-attendee"); |
---|
| 682 | $(this).find('.button').addClass('disable ui-button-disabled ui-state-disabled').end() |
---|
| 683 | .find('.activity-options').removeClass('hover-attendee'); |
---|
| 684 | } |
---|
| 685 | ); |
---|
[7075] | 686 | } |
---|