Ignore:
Timestamp:
02/14/12 16:52:04 (12 years ago)
Author:
acoutinho
Message:

Ticket #2434 - Implementacao anexos, acls e delegacao de participantes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/calendar/js/helpers.js

    r5510 r5514  
    4545} 
    4646*/ 
     47 
    4748function eventDetails( objEvent, decoded, path) 
    4849{ 
     
    6970         */ 
    7071        zebraDiscardEventDialog = false; 
     72         
     73        /** 
     74                ACLs do participant 
     75        */ 
     76        acl_names = { 
     77                'w': 'acl-white', 
     78                'i': 'acl-invite-guests', 
     79                'p': 'acl-participation-required' 
     80        }; 
     81        /** 
     82        * callback de participantes generico 
     83        */ 
     84        var callbackAttendee = function(){ 
     85                //Cria qtip de permissões pelo click do checkbox 
     86                var checked = false; 
     87                blkAddAtendee.find("li.not-attendee").addClass('hidden'); 
     88         
     89                blkAddAtendee.find("li .button").filter(".close.new").button({ 
     90                        icons: { 
     91                                primary: "ui-icon-close" 
     92                        }, 
     93                        text: false 
     94                }).click(function () { 
     95                        DataLayer.remove('participant', $(this).parents('li').find('[type=checkbox]').val()); 
     96                        $(this).parents('li').remove(); 
     97                        if(blkAddAtendee.find(".attendee-list li").length == 1) 
     98                                blkAddAtendee.find("li.not-attendee").removeClass('hidden'); 
     99                }) 
     100                .addClass('tiny disable ui-button-disabled ui-state-disabled') 
     101                .removeClass('new').end() 
     102         
     103                .filter(".delegate.new").button({ 
     104                        icons: { 
     105                                primary: "ui-icon-transferthick-e-w" 
     106                        }, 
     107                        text: false 
     108                }).click(function () { 
     109                                                 
     110                        if($(this).hasClass('attendee-permissions-change-button')){ 
     111                                $(this).removeClass('attendee-permissions-change-button')    
     112                                .find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change').end();                
     113                                 
     114                                $(this).parents('li').find('input[name="delegatedFrom[]"]').val(''); 
     115                                 
     116                                blkAddAtendee.find('.request-update').addClass('hidden'); 
     117                                blkAddAtendee.find('.status option').toggleClass('hidden'); 
     118                                 
     119                                 
     120                                blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change'); 
     121                                 
     122                        }else{ 
     123                                blkAddAtendee.find('.delegate').removeClass('attendee-permissions-change-button'); 
     124                                blkAddAtendee.find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change'); 
     125                         
     126                                $(this).addClass('attendee-permissions-change-button')    
     127                                .find('.ui-icon-transferthick-e-w').addClass('attendee-permissions-change').end();                
     128                                $(this).parents('li').find('input[name="delegatedFrom[]"]').val(blkAddAtendee.find('.me input[name="attendee[]"]').val()); 
     129                         
     130                                blkAddAtendee.find('.request-update').removeClass('hidden'); 
     131                                if(blkAddAtendee.find('.status option.hidden').length == 1) 
     132                                        blkAddAtendee.find('.status option').toggleClass('hidden'); 
     133                         
     134                                blkAddAtendee.find('option[value=5]').attr('selected','selected').trigger('change'); 
     135                        } 
     136                }) 
     137                .addClass('tiny disable ui-button-disabled ui-state-disabled') 
     138                .removeClass('new').end() 
     139                 
     140                .filter(".edit.new").button({ 
     141                        icons: { 
     142                                primary: "ui-icon-key" 
     143                        }, 
     144                        text: false 
     145                }).click(function() { 
     146                         
     147                        if(!!!checked) 
     148                                $(this).parents('li').find('[type=checkbox]').attr('checked', (!$(this).parent().find('[type=checkbox]').is(':checked'))).end(); 
     149                         
     150                        var aclsParticipant =  $(this).parents('li').find('input[name="attendeeAcl[]"]').val(); 
     151                        checked = false; 
     152                         
     153                        if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ 
     154                                blkAddAtendee.find('dd.attendee-list').qtip({ 
     155                                        show: {ready: true, solo: true, when: {event: 'click'}}, 
     156                                        hide: false, 
     157                                        content: { 
     158                                                text: $('<div></div>').html( DataLayer.render( 'templates/attendee_permissions.ejs', {} ) ),  
     159                                                title: { 
     160                                                        text:'Permissões',  
     161                                                        button: '<a class="button close" href="#">close</a>' 
     162                                                } 
     163                                        }, 
     164                                        style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 230, max:230}}, 
     165                                        position: { 
     166                                                corner: { 
     167                                                        target: 'rightMiddle', 
     168                                                        tooltip: 'leftMiddle' 
     169                                                }, 
     170                                                adjust: {x:0, y:0} 
     171                                        } 
     172                                }) 
     173                                .qtip("api").onShow = function(arg0) { 
     174                                        $('.qtip-active .button.close').button({ 
     175                                                icons: {primary: "ui-icon-close"}, 
     176                                                text: false 
     177                                        }) 
     178                                        .click(function(){ 
     179                                                blkAddAtendee.find('dd.attendee-list').qtip('destroy'); 
     180                                        }); 
     181                                         
     182                                        $('.qtip-active .button.save').button().click(function(){ 
     183                                                 
     184                                                var acl = ''; 
     185                                                $('.qtip-active').find('[type=checkbox]:checked').each(function(i, obj) { 
     186                                                        acl+= obj.value; 
     187                                                }); 
     188 
     189                                                blkAddAtendee.find('dd.attendee-list [type=checkbox]:checked').siblings('input[name="attendeeAcl[]"]').each(function(i, obj) {  
     190                                                        obj.value = 'r'+acl; 
     191                                                }).parents('li').find('.button.edit').addClass('attendee-permissions-change-button')    
     192                                                .find('.ui-icon-key').addClass('attendee-permissions-change');                
     193                                                 
     194                                                blkAddAtendee.find('dd.attendee-list [type=checkbox]').attr('checked', false); 
     195                                                 
     196                                                blkAddAtendee.find('dd.attendee-list').qtip('destroy'); 
     197                                         
     198                                        }); 
     199                                        $('.qtip-active .button.cancel').button().click(function(){ 
     200                                                blkAddAtendee.find('dd.attendee-list [type=checkbox]').attr('checked', false); 
     201                                                blkAddAtendee.find('dd.attendee-list').qtip('destroy'); 
     202                                        }); 
     203                                         
     204                                        if(aclsParticipant) 
     205                                                for(var i = 1; i < aclsParticipant.length; i++){ 
     206                                                        $('.qtip-active').find('input[name="'+acl_names[aclsParticipant.charAt(i)]+'"]').attr('checked', true); 
     207                                                } 
     208                                         
     209                                         
     210                                        $('.button').button(); 
     211                                         
     212                                }; 
     213                        }else{ 
     214                                if(!$('.new-event-win dd.attendee-list').find('[type=checkbox]:checked').length){ 
     215                                        blkAddAtendee.find('dd.attendee-list').qtip('destroy'); 
     216                                }else{ 
     217                                        $('.qtip-active .button.save .ui-button-text').html('Aplicar a todos') 
     218                                } 
     219                         
     220                        };                       
     221                }) 
     222                .addClass('tiny disable ui-button-disabled ui-state-disabled') 
     223                .removeClass('new').end() 
     224                 
     225                .filter(".open-delegate.new").click(function(){ 
     226                        if($(this).hasClass('ui-icon-triangle-1-e')){ 
     227                                $(this).removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s'); 
     228                                $(this).parents('li').find('.list-delegates').removeClass('hidden'); 
     229                        }else{ 
     230                                $(this).removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e'); 
     231                                $(this).parents('li').find('.list-delegates').addClass('hidden'); 
     232                        } 
     233                 
     234                }).removeClass('new'); 
     235         
     236         
     237                blkAddAtendee.find("li input[type=checkbox].new").click(function(){ 
     238                        if(!$('.new-event-win dd.attendee-list').find('[type=checkbox]:checked').length){ 
     239                                blkAddAtendee.find('dd.attendee-list').qtip('destroy'); 
     240                        }else{ 
     241                                checked = true; 
     242                                $(this).parents('li').find('.button.edit').click(); 
     243                                //$('.qtip-active .button.save .ui-button-text').html('Aplicar a todos') 
     244                        } 
     245                         
     246                        checked = true; 
     247                        $(this).parents('li').find('.button.edit').click(); 
     248                }).removeClass('new'); 
     249         
     250                UI.dialogs.addEvent.find('.attendees-list li').hover( 
     251                        function () { 
     252                                $(this).addClass("hover-attendee"); 
     253                                $(this).find('.button').removeClass('disable ui-button-disabled ui-state-disabled').end() 
     254                                .find('.attendee-options').addClass('hover-attendee'); 
     255                        }, 
     256                        function () { 
     257                                $(this).removeClass("hover-attendee"); 
     258                                $(this).find('.button').addClass('disable ui-button-disabled ui-state-disabled').end() 
     259                                .find('.attendee-options').removeClass('hover-attendee');; 
     260                        } 
     261                ); 
     262         
     263                 
     264        } 
    71265         
    72266        var html = DataLayer.render( path+'templates/event_add.ejs', {event:objEvent});  
     
    99293                                                                        if(clicked == 'Descartar alterações') { 
    100294                                                                                canDiscardEventDialog = true; 
     295                                                                                /** 
     296                                                                                *Remoção dos anexos do eventos caso seja cancelado a edição 
     297                                                                                */ 
     298                                                                                var ids = []; 
     299                                                                                $.each($('.attachment-list input'), function (i, input) { ids.push(input.value); }); 
     300                                                                                if(ids.length > 0) 
     301                                                                                        DataLayer.remove('attachment', {filter: ['IN', 'id', ids]}); 
     302                                                                                 
    101303                                                                                UI.dialogs.addEvent.dialog('close'); 
    102304                                                                        }else{ 
     
    256458                        canDiscardEventDialog = true; 
    257459                         
    258                         UI.dialogs.addEvent.children(".form-addevent").submit(); 
     460                        UI.dialogs.addEvent.children().find('form.form-addevent').submit(); 
    259461                        UI.dialogs.addEvent.dialog("close"); 
    260462            }).end() 
    261463                 
    262464                .children(".export").click(function(){ 
    263                         UI.dialogs.addEvent.children(".form-export").submit(); 
     465                        UI.dialogs.addEvent.children().find(".form-export").submit(); 
    264466            }); 
    265467 
     
    293495            }); 
    294496             
    295 //          UI.dialogs.addEvent.find('.button-add-attachment').click(function(){ 
    296 //                  var li_attach =  
    297 //                          '<li class="input_label">' +  
    298 //                                  '<input type="file" name="attachments[]"" />' + 
    299 //                          '</li>'; 
    300 //                  jQuery('.attachments-list').append(li_attach); 
    301 //          }); 
    302              
    303                 var attendeeHtml = DataLayer.render( path+'templates/attendee_add.ejs', {event:objEvent}); 
     497                  
     498                UI.dialogs.addEvent.find('.button.suggestion-hours').button({ 
     499                        icons: { 
     500                                primary: "ui-icon-clock" 
     501                        }, 
     502                        text: 'Sugerir horário' 
     503                }).click(function () { 
     504                        $(this).siblings('input').removeAttr('disabled') 
     505                        .end().parents().find('input[name="allDay"]').removeAttr('disabled');            
     506                }); 
     507 
     508                if(objEvent.me.id == User.me.id){ 
     509                        objEvent.me.id = DataLayer.put('participant', {user: objEvent.me.id, mail: objEvent.me.mail }); 
     510                        objEvent.organizer.id = objEvent.me.id; 
     511                } 
     512 
     513                var attendeeHtml = DataLayer.render( path+'templates/attendee_add.ejs', {event:objEvent});               
    304514         
    305515                        // load template of attendees 
    306516                        var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6').append(attendeeHtml); 
    307                          
    308                         blkAddAtendee.find('li.attendee .button').addClass('small '+ (objEvent.isOrganizer == 1 ? '' : 'hidden')).button({text:false, icons: {primary:'ui-icon-close'}}).click(function () { 
    309                                 DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val()); 
    310                                 $(this).parent().remove(); 
    311                         }); 
     517                        if(objEvent.attendee.length) 
     518                                callbackAttendee(); 
     519                        /** 
     520                                Opções de delegação do participante/organizer 
     521                        */               
     522                        blkAddAtendee.find(".button.participant-delegate").button({ 
     523                                icons: { 
     524                                        primary: "ui-icon-transferthick-e-w" 
     525                                }, 
     526                                text: false 
     527                        }).click(function () { 
     528                                if($(this).hasClass('attendee-permissions-change-button')){ 
     529                                        if(!$(this).hasClass('disable')){ 
     530                                                $(this).removeClass('attendee-permissions-change-button')    
     531                                                .find('.ui-icon-transferthick-e-w').removeClass('attendee-permissions-change').end();                
     532                                                blkAddAtendee.find('.block-add-attendee.search').addClass('hidden'); 
     533                                                blkAddAtendee.find('.block-add-attendee.search dt').html('Adicionar outros contatos'); 
     534                                        } 
     535                                }else{                                                                   
     536                                        $(this).addClass('attendee-permissions-change-button')    
     537                                        .find('.ui-icon-transferthick-e-w').addClass('attendee-permissions-change').end();                
     538                                        blkAddAtendee.find('.block-add-attendee.search dt').html('Delegar participação para'); 
     539                                        blkAddAtendee.find('.block-add-attendee.search').removeClass('hidden'); 
     540                                        blkAddAtendee.find('.block-add-attendee.search input.search').focus(); 
     541                                } 
     542                        }) 
     543                        .addClass('tiny');               
     544                         
    312545                        //show or hidden permissions attendees 
    313546                        //blkAddAtendee.find('.block-attendee-list #attendees-users li').click(show_permissions_attendees);  
     
    481714                                                        user[0].id =  DataLayer.put('participant', {user: user[0].id, isExternal: isExternal}); 
    482715                                                        blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( 
    483                                                                 DataLayer.render(path+'templates/participants_add_itemlist.ejs', user) 
     716                                                                DataLayer.render(path+'templates/participants_add_itemlist.ejs', {user:user, acl: objEvent.acl}) 
    484717                                                        ) 
    485                                                         .find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() { 
    486                                                                 DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val()); 
    487                                                                 $(this).parent().remove(); 
    488                                                         }).end() 
    489718                                                        .scrollTo('max'); 
     719                                                        callbackAttendee(); 
    490720                                                } 
    491721                                                 
     
    503733                                                  
    504734                                                blkAddAtendee.find('dd.attendee-list ul.attendee-list').append( 
    505                                                         DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail, isExternal: 1}]) 
    506                                                 ).find('.button.close').addClass('small').button({text:false, icons:{primary:'ui-icon-close'}}).click(function() { 
    507                                                         DataLayer.remove('participant', $(this).parent().find('[type=checkbox]').val()); 
    508                                                         $(this).parent().remove(); 
    509                                                 }).end() 
    510                                                 .scrollTo('max'); 
    511  
     735                                                        DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id:newAttendeeId, name: newAttendeeName, mail: newAttendeeEmail, isExternal: 1, acl: objEvent.acl}]) 
     736                                                ).scrollTo('max'); 
     737                                                callbackAttendee(); 
    512738 
    513739                                                /**  
     
    573799                                                        newAttendeeId = DataLayer.put('participant', {user: old_item.find('.id').html(), isExternal: 0}); 
    574800                                                        blkAddAtendee.find('dd.attendee-list ul.attendee-list') 
    575                                                         .append(DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id: newAttendeeId, name: old_item.find('.name').html(), mail: old_item.find('.mail').html(), isExternal: 0}])) 
    576                                                         .find('.button').addClass('small').button({text:false, icons: {primary:'ui-icon-close'}}).click(function () { 
    577                                                                 $(this).parent().remove(); 
    578                                                         }).end() 
     801                                                        .append(DataLayer.render(path+'templates/participants_add_itemlist.ejs', [{id: newAttendeeId, name: old_item.find('.name').html(), mail: old_item.find('.mail').html(), isExternal: 0, acl: objEvent.acl}])) 
    579802                                                        .scrollTo('max'); 
    580  
    581                                                         old_item.remove(); 
     803                                                        /** 
     804                                                        * Delegação de participação de um participante com permissão apenas de leitura 
     805                                                        * 
     806                                                        */ 
     807                                                        if(!objEvent.acl.organization && !objEvent.acl.write && !objEvent.acl.inviteGuests && objEvent.acl.read ){ 
     808                                                                 
     809                                                                blkAddAtendee.find('.block-add-attendee.search').addClass('hidden'); 
     810                                                                blkAddAtendee.find('.block-add-attendee.search dt').html('Adicionar outros contatos'); 
     811                                                                 
     812                                                                blkAddAtendee.find('.status option').toggleClass('hidden'); 
     813                                                                blkAddAtendee.find('option[value=5]').attr('selected','selected').trigger('change'); 
     814                                                                blkAddAtendee.find('.request-update').removeClass('hidden'); 
     815 
     816                                                                blkAddAtendee.find('dd.attendee-list ul.attendee-list li .button.close').parents('li').find('input[name="delegatedFrom[]"]').val(blkAddAtendee.find('.me input[name="attendee[]"]').val()); 
     817                                                                 
     818                                                                blkAddAtendee.find('.me .participant-delegate').addClass('disable ui-button-disabled ui-state-disabled'); 
     819                                                                blkAddAtendee.find(".button.close").button({ 
     820                                                                        icons: { 
     821                                                                                primary: "ui-icon-close" 
     822                                                                        }, 
     823                                                                        text: false 
     824                                                                }).click(function () { 
     825                                                                         
     826                                                                        $(this).parents('li').find('input[name="delegatedFrom[]"]').val(''); 
     827                                                                        blkAddAtendee.find('.request-update').addClass('hidden'); 
     828                                                                        blkAddAtendee.find('.status option').toggleClass('hidden'); 
     829                                                                        blkAddAtendee.find('option[value=1]').attr('selected','selected').trigger('change');                     
     830                                                                        blkAddAtendee.find('.me .participant-delegate').removeClass('disable ui-button-disabled ui-state-disabled attendee-permissions-change-button') 
     831                                                                        .find('.ui-icon-person').removeClass('attendee-permissions-change').end();                       
     832                                                                         
     833                                                                        DataLayer.remove('participant', $(this).parents('li').find('[type=checkbox]').val()); 
     834                                                                        $(this).parents('li').remove(); 
     835                                                                }) 
     836                                                                .addClass('tiny'); 
     837                                                        }else{ 
     838                                                                callbackAttendee(); 
     839                                                                old_item.remove(); 
     840                                                        } 
    582841                                                } 
    583842                                        }); 
     
    586845                                } 
    587846                        }); 
    588  
    589 /* 
    590                         UI.dialogs.addEvent.find('.attendees-list li').hover( 
    591                                 function () { 
    592                                         $(this).addClass("hover"); 
    593                                 }, 
    594                                 function () { 
    595                                         $(this).removeClass("hover"); 
     847                        //$('.block-add-attendee .search-result-list').selectable(); 
     848 
     849                UI.dialogs.addEvent.find('.row.fileupload-buttonbar .button').filter('.delete').button({ 
     850                        icons: { 
     851                                primary: "ui-icon-close" 
     852                        }, 
     853                                text: 'Excluir' 
     854                        }).click(function () { 
     855                                $('.row.fileupload-buttonbar .attachments-list p').remove(); 
     856                                 
     857                                var ids = []; 
     858                                $.each($('.attachment-list input'), function (i, input) { ids.push(input.value); }); 
     859                                if(ids.length > 0){ 
     860                                        DataLayer.remove('attachment', {filter: ['IN', 'id', ids]}); 
     861                                        $('.attachment-list input').remove(); 
    596862                                } 
    597                         ); 
    598 */ 
    599                         //$('.block-add-attendee .search-result-list').selectable(); 
    600  
    601                         UI.dialogs.addEvent.find('.block-attendee-list select.status').change(function(){ 
    602                                 if ($(this).val() == 'another') { 
    603         //                              jQuery('.block-attendee-list .add-attendee-search').removeClass('hidden'); 
    604                                         $(this).qtip({ 
    605                                                 show: {ready: true}, 
    606                                                 hide: false, 
    607                                                 content: { 
    608                                                         text: $('.block-attendee-list .add-attendee-search').clone().removeClass('hidden'),  
    609                                                         title: { 
    610                                                                 text:'Indique o participante',  
    611                                                                 button: '<a class="button close" href="#">close</a>' 
    612                                                         } 
    613                                                 }, 
    614                                                 style: {name: 'blue', tip: {corner: 'leftMiddle'}, border: {width: 4, radius: 8}, width: {min: 250, max:250}}, 
    615                                                 position: { 
    616                                                         corner: { 
    617                                                                 target: 'rightMiddle', 
    618                                                                 tooltip: 'leftMiddle' 
    619                                                         }, 
    620                                                         adjust: {x:0, y:0} 
    621                                                 } 
    622                                         }) 
    623                                         $(this).qtip.onShow = function() { 
    624                                                 $('.qtip .button.close').button({ 
    625                                                         icons: {primary: "ui-icon-close"}, 
    626                                                         text: false 
    627                                                 }); 
    628                                         } 
    629                                 } else { 
    630         //                              jQuery('.block-attendee-list .add-attendee-search').addClass('hidden'); 
    631                                 } 
    632                         }); 
    633                 UI.dialogs.addEvent.find(':input').change(function(event){ 
    634                         if (event.keyCode != '27' && event.keyCode != '13') 
    635                                 canDiscardEventDialog = false; 
    636                 }).keydown(function(event){ 
    637                         if (event.keyCode != '27' && event.keyCode != '13') 
    638                                 canDiscardEventDialog = false; 
     863                }).end() 
     864                .filter('.close').button({ 
     865                        icons: { 
     866                                primary: "ui-icon-close" 
     867                        }, 
     868                                text: false 
     869                        }).click(function () { 
     870                                DataLayer.remove('attachment', $(this).parents('p').find('input[name="fileId[]"]').val()); 
     871                                $(this).parents('p').remove(); 
     872                }).end() 
     873                .filter('.downlaod-archive').button({ 
     874                        icons: { 
     875                                primary: "ui-icon-arrowthickstop-1-s" 
     876                        }, 
     877                                text: false 
    639878                }); 
     879                 
     880        $('#fileupload').fileupload({ 
     881                sequentialUploads: true, 
     882                add: function (e, data) { 
     883                        if(data.files[0].size < 30000000) 
     884                                data.submit(); 
     885                }, 
     886                change: function (e, data) { 
     887                        $.each(data.files, function (index, file) { 
     888                                var attach = {}; 
     889                                attach.fileName = file.name; 
     890                                if(file.name.length > 10) 
     891                                        attach.fileName = file.name.substr(0, 6) + file.name.substr(file.name.length-4, file.name.length); 
     892                                attach.fileSize = file.size; 
     893                                if(file.size > 30000000) 
     894                                        attach.error = 'Tamanho de arquivo nao permitido!!' 
     895                                 
     896                                $('.attachments-list').append(DataLayer.render(path+'templates/attachment_add_itemlist.ejs', {file : attach})); 
     897                                 
     898                                if(file.size < 30000000){ 
     899                                        $('.fileinput-button.new').append(data.fileInput[0]).removeClass('new'); 
     900                                        $('.attachments-list').find('[type=file]').addClass('hidden'); 
     901                                         
     902                                }else 
     903                                        $('.fileinput-button.new').removeClass('new'); 
     904                                 
     905                                 
     906                                $('.attachments-list').find('.button.close').button({ 
     907                                        icons: { 
     908                                                primary: "ui-icon-close" 
     909                                        }, 
     910                                        text: false 
     911                                }).click(function(){ 
     912                                        var idAttach = $(this).parent().find('input[name="fileId[]"]').val(); 
     913                                        $('.attachment-list').find('input[value="'+idAttach+'"]') 
     914                                        $(this).parent().remove(); 
     915                                });      
     916                                 
     917                })}, 
     918                progress: function(e, data){ 
     919                        var value = parseInt(data.loaded / data.total * 100, 10); 
     920                        $('.progress.in-progress:first').removeClass('hidden') 
     921                        $('.progress.in-progress:first').progressbar({ 
     922                                value: value 
     923                        }); 
     924                         
     925                        if(value == 100){ 
     926                                $('.progress.in-progress:first').removeClass('in-progress').addClass('on-complete').fadeOut('slow'); 
     927                        } 
     928                                 
     929                }, 
     930                done: function(e, data){ 
     931                        if(!!data.result && data.result != "[]"){ 
     932                                var newAttach = jQuery.parseJSON(data.result); 
     933                                $('.attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>'); 
     934                                $('.progress.on-complete:first').removeClass('on-complete').parents('p') 
     935                                .append('<input type="hidden" name="fileId[]" value="'+newAttach['attachment'][0][0].id+'"/>') 
     936                                .find('.status-upload').addClass('ui-icon ui-icon-check'); 
     937                        }else 
     938                                $('.progress.on-complete:first').removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel'); 
     939                                 
     940                        console.log("oi doen"); 
     941                } 
     942        }); 
     943                $('.attachments-list .button').button(); 
     944                 
     945                 
     946                 
     947        $('#fileupload').bind('fileuploadstart', function () { 
     948                var widget = $(this), 
     949        progressElement = $('#fileupload-progress').fadeIn(), 
     950        interval = 500, 
     951        total = 0, 
     952        loaded = 0, 
     953        loadedBefore = 0, 
     954        progressTimer, 
     955        progressHandler = function (e, data) { 
     956            loaded = data.loaded; 
     957            total = data.total; 
     958        }, 
     959        stopHandler = function () { 
     960            widget 
     961                .unbind('fileuploadprogressall', progressHandler) 
     962                .unbind('fileuploadstop', stopHandler); 
     963            window.clearInterval(progressTimer); 
     964            progressElement.fadeOut(function () { 
     965                progressElement.html(''); 
     966            }); 
     967        }, 
     968        formatTime = function (seconds) { 
     969            var date = new Date(seconds * 1000); 
     970            return ('0' + date.getUTCHours()).slice(-2) + ':' + 
     971                ('0' + date.getUTCMinutes()).slice(-2) + ':' + 
     972                ('0' + date.getUTCSeconds()).slice(-2); 
     973        }, 
     974        formatBytes = function (bytes) { 
     975            if (bytes >= 1000000000) { 
     976                return (bytes / 1000000000).toFixed(2) + ' GB'; 
     977            } 
     978            if (bytes >= 1000000) { 
     979                return (bytes / 1000000).toFixed(2) + ' MB'; 
     980            } 
     981            if (bytes >= 1000) { 
     982                return (bytes / 1000).toFixed(2) + ' KB'; 
     983            } 
     984            return bytes + ' B'; 
     985        }, 
     986        formatPercentage = function (floatValue) { 
     987            return (floatValue * 100).toFixed(2) + ' %'; 
     988        }, 
     989        updateProgressElement = function (loaded, total, bps) { 
     990            progressElement.html( 
     991                formatBytes(bps) + 'ps | ' + 
     992                    formatTime((total - loaded) / bps) + ' | ' + 
     993                    formatPercentage(loaded / total) + ' | ' + 
     994                    formatBytes(loaded) + ' / ' + formatBytes(total) 
     995            ); 
     996        }, 
     997        intervalHandler = function () { 
     998            var diff = loaded - loadedBefore; 
     999            if (!diff) { 
     1000                return; 
     1001            } 
     1002            loadedBefore = loaded; 
     1003            updateProgressElement( 
     1004                loaded, 
     1005                total, 
     1006                diff * (1000 / interval) 
     1007            ); 
     1008        }; 
     1009                widget 
     1010                        .bind('fileuploadprogressall', progressHandler) 
     1011                        .bind('fileuploadstop', stopHandler); 
     1012                progressTimer = window.setInterval(intervalHandler, interval); 
     1013        }); 
     1014                 
     1015        UI.dialogs.addEvent.find(':input').change(function(event){ 
     1016                if (event.keyCode != '27' && event.keyCode != '13') 
     1017                        canDiscardEventDialog = false; 
     1018        }).keydown(function(event){ 
     1019                if (event.keyCode != '27' && event.keyCode != '13') 
     1020                        canDiscardEventDialog = false; 
     1021        });      
     1022                 
    6401023                 
    6411024                UI.dialogs.addEvent.dialog('open'); 
Note: See TracChangeset for help on using the changeset viewer.