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