Changeset 6996 for trunk/prototype/modules/calendar/js/helpers.js
- Timestamp:
- 08/10/12 19:11:37 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/modules/calendar/js/helpers.js
r6956 r6996 101 101 } 102 102 103 /* 104 function listEvents(){ 105 var list = $('.fc-header-right').find('.fc-button.fc-button-agendaDay').clone(); 103 function printNow(){ 104 105 var window_print = window.open('','ExpressoCalendar','width=800,height=600,scrollbars=yes'); 106 window_print.document.open(); 107 108 var start = $("#calendar").fullCalendar('getView').visStart.getTime()/1000; 109 var end = $("#calendar").fullCalendar('getView').visEnd.getTime()/1000; 110 var criteria = DataLayer.criteria("schedulable:calendar", {'start':start, 'end':end} ); 111 112 var data = DataLayer.get("schedulable:print", criteria); 113 114 if($("#calendar").fullCalendar('getView').name == "month"){ 115 window_print.document.write(DataLayer.render('templates/calendar_month_print.ejs', { 116 'InfoPage' : $("#calendar").fullCalendar('getView').title, 117 'days' : data 118 } )); 119 } 120 if($("#calendar").fullCalendar('getView').name == "agendaDay"){ 121 window_print.document.write(DataLayer.render('templates/calendar_day_print.ejs', { 122 'InfoPage' : $("#calendar").fullCalendar('getView').title, 123 'days' : data 124 } )); 125 } 126 if($("#calendar").fullCalendar('getView').name == "agendaWeek"){ 127 window_print.document.write(DataLayer.render('templates/calendar_week_print.ejs', { 128 'InfoPage' : $("#calendar").fullCalendar('getView').title, 129 'days' : data 130 })); 131 132 var aux = 0; 133 setTimeout(function(){$(window_print.document).find(".all-day").each(function(){ 134 if($(this).height() > aux) 135 aux = $(this).height(); 136 }); 137 $(window_print.document).find(".all-day").each(function(){ 138 $(this).height(aux); 139 }); 140 $(window_print.document).find(".all-day-line .write").height(aux); 141 aux = 0; 142 },20); 143 } 144 if($("#calendar").fullCalendar('getView').name == "year"){ 145 window_print.document.write(DataLayer.render('templates/calendar_year_print.ejs', { 146 'html' : $('#calendar .fc-content').html(), 147 'header': $('#calendar').find('.fc-header-center h2').text() 148 } )); 149 } 150 window_print.document.close(); 151 setTimeout(window_print.print(), 300); 152 } 153 154 function printEvents(){ 155 //var html = DataLayer.render( path + 'templates/attendee_permissions.ejs', {} ); 156 var print = $('.fc-header-right').find('.fc-button.fc-button-agendaDay').clone(); 157 106 158 $('.fc-header-right').find('.fc-button-year').toggleClass('fc-corner-right'); 107 list.addClass('fc-corner-right'); 108 list.addClass('fc-button-listagem'); 109 list.removeClass('fc-button-agendaDay'); 110 list.removeClass('fc-corner-left'); 111 list.find('.fc-button-content').html('Listagem'); 112 $('.fc-header-right').append(list); 113 } 114 */ 159 print.addClass('fc-corner-right'); 160 print.addClass('fc-button-print'); 161 print.removeClass('fc-button-agendaDay'); 162 print.removeClass('fc-corner-left'); 163 print.find('.fc-button-content').html('Imprimir'); 164 $('.fc-header-right').append(print); 165 $('.fc-button-print').click(function(){ 166 alert('A tela de impressão será melhor visualizada com a preferência "Paisagem" do seu browser selecionada.'); 167 printNow(); 168 }); 169 } 115 170 116 171 /* … … 122 177 function eventDetails( objEvent, decoded, path, isMail, repeat) 123 178 { 179 180 $('.qtip.qtip-blue').remove(); 181 124 182 attendees = {}; 125 183 … … 399 457 modal:true, 400 458 autoOpen: false, 401 width:70 2,459 width:701, 402 460 position: 'center', 403 461 close: function(event, ui) { … … 936 994 // load template of attendees 937 995 var blkAddAtendee = UI.dialogs.addEvent.find('#calendar_addevent_details6').append(attendeeHtml); 938 if(objEvent.attendee.length) 939 callbackAttendee(); 996 if(objEvent.attendee.length) 997 callbackAttendee(); 940 998 /** 941 942 999 Opções de delegação do participante/organizer 1000 */ 943 1001 blkAddAtendee.find(".button.participant-delegate").button({ 944 1002 icons: { … … 968 1026 969 1027 UI.dialogs.addEvent.find(".attendee-list-add .add-attendee-input input").Watermark("digite um email para convidar"); 970 /* Trata a edição de um novo participante adicionado971 * 972 1028 /* 1029 * Trata a edição de um novo participante adicionado 1030 */ 973 1031 var hasNewAttendee = false; 974 1032 … … 978 1036 979 1037 blkAddAtendee.find('.attendee-list-add .add-attendee-input input').keydown(function(event) { 980 981 1038 if (event.keyCode == '13' && $(this).val() != '' || (event.keyCode == undefined && $(this).val() != '')) { 982 1039 Encoder.EncodeType = "entity"; … … 990 1047 991 1048 /** 992 993 1049 * email válido? 1050 */ 994 1051 info.match(/^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/) ? 995 1052 newAttendeeEmail = info : newAttendeeName = info; 996 1053 997 1054 /** 998 999 1000 1001 1002 1003 1004 1005 1055 * 1) busca no banco para saber se o usuário já existe 1056 * 1.1) se existe, atualiza as info na lista de participantes e nao abre o tooltip 1057 * 1.2) se não existe 1058 * a) salva como novo usuario externo no banco (apenas com email) 1059 * b) exibe tooltip pedindo o nome 1060 * c) se o usuário preenche tooltip e salva, atualiza com o nome o usuário recém criado 1061 * d) se o usuário cancela o tooltip, fica o usuário salvo apenas com email e sem nome 1062 */ 1006 1063 1007 1064 var user = DataLayer.get('user', ["=", "mail", $(this).val()]); … … 1012 1069 1013 1070 /** 1014 1015 1071 * guarda o último tooltip aberto referente à lista de participantes 1072 */ 1016 1073 lastEditAttendeeToolTip = []; 1017 1074 1018 1075 /** 1019 1020 1076 * Valida email e salva um participante externo 1077 */ 1021 1078 var saveContact = function() { 1022 1079 Encoder.EncodeType = "entity"; … … 1192 1249 $(this).val(''); 1193 1250 1194 } else if (!skipAddNewLine) { 1251 } else if (!skipAddNewLine) { 1195 1252 /** 1196 1197 1198 1253 * a) salva como novo usuario externo no banco (apenas com email) e... 1254 * adiciona novo contato externo à lista de convidados 1255 */ 1199 1256 1200 1257 userId = DataLayer.put('user', { … … 1285 1342 1286 1343 /** 1287 1288 1344 * Trata a busca de usuários para adição de participantes 1345 */ 1289 1346 blkAddAtendee.find('.add-attendee-search .ui-icon-search').click(function(event) { 1290 1347 blkAddAtendee.find('.add-attendee-search input').keydown(); … … 1374 1431 } 1375 1432 }); 1433 1376 1434 //$('.block-add-attendee .search-result-list').selectable(); 1377 1435 … … 1395 1453 }); 1396 1454 }); 1397 $('.attachment-list input').remove(); 1398 $('.row.fileupload-buttonbar .attachments-list p').remove(); 1455 $('div.new-event-win .attachment-list input').remove(); 1456 $('div.new-event-win .row.fileupload-buttonbar .attachments-list p').remove(); 1457 $('div.new-event-win .btn-danger.delete').addClass('hidden'); 1399 1458 } 1400 1459 }}); … … 1415 1474 text: false 1416 1475 }); 1417 var maxSizeFile = 2000000; 1418 $('#fileupload').fileupload({ 1419 sequentialUploads: true, 1420 add: function (e, data) { 1421 if(data.files[0].size < maxSizeFile) 1422 data.submit(); 1423 }, 1424 change: function (e, data) { 1425 $.each(data.files, function (index, file) { 1426 var attach = {}; 1427 attach.fileName = file.name; 1428 var ext = file.name.split('.'); 1429 if(file.name.length > 10) 1430 attach.fileName = ext.length == 1 ? file.name.substr(0, 10) : file.name.substr(0, 6) + '.' + ext[ext.length -1]; 1431 attach.fileSize = formatBytes(file.size); 1432 if(file.size > maxSizeFile) 1433 attach.error = 'Tamanho de arquivo nao permitido!!' 1434 1435 $('.attachments-list').append(DataLayer.render(path+'templates/attachment_add_itemlist.ejs', { 1436 file : attach 1437 })); 1438 1439 if(file.size < maxSizeFile){ 1440 $('.fileinput-button.new').append(data.fileInput[0]).removeClass('new'); 1441 $('.attachments-list').find('[type=file]').addClass('hidden'); 1442 1443 }else 1444 $('.fileinput-button.new').removeClass('new'); 1445 1446 1447 $('.attachments-list').find('.button.close').button({ 1448 icons: { 1449 primary: "ui-icon-close" 1450 }, 1451 text: false 1452 }).click(function(){ 1453 var idAttach = $(this).parent().find('input[name="fileId[]"]').val(); 1454 $('.attachment-list').find('input[value="'+idAttach+'"]') 1455 $(this).parent().remove(); 1456 }); 1457 1458 }) 1459 }, 1460 done: function(e, data){ 1461 var currentUpload = $('.progress.after-upload:first').removeClass('after-upload').addClass('on-complete').hide(); 1462 1463 if(!!data.result && data.result != "[]"){ 1464 var newAttach = (attch = jQuery.parseJSON(data.result)) ? attch : jQuery.parseJSON(data.result[0].activeElement.childNodes[0].data); 1465 $('.attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>'); 1466 currentUpload.removeClass('on-complete').parents('p') 1467 .append('<input type="hidden" name="fileId[]" value="'+newAttach['attachment'][0][0].id+'"/>') 1468 .find('.status-upload').addClass('ui-icon ui-icon-check'); 1469 }else 1470 currentUpload.removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel'); 1471 } 1472 }); 1473 $('.attachments-list .button').button(); 1474 1475 if(!!window.FormData) 1476 $('#fileupload').bind('fileuploadstart', function () { 1477 var widget = $(this), 1478 progressElement = $('#fileupload-progress').fadeIn(), 1479 interval = 500, 1480 total = 0, 1481 loaded = 0, 1482 loadedBefore = 0, 1483 progressTimer, 1484 progressHandler = function (e, data) { 1485 loaded = data.loaded; 1486 total = data.total; 1487 }, 1488 stopHandler = function () { 1489 widget 1490 .unbind('fileuploadprogressall', progressHandler) 1491 .unbind('fileuploadstop', stopHandler); 1492 window.clearInterval(progressTimer); 1493 progressElement.fadeOut(function () { 1494 progressElement.html(''); 1495 }); 1496 }, 1497 formatTime = function (seconds) { 1498 var date = new Date(seconds * 1000); 1499 return ('0' + date.getUTCHours()).slice(-2) + ':' + 1500 ('0' + date.getUTCMinutes()).slice(-2) + ':' + 1501 ('0' + date.getUTCSeconds()).slice(-2); 1502 }, 1503 /* formatBytes = function (bytes) { 1504 if (bytes >= 1000000000) { 1505 return (bytes / 1000000000).toFixed(2) + ' GB'; 1506 } 1507 if (bytes >= 1000000) { 1508 return (bytes / 1000000).toFixed(2) + ' MB'; 1509 } 1510 if (bytes >= 1000) { 1511 return (bytes / 1000).toFixed(2) + ' KB'; 1512 } 1513 return bytes + ' B'; 1514 },*/ 1515 formatPercentage = function (floatValue) { 1516 return (floatValue * 100).toFixed(2) + ' %'; 1517 }, 1518 updateProgressElement = function (loaded, total, bps) { 1519 progressElement.html( 1520 formatBytes(bps) + 'ps | ' + 1521 formatTime((total - loaded) / bps) + ' | ' + 1522 formatPercentage(loaded / total) + ' | ' + 1523 formatBytes(loaded) + ' / ' + formatBytes(total) 1524 ); 1525 }, 1526 intervalHandler = function () { 1527 var diff = loaded - loadedBefore; 1528 if (!diff) { 1529 return; 1530 } 1531 loadedBefore = loaded; 1532 updateProgressElement( 1533 loaded, 1534 total, 1535 diff * (1000 / interval) 1536 ); 1537 }; 1538 widget 1539 .bind('fileuploadprogressall', progressHandler) 1540 .bind('fileuploadstop', stopHandler); 1541 progressTimer = window.setInterval(intervalHandler, interval); 1542 }); 1476 1477 extendsFileupload('event', path); 1543 1478 1544 1479 if(objEvent.isShared){ … … 1557 1492 } 1558 1493 1559 disponibily(objEvent, path, attendees );1494 disponibily(objEvent, path, attendees, 'event'); 1560 1495 1561 1496 /*Seleciona a agenda padrão para criação de um evento*/ … … 1573 1508 1574 1509 UI.dialogs.addEvent.dialog('open'); 1575 //$('[href="#calendar_addevent_details7"]').trigger('click'); 1576 //$('[href="#calendar_addevent_details2"]').trigger('click'); 1510 1577 1511 } 1578 1512 … … 1691 1625 1692 1626 1693 function add_tab_configure_calendar(calendar )1627 function add_tab_configure_calendar(calendar, type) 1694 1628 { 1629 $('.qtip.qtip-blue').remove(); 1630 1695 1631 var calendars = []; 1696 1632 var signatures = []; … … 1698 1634 var calendarAlarms = []; 1699 1635 1700 for (var i=0; i<Calendar.signatures.length; i++) { 1701 calendars[i] = Calendar.signatures[i].calendar; 1702 signatures[i] = Calendar.signatures[i]; 1703 signatures[i].numberDefaultAlarm = signatures[i].defaultAlarms != '' ? signatures[i].defaultAlarms.length: 0; 1704 if (calendar && calendars[i].id == calendar) 1705 previewActiveCalendarConf = i; 1706 } 1707 1708 if(!(document.getElementById('configure_tab'))) 1636 for (var i=0; i<Calendar.signatures.length; i++) { 1637 if(parseInt(Calendar.signatures[i].calendar.type) == type){ 1638 calendars.push(Calendar.signatures[i].calendar); 1639 signatures.push(Calendar.signatures[i]); 1640 length = signatures.length - 1; 1641 signatures[length].numberDefaultAlarm = signatures[length].defaultAlarms != '' ? signatures[length].defaultAlarms.length: 0; 1642 if (calendar && calendars[length].id == calendar) 1643 previewActiveCalendarConf = length; 1644 } 1645 } 1646 var tab_selector = ['configure_tab', 'configure_tab_group']; 1647 if(!(document.getElementById(tab_selector[type]))) 1709 1648 { 1710 1649 $('.positionHelper').css('display', 'none'); 1711 1650 $('.cal-list-options-btn').removeClass('fg-menu-open ui-state-active'); 1712 var tab_title = "Configurações de agendas"; 1713 $tabs.tabs( "add", "#configure_tab", tab_title ); 1651 if(type == 0){ 1652 var tab_title = "Configurações de agendas"; 1653 }else{ 1654 var tab_title = "Configurações de Grupos"; 1655 } 1656 $tabs.tabs( "add", "#"+tab_selector[type], tab_title ); 1714 1657 1715 1658 var dataColorPicker = { … … 1734 1677 DataLayer.render( 'templates/configure_calendars_itemlist.ejs', { 1735 1678 user:User, 1679 type:0, 1736 1680 calendar:calendars[nowActive], 1737 1681 signature:signatures[nowActive] 1738 1682 }, function( form_template ){ 1739 var form_content = jQuery(' .accordion-user-calendars .ui-accordion-content').eq(nowActive).html( form_template ).find('form');1683 var form_content = jQuery('#'+tab_selector[type]+' .accordion-user-calendars .ui-accordion-content').eq(nowActive).html( form_template ).find('form'); 1740 1684 form_content.find('.preferences-alarms-list .button').button({ 1741 1685 text:false, … … 1756 1700 1757 1701 form_content.find('.button-add-alarms').click(function(){ 1758 DataLayer.render( 'templates/alarms_add_itemlist.ejs', { }, function( template ){1702 DataLayer.render( 'templates/alarms_add_itemlist.ejs', {type: 0}, function( template ){ 1759 1703 jQuery('.preferences-alarms-list').append(template) 1760 1704 .find('li:last label:eq(0)').remove().end() … … 1862 1806 DataLayer.render( 'templates/configure_calendars.ejs', { 1863 1807 user:User, 1808 type: 0, 1864 1809 calendars:calendars, 1865 1810 signatures:signatures 1866 1811 }, function( template ){ 1867 var template_content = jQuery('# configure_tab').html( template ).find('.configure-calendars-win');1812 var template_content = jQuery('#'+tab_selector[type]).html( template ).find('.configure-calendars-win'); 1868 1813 template_content.find('.button').button().filter('.save').click(function(evt){ 1869 1814 if(calendarAlarms.length) 1870 1815 DataLayer.removeFilter('calendarSignatureAlarm', {filter: ['IN','id', calendarAlarms]}); 1871 1816 template_content.find('form').submit(); 1872 $tabs.tabs( "remove", "# configure_tab");1817 $tabs.tabs( "remove", "#"+tab_selector[type]); 1873 1818 DataLayer.commit( false, false, function( received ){ 1874 1819 delete Calendar.currentViewKey; … … 1879 1824 Calendar.load(); 1880 1825 }).end().filter('.cancel').click(function(evt){ 1881 $tabs.tabs( "remove", "# configure_tab");1826 $tabs.tabs( "remove", "#"+tab_selector[type]); 1882 1827 }); 1883 1828 … … 1905 1850 $('.positionHelper').css('display','none'); 1906 1851 $('.cal-list-options-btn').removeClass('fg-menu-open ui-state-active'); 1907 $tabs.tabs("select", "# configure_tab");1852 $tabs.tabs("select", "#"+tab_selector[type]); 1908 1853 $('.accordion-user-calendars').accordion( "activate" , previewActiveCalendarConf ); 1909 1854 … … 1913 1858 } 1914 1859 1915 function getSelectedCalendars( reverse ){ 1860 function getSelectedCalendars( reverse, type ){ 1861 var selector = ""; 1862 if(type == 0) 1863 selector = ".my-calendars"; 1864 if(type == 1) 1865 selector = ".my-groups-task"; 1916 1866 var selecteds = {}; 1917 1867 var cont = 0; 1918 1868 jQuery(function() { 1919 jQuery( ".my-calendars.calendar-view").each(function(i, obj) {1869 jQuery(selector+" .calendar-view").each(function(i, obj) { 1920 1870 var check_box = obj; 1921 1871 if( reverse ? !check_box.checked : check_box.checked ) { … … 1975 1925 1976 1926 function remove_event(eventId, idCalendar){ 1977 $.Zebra_Dialog('Tem certeza que deseja excluir o evento?', {1927 $.Zebra_Dialog('Tem certeza que deseja excluir?', { 1978 1928 'type': 'question', 1979 1929 'overlay_opacity': '0.5', … … 2029 1979 2030 1980 2031 function remove_calendar( ){1981 function remove_calendar(type){ 2032 1982 /* Pode ser assim $('.cal-list-options-btn.ui-state-active').attr('class').replace(/[a-zA-Z-]+/g, ''); */ 2033 $.Zebra_Dialog('Todos os eventos desta agenda serão removidos. Deseja prosseguir com a operação?', { 1983 if(!!parseInt(type)) 1984 var title = 'Todas as tarefas deste grupo serão removidas. Deseja prosseguir com a operação?'; 1985 else 1986 var title = 'Todos os eventos desta agenda serão removidos. Deseja prosseguir com a operação?'; 1987 $.Zebra_Dialog(title, { 2034 1988 'type': 'question', 2035 1989 'overlay_opacity': '0.5', … … 2047 2001 delete Calendar.currentViewKey; 2048 2002 Calendar.load(); 2049 refresh_calendars( );2003 refresh_calendars(type); 2050 2004 }); 2051 2005 } … … 2056 2010 } 2057 2011 2058 function refresh_calendars( ){2012 function refresh_calendars(type){ 2059 2013 2060 2014 var colorsSuggestions = colors_suggestions(); … … 2091 2045 }); 2092 2046 } 2047 2093 2048 doMenu(); 2049 var currentToolTip = null; 2094 2050 $('#divAppbox').on('scroll',function(){ 2095 2051 if ($('.cal-list-options-btn.fg-menu-open.ui-state-active')){ 2096 2052 var offset = $('.cal-list-options-btn.fg-menu-open.ui-state-active').offset(); 2097 2053 if (offset) 2098 2054 $('.positionHelper').css('top',offset.top); 2099 2055 } 2056 2100 2057 if ($('.button.config-menu.fg-menu-open')){ 2101 2058 var offset = $('.button.config-menu.fg-menu-open').offset(); 2102 2059 if (offset) 2103 2060 $('.positionHelper').css('top',offset.top); 2104 2061 } 2062 2063 2064 if ($(".new-group.qtip-active").length || $(".new-calendar.qtip-active").length) 2065 $('.qtip-active').css('top',currentToolTip.offset().top - 50); 2066 2105 2067 }); 2068 2106 2069 $('ul.list-calendars .cal-list-options-btn').on('click',function(){doMenu();}); 2107 2070 2071 2072 /***************************************New Calendar***************************************/ 2108 2073 meu_container.find(".button.new-calendar").button({ 2109 2074 icons: { … … 2112 2077 text: false 2113 2078 }).click(function () { 2114 2115 if( $('.qtip.qtip-blue.qtip-active').val() !== ''){ 2116 $(this).qtip({ 2117 show: { 2118 ready: true, 2119 solo: true, 2120 when: { 2121 event: 'click' 2122 } 2123 }, 2124 hide: false, 2125 content: { 2126 text: $('<div></div>').html( DataLayer.render( 'templates/calendar_quick_add.ejs', {} ) ), 2127 title: { 2128 text:'Nova Agenda', 2129 button: '<a class="button close" href="#">close</a>' 2130 } 2131 }, 2132 style: { 2133 name: 'blue', 2134 tip: { 2135 corner: 'leftMiddle' 2136 }, 2137 border: { 2138 width: 4, 2139 radius: 8 2140 }, 2141 width: { 2142 min: 230, 2143 max:230 2144 } 2145 }, 2146 position: { 2147 corner: { 2148 target: 'rightMiddle', 2149 tooltip: 'leftMiddle' 2150 }, 2151 adjust: { 2152 x:0, 2153 y:-12 2154 } 2155 } 2156 }) 2157 .qtip("api").onShow = function(arg0) { 2158 $('.qtip-active .button.close').button({ 2159 icons: { 2160 primary: "ui-icon-close" 2161 }, 2162 text: false 2163 }) 2164 .click(function(){ 2165 meu_container.find(".button.new-calendar").qtip('destroy'); 2166 }); 2167 //TODO emplementar tratamento de duplicação de valores no location 2168 $('.qtip-active .button.save').button().click(function(){ 2169 for(var i = 0; i < Calendar.calendars.length; i++){ 2170 if(Calendar.calendars[i].location == ( User.me.uid + '/' + $('.qtip-active input').val())){ 2171 $.Zebra_Dialog('O nome desta agenda já está sendo utilizada em uma Url de outra agenda. Por favor, informe outro nome para agenda.',{ 2172 'overlay_opacity': '0.5', 2173 'type': 'warning' 2174 }); 2175 meu_container.find(".button.new").qtip('destroy'); 2176 return; 2177 } 2178 } 2079 currentToolTip = $(this); 2080 var typeCalendar = !!parseInt($(this).attr('class').match(/[0-9]+/g)) ? 2081 {type: 'new-group', title: 'Novo Grupo', typeValue: 1, prompt: 'Nome do grupo'} : 2082 {type: 'new-calendar', title: 'Nova Agenda', typeValue: 0, prompt: 'Nome da agenda'} 2083 2084 if(!$('.qtip.qtip-blue.qtip-active.'+typeCalendar.type).length){ 2085 2086 $('.qtip.qtip-blue').remove(); 2087 2088 $(this).qtip({ 2089 show: { 2090 ready: true, 2091 solo: true, 2092 when: { 2093 event: 'click' 2094 } 2095 }, 2096 hide: false, 2097 content: { 2098 text: $('<div></div>').html( DataLayer.render( 'templates/calendar_quick_add.ejs', {} ) ), 2099 title: { 2100 text: typeCalendar.title, 2101 button: '<a class="button close" href="#">close</a>' 2102 } 2103 }, 2104 style: { 2105 name: 'blue', 2106 tip: { 2107 corner: 'leftMiddle' 2108 }, 2109 border: { 2110 width: 4, 2111 radius: 8 2112 }, 2113 width: { 2114 min: 230, 2115 max:230 2116 } 2117 }, 2118 position: { 2119 corner: { 2120 target: 'rightMiddle', 2121 tooltip: 'leftMiddle' 2122 }, 2123 adjust: { 2124 x:0, 2125 y: -12 2126 2127 } 2128 } 2129 }) 2130 .qtip("api").onShow = function(arg0) { 2179 2131 2180 var selected; 2181 var color = $('.cal-colors-options-btn').each(function(index){ 2182 if ($(this).is('.color-selected')) 2183 selected = index; 2184 }); 2185 DataLayer.put( "calendarSignature", { 2186 user: User.me.id, 2187 calendar: { 2188 name: Encoder.htmlEncode($('.qtip-active input').val()), 2189 timezone: User.preferences.timezone 2190 }, 2191 isOwner: 1, 2192 fontColor: colorsSuggestions[selected]['font'].substring(1) , 2193 backgroundColor: colorsSuggestions[selected]['background'].substring(1) , 2194 borderColor: colorsSuggestions[selected]['border'].substring(1) 2195 }); 2196 DataLayer.commit( false, false, function( received ){ 2197 delete Calendar.currentViewKey; 2198 Calendar.load(); 2199 refresh_calendars(); 2200 }); 2201 meu_container.find(".button.new").qtip('destroy'); 2202 }); 2203 2204 $('.qtip-active .button.cancel').button().click(function(){ 2205 meu_container.find(".button.new").qtip('destroy'); 2206 }); 2207 2208 $(".qtip-active input").Watermark("Nome da agenda"); 2209 2210 $('.qtip-active').keydown(function(event) { 2211 if (event.keyCode == '27') { 2212 meu_container.find(".button.new").qtip('destroy'); 2213 } 2214 }); 2215 2216 $('.colors-options').prepend(buttons_colors); 2217 $('.colors-options .signed-cal-colors-options-btn-0').addClass('color-selected'); 2218 2219 var buttons = $('.cal-colors-options-btn').button(); 2220 2221 buttons.click(function(){ 2222 buttons.removeClass('color-selected'); 2223 $(this).addClass('color-selected'); 2224 }); 2225 } 2226 } 2132 $('.qtip-active .button.close').button({ 2133 icons: { 2134 primary: "ui-icon-close" 2135 }, 2136 text: false 2137 }) 2138 .click(function(){ 2139 $('.qtip.qtip-blue').remove(); 2140 }); 2141 2142 $('.qtip-active').addClass(typeCalendar.type); 2143 2144 $('.qtip-active .button.save').button().click(function(){ 2145 if(!typeCalendar.typeValue) 2146 for(var i = 0; i < Calendar.calendars.length; i++){ 2147 if(Calendar.calendars[i].location == ( User.me.uid + '/' + $('.qtip-active input').val())){ 2148 $.Zebra_Dialog('O nome desta agenda já está sendo utilizada em uma Url de outra agenda. Por favor, informe outro nome para agenda.',{ 2149 'overlay_opacity': '0.5', 2150 'type': 'warning' 2151 }); 2152 $('.qtip.qtip-blue').remove(); 2153 return; 2154 } 2155 } 2156 2157 var selected; 2158 var color = $('.cal-colors-options-btn').each(function(index){ 2159 if ($(this).is('.color-selected')) 2160 selected = index; 2161 }); 2162 DataLayer.put( "calendarSignature", { 2163 user: User.me.id, 2164 calendar: { 2165 name: Encoder.htmlEncode($('.qtip-active input').val()), 2166 timezone: User.preferences.timezone, 2167 type: typeCalendar.typeValue 2168 }, 2169 isOwner: 1, 2170 fontColor: colorsSuggestions[selected]['font'].substring(1) , 2171 backgroundColor: colorsSuggestions[selected]['background'].substring(1) , 2172 borderColor: colorsSuggestions[selected]['border'].substring(1) 2173 }); 2174 DataLayer.commit( false, false, function( received ){ 2175 delete Calendar.currentViewKey; 2176 Calendar.load(); 2177 refresh_calendars(); 2178 }); 2179 $('.qtip.qtip-blue').remove(); 2180 }); 2181 2182 $('.qtip-active .button.cancel').button().click(function(){ 2183 meu_container.find(".button.new").qtip('destroy'); 2184 }); 2185 2186 $(".qtip-active input").Watermark(typeCalendar.prompt); 2187 2188 $('.qtip-active').keydown(function(event) { 2189 if (event.keyCode == '27') 2190 meu_container.find(".button.new").qtip('destroy'); 2191 }); 2192 2193 $('.colors-options').prepend(buttons_colors); 2194 $('.colors-options .signed-cal-colors-options-btn-0').addClass('color-selected'); 2195 2196 var buttons = $('.cal-colors-options-btn').button(); 2197 2198 buttons.click(function(){ 2199 buttons.removeClass('color-selected'); 2200 $(this).addClass('color-selected'); 2201 }); 2202 } 2203 } 2227 2204 }); 2228 2205 2229 2206 $("img.cal-list-img").click(function(evt) { 2230 $(".cal-list-options_1").toggleClass( "hidden" );2207 $(".cal-list-options_1").toggleClass( "hidden" ); 2231 2208 }); 2232 2209 2210 $(".my-groups-task a.title-my-calendars").click(function() { 2211 $(".my-groups-task ul.my-list-calendars").toggleClass("hidden") 2212 $('.my-groups-task .status-list').toggleClass("ui-icon-triangle-1-s"); 2213 $('.my-groups-task .status-list').toggleClass("ui-icon-triangle-1-e"); 2214 }); 2215 2233 2216 $(".my-calendars a.title-my-calendars").click(function() { 2234 $(".my-calendars ul.my-list-calendars").toggleClass("hidden")2235 $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-s");2236 $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-e");2217 $(".my-calendars ul.my-list-calendars").toggleClass("hidden") 2218 $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-s"); 2219 $('.my-calendars .status-list').toggleClass("ui-icon-triangle-1-e"); 2237 2220 }); 2238 2221 2239 2222 $(".signed-calendars a.title-signed-calendars").click(function() { 2240 $(".signed-calendars ul.signed-list-calendars").toggleClass( "hidden");2223 $(".signed-calendars ul.signed-list-calendars").toggleClass( "hidden"); 2241 2224 }); 2242 2225 … … 2270 2253 2271 2254 $('.calendar-view').click(function(evt){ 2272 if($tabs.tabs('option' ,'selected') == 1){2273 pageselectCallback('', 0 );2255 if($tabs.tabs('option' ,'selected') != 0){ 2256 pageselectCallback('', 0, false, type); 2274 2257 } 2275 2258 … … 2285 2268 } 2286 2269 2287 function add_events_list(keyword )2270 function add_events_list(keyword, type) 2288 2271 { 2289 2272 var tab_title = ""; 2290 2273 if (keyword){ 2291 if(keyword.length < 10) 2292 tab_title = keyword; 2293 else 2294 tab_title = keyword.substr(0,10) + '..."'; 2274 type = 2; 2275 if(keyword.length < 10) 2276 tab_title = keyword; 2277 else 2278 tab_title = keyword.substr(0,10) + '..."'; 2295 2279 }else{ 2296 tab_title = "Lista de eventos"; 2297 } 2280 if(type){ 2281 if(!!parseInt(type)) 2282 tab_title = "Lista de tarefas"; 2283 else 2284 tab_title = "Lista de eventos"; 2285 } 2286 } 2287 var tab_selector = ['tab_events_list_', 'tab_tasks_list_', 'tab_all_list_']; 2298 2288 keyword = ( keyword || '' ).replace( /\s+/g, "_" ); 2299 2289 2300 if(!(document.getElementById( 'tab_events_list_'+ (Base64.encode(keyword)).replace(/[^\w\s]/gi, "") )))2290 if(!(document.getElementById(tab_selector[type] + (Base64.encode(keyword)).replace(/[^\w\s]/gi, "") ))) 2301 2291 { 2302 2292 Encoder.EncodeType = "entity"; 2303 $tabs.tabs( "add", "# tab_events_list_"+ (Base64.encode(keyword)).replace(/[^\w\s]/gi, ""), Encoder.htmlEncode(tab_title) );2293 $tabs.tabs( "add", "#"+tab_selector[type] + (Base64.encode(keyword)).replace(/[^\w\s]/gi, ""), Encoder.htmlEncode(tab_title) ); 2304 2294 } 2305 2295 else /* Tab already opened */ 2306 2296 { 2307 $tabs.tabs("option", "selected", 2);2308 2309 2310 pageselectCallback(keyword, 0 ); // load page 1 and insert data on event_list.ejs2297 //$tabs.tabs("option", "selected", 2); 2298 } 2299 2300 pageselectCallback(keyword, 0, false, type); // load page 1 and insert data on event_list.ejs 2311 2301 2312 2302 $('.preferences-win.active .button.save, .preferences-win.active .button.cancel, .preferences-win.active .button.import, .preferences-win.active .button.export').button(); … … 2328 2318 if(paginator.indexOf('next') > 0){ 2329 2319 if(parseInt($(currentView+' [name = results]').val()) > 25) 2330 pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) +1) );2320 pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) +1), false, 2); 2331 2321 }else{ 2332 2322 if(parseInt($(currentView+' [name = page_index]').val()) > 0) 2333 pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) -1) );2323 pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) -1), false, 2); 2334 2324 } 2335 2325 }); … … 2369 2359 } 2370 2360 2371 function paginatorList(currentView, view ){2372 $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>'+mountTitleList( parseInt($( '[name = page_index]').val()),view)+'</h2>');2361 function paginatorList(currentView, view, type){ 2362 $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>'+mountTitleList( parseInt($(currentView+' [name = page_index]').val()),view)+'</h2>'); 2373 2363 $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right .fc-button').removeClass('fc-state-active') 2374 2364 if(view == 'basicDay') … … 2390 2380 var goView = $(this).attr('class'); 2391 2381 if(goView.indexOf('agendaDay') > 0) 2392 pageselectCallback($(currentView+' [name = keyword]').val(), 0, ' ', 'agendaDay');2382 pageselectCallback($(currentView+' [name = keyword]').val(), 0, 'agendaDay', type); 2393 2383 else if(goView.indexOf('month') > 0) 2394 pageselectCallback($(currentView+' [name = keyword]').val(), 0, ' ', 'month');2384 pageselectCallback($(currentView+' [name = keyword]').val(), 0, 'month', type); 2395 2385 else if(goView.indexOf('year') > 0) 2396 pageselectCallback($(currentView+' [name = keyword]').val(), 0, ' ', 'year');2386 pageselectCallback($(currentView+' [name = keyword]').val(), 0, 'year', type); 2397 2387 else if(goView.indexOf('agendaWeek') > 0) 2398 pageselectCallback($(currentView+' [name = keyword]').val(), 0, ' ', 'agendaWeek');2388 pageselectCallback($(currentView+' [name = keyword]').val(), 0, 'agendaWeek', type); 2399 2389 2400 2390 }); … … 2412 2402 var paginator = $(this).attr('class'); 2413 2403 if(paginator.indexOf('next') > 0) 2414 pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($( '[name = page_index]').val())) +1), '', view);2404 pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) +1), view, type); 2415 2405 else 2416 pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($( '[name = page_index]').val())) -1), '', view);2406 pageselectCallback($(currentView+' [name = keyword]').val(), ((parseInt($(currentView+' [name = page_index]').val())) -1), view, type); 2417 2407 }); 2418 2408 } 2419 2409 2420 function paginatorListEvent(currentView, typeView, view){ 2410 function printEventList(view){ 2411 $('.fc-button-print.print-list-events').click(function(){ 2412 var window_print = window.open('','ExpressoCalendar','width=800,height=600,scrollbars=yes'); 2413 var listEvents = $(view).clone(); 2414 listEvents.find('.fc-button').remove(); 2415 listEvents.find('.details-event-list').remove(); 2416 listEvents.find('.list-events-paginator').attr( "align" , "center" ); 2417 listEvents = listEvents.html(); 2418 type = $(this).parents('.ui-tabs-panel').attr("id").split("_")[1]; 2419 var data = { 2420 type : type == "tasks" ? "task-list" : ( type == "events" ? "event-list" : "search"), 2421 html : listEvents 2422 } 2423 window_print.document.open(); 2424 window_print.document.write(DataLayer.render('templates/calendar_list_print.ejs', data)); 2425 window_print.document.close(); 2426 window_print.print(); 2427 }); 2428 } 2429 2430 function paginatorListEvent(currentView, typeView, view, type){ 2421 2431 if(!!$(currentView).find('.fc-calendar').length) 2422 2432 return; … … 2430 2440 $(currentView+' .events-list.events-list-win.active .fc-header .fc-header-center').addClass('list-events-paginator'); 2431 2441 $(currentView+' .events-list.events-list-win.active .fc-header .list-events-paginator').removeClass('fc-header-center'); 2432 2442 2433 2443 //Adicionar class no header padronizar com a tela principal 2434 $(currentView+' .events-list.events-list-win.active .fc-header').addClass('header-paginator'); 2435 $(currentView+' .events-list.events-list-win.active .header-paginator').removeClass('fc-header'); 2436 2444 $(currentView+' .events-list.events-list-win.active .fc-header .fc-button-print').addClass('print-list-events'); 2445 $(currentView+' .events-list.events-list-win.active .fc-header').addClass('header-paginator'); 2446 $(currentView+' .events-list.events-list-win.active .header-paginator').removeClass('fc-header'); 2447 2448 printEventList(currentView); 2449 2437 2450 if(typeView == 'search'){ 2438 $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right ').remove()2451 $(currentView+' .events-list.events-list-win.active .header-paginator .fc-header-right span.fc-button:not(.fc-button-print)').remove(); 2439 2452 $(currentView+' .events-list.events-list-win.active .list-events-paginator .fc-header-title').html('<h2>Resultados para: '+$(currentView+' [name = keyword]').val()+'</h2>'); 2440 2453 if((parseInt($(currentView+' [name = page_index]').val()) == 0) && (parseInt($(currentView+' [name = results]').val()) <= 25)) … … 2442 2455 paginatorSearch(currentView); 2443 2456 }else 2444 paginatorList(currentView, view );2457 paginatorList(currentView, view, type); 2445 2458 } 2446 2459 … … 2450 2463 case 'basicDay': 2451 2464 case 'agendaDay': 2452 rangeStart = new Date ().add({2465 rangeStart = new Date.today().add({ 2453 2466 days: page_index 2454 2467 }).getTime(); 2455 rangeEnd = rangeStart ;2468 rangeEnd = rangeStart + 86400000; 2456 2469 break; 2457 2470 case 'agendaWeek': … … 2519 2532 } 2520 2533 2521 function pageselectCallback(keyword, page_index, jq, view){ 2522 2523 var selecteds = getSelectedCalendars(); 2524 if(!selecteds && (keyword != '' && keyword != null)){ 2525 jQuery('#tab_events_list_' + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( 2526 '<div title="Lista de eventos" class="events-list events-list-win active empty">' + 2527 '<label>Por favor selecione ao menos uma agenda.</label>' + 2534 function pageselectCallback(keyword, page_index, view, type){ 2535 $('.qtip.qtip-blue').remove(); 2536 var tab_selector = ['tab_events_list_', 'tab_tasks_list_', 'tab_all_list_']; 2537 var tab_title = ['Lista de eventos', 'Lista de tarefas']; 2538 var label_noselect_calendar = ['Por favor selecione ao menos uma agenda.', 'Por favor selecione ao menos um grupo.', 'Por favor selecione ao menos uma agenda ou grupo.']; 2539 var label_nofound_search = ['Não foi encontrado nenhum evento correspondente à sua pesquisa.', 'Não foi encontrado nenhuma tarefa ou atividade correspondente à sua pesquisa.', 'Não foi encontrado nenhum evento ou tarefa ou atividade correspondente à sua pesquisa.']; 2540 var label_nofound = ['Não foram encontrados eventos neste intervalo.', 'Não foram encontradas tarefas ou atividades neste intervalo.', 'Não foram encontrados eventos ou tarefas ou atividades neste intervalo.']; 2541 var selecteds = getSelectedCalendars(false, type); 2542 2543 if(!selecteds && (keyword != '' && keyword != null)){ 2544 jQuery('#'+tab_selector[type] + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "")|| '')).html( 2545 '<div title="'+tab_title[type]+'" class="events-list events-list-win active empty">' + 2546 '<label>'+label_noselect_calendar[type]+'</label>' + 2528 2547 '</div>' 2529 2548 ); … … 2545 2564 var results = DataLayer.get('schedulable:detail', criteria); 2546 2565 keyword = ( keyword || '' ).replace( /\s+/g, "_" ); 2547 }2566 } 2548 2567 // não há resultados 2549 2568 2550 var currentView = '# tab_events_list_'+ ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || '');2569 var currentView = '#'+tab_selector[type] + ((Base64.encode(keyword)).replace(/[^\w\s]/gi, "") || ''); 2551 2570 2552 2571 if ((((typeof(results) == 'undefined') || (!results.events_list )) && selecteds) &&(keyword != '' && keyword != null)) { 2553 2572 $(currentView).html( 2554 '<div title=" Lista de eventos" class="events-list events-list-win active empty">' +2555 '<label> Não foi encontrado nenhum evento correspondente à sua pesquisa.</label>' +2573 '<div title="'+title+'" class="events-list events-list-win active empty">' + 2574 '<label>'+label_nofound_search[type]+'</label>' + 2556 2575 '</div>' 2557 2576 ); … … 2561 2580 results['page_index'] = page_index; 2562 2581 results['keyword'] = keyword; 2563 2582 results['tab_title'] = tab_title[type]; 2564 2583 DataLayer.render( 'templates/event_list.ejs', results, function( html ){ 2565 2584 … … 2567 2586 $('.events-list-win .menu-container .button').button(); 2568 2587 2569 $(".event-details-item").parent().click(function( ){2570 2588 $(".event-details-item").parent().click(function(event){ 2589 event.stopImmediatePropagation(); 2571 2590 $(this).siblings("div.details-event-list").toggleClass("hidden") 2572 .find('.button.delete').click(function( ){2591 .find('.button.delete').click(function(event){ 2573 2592 var eventId = $(this).siblings('[name="eventid"]').val(); 2574 2593 var calendarId = $(this).siblings('[name="calendarid"]').val(); 2575 2576 2594 remove_event(eventId, calendarId); 2595 event.stopImmediatePropagation() 2577 2596 }) 2578 .end().find('.button.edit').click(function(){ 2579 eventDetails( DataLayer.get( "schedulable", $(this).siblings('[name="eventid"]').val() ), true ); 2597 .end().find('.button.edit').click(function(event){ 2598 if($(this).siblings('[name="eventtype"]').val() == 1) 2599 eventDetails( DataLayer.get( "schedulable", $(this).siblings('[name="eventid"]').val() ), true ); 2600 else 2601 taskDetails( DataLayer.get( "schedulable", $(this).siblings('[name="eventid"]').val() ), true ); 2602 2603 event.stopImmediatePropagation() 2604 }) 2605 .end().find('.button.print').click(function(event){ 2606 var window_print = window.open('','ExpressoCalendar','width=800,height=600,scrollbars=yes'); 2607 var html = $(this).parents("td:first").clone(); 2608 html.find(".menu-container.footer-container").remove(); 2609 var html = html.html(); 2610 var data = { 2611 type : $(this).parents('.details-event-list').hasClass("details-event") ? "event-detail" : "task-detail", 2612 html : html 2613 } 2614 window_print.document.open(); 2615 window_print.document.write(DataLayer.render('templates/calendar_list_print.ejs', data)); 2616 window_print.document.close(); 2617 window_print.print(); 2618 2619 event.stopImmediatePropagation() 2580 2620 }); 2581 2621 2582 2622 }); 2583 paginatorListEvent(currentView, (keyword == '' || keyword == null) ? 'list' : 'search', !!view ? view : User.preferences.defaultCalView );2623 paginatorListEvent(currentView, (keyword == '' || keyword == null) ? 'list' : 'search', !!view ? view : User.preferences.defaultCalView, type); 2584 2624 }); 2585 2625 }else{ 2586 2626 $(currentView).html( 2587 '<div title=" Lista de eventos" class="events-list events-list-win active empty">' +2627 '<div title="'+title+'" class="events-list events-list-win active empty">' + 2588 2628 '<input type="hidden" name="page_index" value="'+page_index+'"></inpunt>'+ 2589 2629 '<input type="hidden" name="keyword" value="'+keyword+'"></inpunt>'+ 2590 '<label class="empty-result"> Não foram encontrados eventos neste intervalo.</label>' +2630 '<label class="empty-result">'+label_nofound[type]+'</label>' + 2591 2631 '</div>' 2592 2632 ); 2593 paginatorListEvent(currentView, 'list', !!view ? view : User.preferences.defaultCalView );2594 } 2595 } 2596 if(currentView != '# tab_events_list_')2633 paginatorListEvent(currentView, 'list', !!view ? view : User.preferences.defaultCalView, type); 2634 } 2635 } 2636 if(currentView != '#'+tab_selector[type]) 2597 2637 $tabs.tabs("select", currentView); 2598 2638 } 2599 2639 2600 function show_modal_import_export(tab, calendarId) { 2640 function show_modal_import_export(tab, calendarId, typeView){ 2641 $('.qtip.qtip-blue').remove(); 2601 2642 DataLayer.render( 'templates/import_export.ejs', { 2602 calendars: Calendar.calendars, 2603 owner: User.me.id 2643 calendars: typeView == 0 ? Calendar.calendars : Calendar.groups, 2644 owner: User.me.id, 2645 typeView: typeView 2604 2646 }, function( html ){ 2605 2647 2606 2648 if (!UI.dialogs.importCalendar) { 2607 2649 UI.dialogs.importCalendar = jQuery('#div-import-export-calendar') 2608 .append('<div title="Importar e Exportar Eventos" class="import-export import-export-win active"> <div>')2650 .append('<div title="Importar e Exportar "' + (typeView == 0 ? 'Eventos' : 'Tarefas') + '" class="import-export import-export-win active"> <div>') 2609 2651 .find('.import-export-win.active').html(html).dialog({ 2610 2652 resizable: false, … … 2831 2873 } 2832 2874 } 2875 2876 function extendsFileupload(view, path){ 2877 var viewName = 'div.new-'+view+'-win'; 2878 2879 path = !!path ? path : ''; 2880 2881 var maxSizeFile = 2000000; 2882 $('#fileupload'+view).fileupload({ 2883 sequentialUploads: true, 2884 add: function (e, data) { 2885 if(data.files[0].size < maxSizeFile) 2886 data.submit(); 2887 }, 2888 change: function (e, data) { 2889 $.each(data.files, function (index, file) { 2890 var attach = {}; 2891 attach.fileName = file.name; 2892 var ext = file.name.split('.'); 2893 if(file.name.length > 10) 2894 attach.fileName = ext.length == 1 ? file.name.substr(0, 10) : file.name.substr(0, 6) + '.' + ext[ext.length -1]; 2895 attach.fileSize = formatBytes(file.size); 2896 if(file.size > maxSizeFile) 2897 attach.error = 'Tamanho de arquivo nao permitido!!' 2898 2899 $(viewName+' .attachments-list').append(DataLayer.render(path+'templates/attachment_add_itemlist.ejs', { 2900 file : attach 2901 })); 2902 2903 if(file.size < maxSizeFile){ 2904 $(viewName+' .fileinput-button.new').append(data.fileInput[0]).removeClass('new'); 2905 $(viewName+' .attachments-list').find('[type=file]').addClass('hidden'); 2906 2907 }else 2908 $(viewName+' .fileinput-button.new').removeClass('new'); 2909 2910 2911 $(viewName+' .attachments-list').find('.button.close').button({ 2912 icons: { 2913 primary: "ui-icon-close" 2914 }, 2915 text: false 2916 }).click(function(){ 2917 var idAttach = $(this).parent().find('input[name="fileId[]"]').val(); 2918 $(viewName+' .attachment-list').find('input[value="'+idAttach+'"]').remove(); 2919 $(this).parent().remove(); 2920 2921 if(!$(viewName+' .attachment-list input').length) 2922 $(viewName+' .btn-danger.delete').addClass('hidden'); 2923 2924 }); 2925 2926 }) 2927 }, 2928 done: function(e, data){ 2929 var currentUpload = $(viewName+' .progress.after-upload:first').removeClass('after-upload').addClass('on-complete').hide(); 2930 2931 if(!!data.result && data.result != "[]"){ 2932 $(viewName+' .btn-danger.delete').removeClass('hidden'); 2933 var newAttach = (attch = jQuery.parseJSON(data.result)) ? attch : jQuery.parseJSON(data.result[0].activeElement.childNodes[0].data); 2934 $(viewName+' .attachment-list').append('<input tyepe="hidden" name="attachment[]" value="'+newAttach['attachment'][0][0].id+'"/>'); 2935 currentUpload.removeClass('on-complete').parents('p') 2936 .append('<input type="hidden" name="fileId[]" value="'+newAttach['attachment'][0][0].id+'"/>') 2937 .find('.status-upload').addClass('ui-icon ui-icon-check'); 2938 }else 2939 currentUpload.removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel'); 2940 } 2941 }); 2942 $('.attachments-list .button').button(); 2943 2944 if(!!window.FormData) 2945 $('#fileupload'+view).bind('fileuploadstart', function () { 2946 var widget = $(this), 2947 progressElement = $('#fileupload-progress-'+view).fadeIn(), 2948 interval = 500, 2949 total = 0, 2950 loaded = 0, 2951 loadedBefore = 0, 2952 progressTimer, 2953 progressHandler = function (e, data) { 2954 loaded = data.loaded; 2955 total = data.total; 2956 }, 2957 stopHandler = function () { 2958 widget 2959 .unbind('fileuploadprogressall', progressHandler) 2960 .unbind('fileuploadstop', stopHandler); 2961 window.clearInterval(progressTimer); 2962 progressElement.fadeOut(function () { 2963 progressElement.html(''); 2964 }); 2965 }, 2966 formatTime = function (seconds) { 2967 var date = new Date(seconds * 1000); 2968 return ('0' + date.getUTCHours()).slice(-2) + ':' + 2969 ('0' + date.getUTCMinutes()).slice(-2) + ':' + 2970 ('0' + date.getUTCSeconds()).slice(-2); 2971 }, 2972 /* formatBytes = function (bytes) { 2973 if (bytes >= 1000000000) { 2974 return (bytes / 1000000000).toFixed(2) + ' GB'; 2975 } 2976 if (bytes >= 1000000) { 2977 return (bytes / 1000000).toFixed(2) + ' MB'; 2978 } 2979 if (bytes >= 1000) { 2980 return (bytes / 1000).toFixed(2) + ' KB'; 2981 } 2982 return bytes + ' B'; 2983 },*/ 2984 formatPercentage = function (floatValue) { 2985 return (floatValue * 100).toFixed(2) + ' %'; 2986 }, 2987 updateProgressElement = function (loaded, total, bps) { 2988 progressElement.html( 2989 formatBytes(bps) + 'ps | ' + 2990 formatTime((total - loaded) / bps) + ' | ' + 2991 formatPercentage(loaded / total) + ' | ' + 2992 formatBytes(loaded) + ' / ' + formatBytes(total) 2993 ); 2994 }, 2995 intervalHandler = function () { 2996 var diff = loaded - loadedBefore; 2997 if (!diff) { 2998 return; 2999 } 3000 loadedBefore = loaded; 3001 updateProgressElement( 3002 loaded, 3003 total, 3004 diff * (1000 / interval) 3005 ); 3006 }; 3007 widget 3008 .bind('fileuploadprogressall', progressHandler) 3009 .bind('fileuploadstop', stopHandler); 3010 progressTimer = window.setInterval(intervalHandler, interval); 3011 }); 3012 3013 }
Note: See TracChangeset
for help on using the changeset viewer.