[5592] | 1 | function show_modal_shared(calendarId){ |
---|
| 2 | var html = DataLayer.render('templates/shared_calendar.ejs', {calendar: Calendar.calendars}); |
---|
| 3 | |
---|
| 4 | //Variaval global para manipulação dos usuários |
---|
| 5 | //melhor perforface |
---|
[5617] | 6 | currentUsers = {}; |
---|
[5592] | 7 | currentUsers[User.me.id] = true; |
---|
| 8 | changePublic = false; |
---|
| 9 | |
---|
| 10 | if (!UI.dialogs.sharedCalendar) { |
---|
| 11 | UI.dialogs.sharedCalendar = jQuery('#calendarShared').append('<div title="Compatilhamento de Agenda" class="shared-calendar active"> <div>').find('.shared-calendar.active').html(html).dialog({ |
---|
| 12 | resizable: false, |
---|
| 13 | modal:true, |
---|
| 14 | autoOpen: false, |
---|
| 15 | width:620, |
---|
| 16 | position: 'center', |
---|
| 17 | close: function(event, ui) { |
---|
| 18 | //Implementações de cancelar |
---|
[5812] | 19 | DataLayer.rollback('calendarToPermission'); |
---|
[5617] | 20 | currentUsers = {}; |
---|
[5592] | 21 | } |
---|
| 22 | }); |
---|
| 23 | } else { |
---|
| 24 | UI.dialogs.sharedCalendar.html(html); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | /*Seleciona a agenda selecionada para compartilhamento*/ |
---|
| 28 | UI.dialogs.sharedCalendar.find('option[value="'+calendarId+'"]').attr('selected','selected').trigger('change'); |
---|
| 29 | |
---|
| 30 | UI.dialogs.sharedCalendar.find('input[name="isPublic"]').change(function(event){ |
---|
| 31 | $(this).parent().find('.free-busy').toggleClass('hidden'); |
---|
| 32 | changePublic = changePublic ? false: true; |
---|
| 33 | }); |
---|
| 34 | |
---|
| 35 | UI.dialogs.sharedCalendar.find('.button').button() |
---|
| 36 | .filter('.cancel').click(function(evt){ |
---|
| 37 | UI.dialogs.sharedCalendar.dialog("close"); |
---|
| 38 | }).end() |
---|
| 39 | .filter('.save').click(function(evt){ |
---|
| 40 | //TODO - API ainda não suporta |
---|
| 41 | //UI.dialogs.sharedCalendar.find('form').submit(); |
---|
| 42 | var calendarSelected = UI.dialogs.sharedCalendar.find('option:selected').val(); |
---|
| 43 | var save = function(){ |
---|
| 44 | if($('li.not-user').length == 0) |
---|
[5776] | 45 | $.each(UI.dialogs.sharedCalendar.find('.user-list li.new'), function( i , element ){ |
---|
[5592] | 46 | var user = $(element).find('input[name="user[]"]').val(); |
---|
| 47 | var acl = $(element).find('input[name="attendeeAcl[]"]').val(); |
---|
| 48 | if(acl == "") |
---|
| 49 | return true; |
---|
| 50 | DataLayer.put('calendarToPermission', {calendar: calendarSelected, type: 0, user: user, acl: acl}); |
---|
| 51 | }); |
---|
[5812] | 52 | |
---|
| 53 | $.each(UI.dialogs.sharedCalendar.find('.user-list li.current'), function( i , element ){ |
---|
| 54 | var id = $(element).find('input[type="checkbox"]').val(); |
---|
| 55 | var acl = $(element).find('input[name="attendeeAcl[]"]').val(); |
---|
| 56 | if(acl == "") |
---|
| 57 | DataLayer.remove('calendarToPermission', id); |
---|
| 58 | else |
---|
| 59 | DataLayer.put('calendarToPermission', {calendar: calendarSelected, type: 0, id: id, acl: acl}); |
---|
| 60 | }); |
---|
| 61 | |
---|
| 62 | |
---|
[5592] | 63 | DataLayer.commit(false, false, function(data){ |
---|
| 64 | UI.dialogs.sharedCalendar.dialog("close"); |
---|
| 65 | }); |
---|
| 66 | }; |
---|
| 67 | |
---|
| 68 | //Trata a criação de um acesso público a agenda |
---|
| 69 | if(changePublic){ |
---|
| 70 | if(UI.dialogs.sharedCalendar.find('input[name="isPublic"]').is(':checked')){ |
---|
| 71 | var acl = UI.dialogs.sharedCalendar.find('input[name="busy"]').is(':checked') ? 'b' : 'w'; |
---|
| 72 | DataLayer.put('calendarToPermission', {calendar: calendarSelected, type: '1', user: '0', acl: acl}); |
---|
| 73 | }else{ |
---|
| 74 | //TODO - remover quando for implementado remove com criteria |
---|
[5863] | 75 | var permission = DataLayer.get('calendarToPermission', {filter: ['AND', ['=', 'calendar', calendarId], ['=', 'user', '0']]}, true); |
---|
| 76 | if($.isArray(permission)) |
---|
| 77 | permission = permission[0]; |
---|
| 78 | |
---|
[5592] | 79 | DataLayer.remove('calendarToPermission', permission.id); |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | if(!!UI.dialogs.sharedCalendar.find('.user-list li input[name="attendeeAcl[]"][value=""]').length){ |
---|
| 83 | $.Zebra_Dialog('Alguns usuários estão sem permissões e serão automáticamente removidos, deseja continuar ?', { |
---|
| 84 | 'type': 'question', |
---|
| 85 | 'overlay_opacity': '0.5', |
---|
| 86 | 'buttons': ['Continuar', 'Cancelar'], |
---|
| 87 | 'onClose': function(clicked) { |
---|
| 88 | if(clicked == 'Continuar') { |
---|
| 89 | save(); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | }); |
---|
| 93 | }else |
---|
| 94 | save(); |
---|
| 95 | }); |
---|
| 96 | |
---|
| 97 | UI.dialogs.sharedCalendar.find('.add-user-search .ui-icon-search').click(function(event) { |
---|
| 98 | UI.dialogs.sharedCalendar.find('.add-user-search input').keydown(); |
---|
| 99 | }); |
---|
| 100 | |
---|
| 101 | var incompatibleAcl = function (obj, acls, buttons){ |
---|
| 102 | for (var i = 0; i < acls.length; i++){ |
---|
| 103 | var objremove = obj.parent().find('.'+buttons[i]+''); |
---|
| 104 | if(objremove.hasClass('attendee-permissions-change-button')) |
---|
| 105 | changeAcl(objremove, acls[i]); |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | var removeAcl = function(current, acl){ |
---|
| 110 | var acls = ''; |
---|
| 111 | for(var i = 0; i < current.length; i++) |
---|
| 112 | if(current.charAt(i) != acl) |
---|
| 113 | acls += current.charAt(i) ; |
---|
| 114 | return acls; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | var dependsAcl = function(obj, acls, buttons){ |
---|
| 118 | for (var i = 0; i < acls.length; i++){ |
---|
| 119 | var objremove = obj.parent().find('.'+buttons[i]+''); |
---|
| 120 | if(!objremove.hasClass('attendee-permissions-change-button')) |
---|
| 121 | changeAcl(objremove, acls[i]); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | var changeAcl = function(obj, acl){ |
---|
| 126 | if(obj.hasClass('attendee-permissions-change-button')){ |
---|
| 127 | obj.parent().siblings('input[name="attendeeAcl[]"]').val(removeAcl( obj.parent().siblings('input[name="attendeeAcl[]"]').val(), acl)) ; |
---|
| 128 | }else{ |
---|
| 129 | var acls = obj.parent().siblings('input[name="attendeeAcl[]"]').val(); |
---|
| 130 | obj.parent().siblings('input[name="attendeeAcl[]"]').val(acls + acl); |
---|
| 131 | } |
---|
| 132 | obj.toggleClass('attendee-permissions-change-button') |
---|
| 133 | .find('span:first').toggleClass('attendee-permissions-change').end(); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | UI.dialogs.sharedCalendar.find('.add-user-search input').keydown(function(event) { |
---|
| 138 | if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') { |
---|
| 139 | var result = DataLayer.get('user', ["*", "name", $(this).val()], true); |
---|
| 140 | /** |
---|
| 141 | * TODO: trocar por template |
---|
| 142 | */ |
---|
| 143 | UI.dialogs.sharedCalendar.find('ul.search-result-list').empty().css('overflow', 'hidden'); |
---|
| 144 | if (!result) { |
---|
| 145 | UI.dialogs.sharedCalendar.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>'); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | for(i=0; i<result.length; i++) |
---|
| 149 | result[i].enabled = currentUsers[result[i].id] ? false : true; |
---|
| 150 | |
---|
| 151 | UI.dialogs.sharedCalendar.find('ul.search-result-list').append(DataLayer.render( 'templates/participants_search_itemlist.ejs', result)); |
---|
| 152 | |
---|
| 153 | UI.dialogs.sharedCalendar.find('ul.search-result-list li').click(function(event, ui){ |
---|
| 154 | if ($(event.target).is('input')) { |
---|
| 155 | old_item = $(event.target).parents('li'); |
---|
| 156 | var id = old_item.find('.id').html(); |
---|
| 157 | |
---|
| 158 | currentUsers [id] = { |
---|
| 159 | id: id, |
---|
| 160 | name: old_item.find('.name').html(), |
---|
| 161 | mail: old_item.find('.mail').html() |
---|
| 162 | }; |
---|
| 163 | |
---|
| 164 | UI.dialogs.sharedCalendar.find('dd.user-list ul.user-list') |
---|
| 165 | .append(DataLayer.render('templates/user_shared_add_itemlist.ejs', [{id: id, name: currentUsers [id] .name, mail: currentUsers [id] .mail}])) |
---|
| 166 | .scrollTo('max'); |
---|
| 167 | |
---|
| 168 | $('li.not-user').remove(); |
---|
| 169 | callbackSharedCotactsAdd(); |
---|
| 170 | old_item.remove(); |
---|
| 171 | } |
---|
| 172 | }); |
---|
| 173 | event.preventDefault(); |
---|
| 174 | } |
---|
| 175 | }); |
---|
| 176 | |
---|
| 177 | var callbackSharedCotactsAdd = function(event){ |
---|
| 178 | UI.dialogs.sharedCalendar.find('.button').filter(".read.new").button({ |
---|
| 179 | icons: { |
---|
| 180 | primary: "ui-icon-circle-zoomin" |
---|
| 181 | }, |
---|
| 182 | text: false |
---|
| 183 | }).click(function () { |
---|
| 184 | incompatibleAcl($(this), ['b'], ['busy']); |
---|
| 185 | changeAcl($(this), 'r'); |
---|
| 186 | }) |
---|
| 187 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 188 | .removeClass('new').end() |
---|
| 189 | |
---|
| 190 | .filter(".write.new").button({ |
---|
| 191 | icons: { |
---|
| 192 | primary: "ui-icon-key" |
---|
| 193 | }, |
---|
| 194 | text: false |
---|
| 195 | }).click(function () { |
---|
| 196 | incompatibleAcl($(this), ['b'], ['busy']); |
---|
| 197 | dependsAcl($(this), ['r'], ['read']); |
---|
| 198 | changeAcl($(this), 'w'); |
---|
| 199 | }) |
---|
| 200 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 201 | .removeClass('new').end() |
---|
| 202 | |
---|
| 203 | .filter(".remove.new").button({ |
---|
| 204 | icons: { |
---|
| 205 | primary: "ui-icon-trash" |
---|
| 206 | }, |
---|
| 207 | text: false |
---|
| 208 | }).click(function () { |
---|
| 209 | incompatibleAcl($(this), ['b'], ['busy']); |
---|
| 210 | dependsAcl($(this), ['r'], ['read']); |
---|
| 211 | changeAcl($(this), 'd'); |
---|
| 212 | }) |
---|
| 213 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 214 | .removeClass('new').end() |
---|
| 215 | |
---|
| 216 | .filter(".busy.new").button({ |
---|
| 217 | icons: { |
---|
| 218 | primary: "ui-icon-clock" |
---|
| 219 | }, |
---|
| 220 | text: false |
---|
| 221 | }).click(function () { |
---|
| 222 | //Remove incompativbilidade de acls |
---|
| 223 | incompatibleAcl($(this), ['r', 'w', 'd', 's' ], ['read', 'write', 'remove', 'shared']); |
---|
| 224 | changeAcl($(this), 'b'); |
---|
| 225 | }) |
---|
| 226 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 227 | .removeClass('new').end() |
---|
| 228 | |
---|
| 229 | .filter(".shared.new").button({ |
---|
| 230 | icons: { |
---|
| 231 | primary: "ui-icon-transferthick-e-w" |
---|
| 232 | }, |
---|
| 233 | text: false |
---|
| 234 | }).click(function () { |
---|
| 235 | incompatibleAcl($(this), ['b',], ['busy']); |
---|
| 236 | dependsAcl($(this), ['r'], ['read']); |
---|
| 237 | changeAcl($(this), 's'); |
---|
| 238 | }) |
---|
| 239 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 240 | .removeClass('new').end() |
---|
| 241 | |
---|
| 242 | .filter(".close.new").button({ |
---|
| 243 | icons: { |
---|
| 244 | primary: "ui-icon-close" |
---|
| 245 | }, |
---|
| 246 | text: false |
---|
| 247 | }).click(function () { |
---|
| 248 | currentUsers[$(this).parents().find('input[name="user[]"]').val()] = false; |
---|
[5812] | 249 | //remove permissão |
---|
| 250 | if($(this).parents('li.current').length) |
---|
| 251 | DataLayer.remove('calendarToPermission', $(this).parents('li.current').find('input[type="checkbox"]').val()); |
---|
| 252 | |
---|
[5592] | 253 | $(this).parents('li').remove(); |
---|
| 254 | }) |
---|
| 255 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 256 | .removeClass('new').end(); |
---|
| 257 | |
---|
| 258 | UI.dialogs.sharedCalendar.find('.user-list li').hover( |
---|
| 259 | function () { |
---|
| 260 | $(this).addClass("hover-user"); |
---|
| 261 | $(this).find('.button').removeClass('disable ui-button-disabled ui-state-disabled').end() |
---|
| 262 | .find('.user-acls-shared-calendar').addClass('hover-user'); |
---|
| 263 | }, |
---|
| 264 | function () { |
---|
| 265 | $(this).removeClass("hover-user"); |
---|
| 266 | $(this).find('.button').addClass('disable ui-button-disabled ui-state-disabled').end() |
---|
| 267 | .find('.user-acls-shared-calendar').removeClass('hover-user');; |
---|
| 268 | } |
---|
| 269 | ); |
---|
| 270 | } |
---|
[5617] | 271 | |
---|
[5592] | 272 | //Carrega os dados já cadastrados |
---|
[5812] | 273 | var dataCurrent = DataLayer.get('calendarToPermission:detail', {filter: ['=','calendar', calendarId] , criteria: {deepness: 2}}); |
---|
[5592] | 274 | if(dataCurrent){ |
---|
| 275 | for(var i = 0; i < dataCurrent.length; i++){ |
---|
| 276 | if(dataCurrent[i].user == "0"){ |
---|
| 277 | UI.dialogs.sharedCalendar.find('input[name="isPublic"]').attr('checked', 'checked') |
---|
| 278 | .parent().find('.free-busy').toggleClass('hidden'); |
---|
| 279 | if(dataCurrent[i].acl['busy']) |
---|
[5810] | 280 | UI.dialogs.sharedCalendar.find('input[name="busy"]').attr('checked', 'checked'); |
---|
[5592] | 281 | }else{ |
---|
| 282 | currentUsers[dataCurrent[i].user.id] = true; |
---|
| 283 | |
---|
| 284 | UI.dialogs.sharedCalendar.find('dd.user-list ul.user-list') |
---|
[5812] | 285 | .append(DataLayer.render('templates/user_shared_add_itemlist.ejs', [{id: dataCurrent[i].user.id, name: dataCurrent[i].user.name, mail: dataCurrent[i].user.mail, acl:dataCurrent[i].acl, aclValue: dataCurrent[i].aclValues, current: true, idPermission: dataCurrent[i].id }])) |
---|
[5592] | 286 | .scrollTo('max'); |
---|
| 287 | $('li.not-user').remove(); |
---|
| 288 | callbackSharedCotactsAdd(); |
---|
| 289 | |
---|
| 290 | for (var f in dataCurrent[i].acl){ |
---|
| 291 | if(dataCurrent[i].acl[f]){ |
---|
| 292 | UI.dialogs.sharedCalendar.find('.'+f+':last').toggleClass('attendee-permissions-change-button') |
---|
| 293 | .find('span:first').toggleClass('attendee-permissions-change').end(); |
---|
| 294 | } |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | } |
---|
| 299 | UI.dialogs.sharedCalendar.dialog('open'); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | function show_modal_search_shared(){ |
---|
| 303 | |
---|
| 304 | var html = DataLayer.render('templates/shared_calendar.ejs', {}); |
---|
| 305 | |
---|
| 306 | //Variaval global para manipulação dos usuários |
---|
| 307 | //melhor perforface |
---|
[5617] | 308 | currentCalendars = {}; |
---|
[5592] | 309 | |
---|
| 310 | if (!UI.dialogs.sharedCalendar) { |
---|
| 311 | UI.dialogs.sharedCalendar = jQuery('#calendarShared').append('<div title="Pesquisar Agendas" class="shared-calendar active"> <div>').find('.shared-calendar.active').html(html).dialog({ |
---|
| 312 | resizable: false, |
---|
| 313 | modal:true, |
---|
| 314 | autoOpen: false, |
---|
| 315 | width:620, |
---|
| 316 | position: 'center', |
---|
| 317 | close: function(event, ui) { |
---|
| 318 | //Implementações de cancelar :D |
---|
[5617] | 319 | currentCalendars = {}; |
---|
[5592] | 320 | $('.signed-calendars').find('.calendar-shared-search input').val('').Watermark('Pesquisar agendas...'); |
---|
| 321 | } |
---|
| 322 | }); |
---|
| 323 | } else { |
---|
| 324 | UI.dialogs.sharedCalendar.html(html); |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | UI.dialogs.sharedCalendar.find('.button').button() |
---|
| 328 | .filter('.cancel').click(function(evt){ |
---|
| 329 | UI.dialogs.sharedCalendar.dialog("close"); |
---|
| 330 | }).end() |
---|
| 331 | .filter('.save').click(function(evt){ |
---|
| 332 | $.each(UI.dialogs.sharedCalendar.find('.user-list li'), function( i , element ){ |
---|
| 333 | var idPermission = $(element).find('input[name="idpermission[]"]').val(); |
---|
| 334 | var calendarId = $(element).find('input[name="calendar[]"]').val(); |
---|
| 335 | var type = parseInt($(element).find('input[name="type[]"]').val()); |
---|
| 336 | DataLayer.put('calendarSignature', DataLayer.merge({calendar: calendarId, isOwner: 0, user: User.me.id, fontColor: '120d0d', backgroundColor: (!!type ? 'fbec88' : '8c8c8c'), borderColor: (!!type ? 'fad24e' : '120d0d')}, !!idPermission ? {id: idPermission} : {} )); |
---|
| 337 | }); |
---|
[5615] | 338 | |
---|
| 339 | DataLayer.commit( false, false, function( received ){ |
---|
| 340 | delete Calendar.currentViewKey; |
---|
| 341 | Calendar.load(); |
---|
| 342 | refresh_calendars(); |
---|
| 343 | }); |
---|
| 344 | |
---|
[5592] | 345 | UI.dialogs.sharedCalendar.dialog("close"); |
---|
| 346 | |
---|
| 347 | }); |
---|
| 348 | |
---|
| 349 | UI.dialogs.sharedCalendar.find('.add-user-search .ui-icon-search').click(function(event) { |
---|
| 350 | UI.dialogs.sharedCalendar.find('.add-user-search input').keydown(); |
---|
| 351 | }); |
---|
| 352 | |
---|
| 353 | UI.dialogs.sharedCalendar.find('.add-user-search input').keydown(function(event) { |
---|
| 354 | if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') { |
---|
| 355 | var result = DataLayer.get('calendarToPermission', {filter: ['AND', ['=','user',User.me.id], ['OR', ['i*','name',$(this).val()], ["i*", "description", $(this).val()]]] , criteria: {deepness: 2}}, true); |
---|
| 356 | var resultPublic = DataLayer.get('calendarToPermission', {filter: ['AND', ['=','type',1], ['OR', ['i*','name',$(this).val()], ["i*", "description", $(this).val()]]] , criteria: {deepness: 2}}, true); |
---|
| 357 | |
---|
| 358 | /** |
---|
| 359 | * TODO: trocar por template |
---|
| 360 | */ |
---|
| 361 | UI.dialogs.sharedCalendar.find('ul.search-result-list').empty().css('overflow', 'hidden'); |
---|
| 362 | if (!result && !resultPublic) { |
---|
| 363 | UI.dialogs.sharedCalendar.find('ul.search-result-list').append('<li><label class="empty">Nenhum resultado encontrado.</label></li>'); |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | if(resultPublic){ |
---|
| 367 | var notConflict = []; |
---|
| 368 | var conflit = false; |
---|
| 369 | for(var i = 0; i < resultPublic.length; i++){ |
---|
| 370 | for(var j = 0; j < result.length; j++){ |
---|
| 371 | if(resultPublic[i].id == result[j].calendar.id) |
---|
| 372 | conflit = true; |
---|
| 373 | }if(!conflit){ |
---|
| 374 | notConflict.push(resultPublic[i]); |
---|
| 375 | conflit = false; |
---|
| 376 | } |
---|
| 377 | } |
---|
| 378 | } |
---|
| 379 | resultPublic = notConflict; |
---|
| 380 | |
---|
| 381 | var resultNormalize = []; |
---|
| 382 | for(i=0; i<result.length; i++){ |
---|
| 383 | resultNormalize.push({id: result[i].calendar.id, name:result[i].calendar.name, mail: result[i].calendar.description, type: 0 }) |
---|
| 384 | resultNormalize[i].enabled = currentCalendars[result[i].id] ? false : true; |
---|
| 385 | } |
---|
| 386 | if(resultPublic) |
---|
| 387 | for(i=0; i<resultPublic.length; i++){ |
---|
| 388 | resultNormalize.push({id: resultPublic[i].calendar.id, name:resultPublic[i].calendar.name, mail: resultPublic[i].calendar.description,type: 1 }) |
---|
| 389 | resultNormalize[i].enabled = currentCalendars[resultPublic[i].id] ? false : true; |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | UI.dialogs.sharedCalendar.find('ul.search-result-list').append(DataLayer.render( 'templates/participants_search_itemlist.ejs', resultNormalize)); |
---|
| 393 | |
---|
| 394 | UI.dialogs.sharedCalendar.find('ul.search-result-list li').click(function(event, ui){ |
---|
| 395 | if ($(event.target).is('input')) { |
---|
| 396 | old_item = $(event.target).parents('li'); |
---|
| 397 | var id = old_item.find('.id').html(); |
---|
| 398 | |
---|
| 399 | for(var i = 0; i<resultNormalize.length; i++){ |
---|
| 400 | if(resultNormalize[i].id == id) |
---|
| 401 | currentCalendars[id] = { id: id, name: resultNormalize[i].name, description: resultNormalize[i].description, type: resultNormalize[i].type, isCalendar: true}; |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | UI.dialogs.sharedCalendar.find('dd.calendar-list ul.user-list') |
---|
| 405 | .append(DataLayer.render('templates/user_shared_add_itemlist.ejs', [currentCalendars[id]])) |
---|
| 406 | .scrollTo('max'); |
---|
| 407 | |
---|
| 408 | $('li.not-user').remove(); |
---|
| 409 | callbackSharedCalendarAdd(); |
---|
| 410 | old_item.remove(); |
---|
| 411 | } |
---|
| 412 | }); |
---|
| 413 | event.preventDefault(); |
---|
| 414 | } |
---|
| 415 | }); |
---|
| 416 | |
---|
| 417 | var callbackSharedCalendarAdd = function(event){ |
---|
| 418 | |
---|
| 419 | UI.dialogs.sharedCalendar.find('.button').filter(".close.new").button({ |
---|
| 420 | icons: { |
---|
| 421 | primary: "ui-icon-close" |
---|
| 422 | }, |
---|
| 423 | text: false |
---|
| 424 | }).click(function () { |
---|
| 425 | currentCalendars[$(this).parents().find('input[name="calendar[]"]').val()] = false; |
---|
| 426 | $(this).parents('li').remove(); |
---|
| 427 | }) |
---|
| 428 | .addClass('tiny disable ui-button-disabled ui-state-disabled') |
---|
| 429 | .removeClass('new').end(); |
---|
| 430 | |
---|
| 431 | UI.dialogs.sharedCalendar.find('.user-list li').hover( |
---|
| 432 | function () { |
---|
| 433 | $(this).addClass("hover-user"); |
---|
| 434 | $(this).find('.button').removeClass('disable ui-button-disabled ui-state-disabled').end() |
---|
| 435 | .find('.user-acls-shared-calendar').addClass('hover-user'); |
---|
| 436 | }, |
---|
| 437 | function () { |
---|
| 438 | $(this).removeClass("hover-user"); |
---|
| 439 | $(this).find('.button').addClass('disable ui-button-disabled ui-state-disabled').end() |
---|
| 440 | .find('.user-acls-shared-calendar').removeClass('hover-user');; |
---|
| 441 | } |
---|
| 442 | ); |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | //Carrega os dados já cadastrados |
---|
| 446 | for (var i = 0; i < Calendar.signatures.length; i++) |
---|
| 447 | if(Calendar.signatures[i].isOwner == "0"){ |
---|
| 448 | var dataCurrent = Calendar.signatures[i].calendar; |
---|
| 449 | currentCalendars[Calendar.signatures[i].permission.id] = { id: dataCurrent.id, idPermission:Calendar.signatures[i].id ,name: dataCurrent.name, description: dataCurrent.description, type: Calendar.signatures[i].permission.type, isCalendar: true}; |
---|
| 450 | |
---|
| 451 | UI.dialogs.sharedCalendar.find('dd.calendar-list ul.user-list') |
---|
| 452 | .append(DataLayer.render('templates/user_shared_add_itemlist.ejs', [currentCalendars[Calendar.signatures[i].permission.id]])) |
---|
| 453 | .scrollTo('max'); |
---|
| 454 | |
---|
| 455 | $('li.not-user').remove(); |
---|
| 456 | callbackSharedCalendarAdd(); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | UI.dialogs.sharedCalendar.dialog('open'); |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | function cancel_signature(signatureId){ |
---|
| 463 | $.Zebra_Dialog('Confirma a remoção desta assinatura ?', { |
---|
| 464 | 'type': 'question', |
---|
| 465 | 'overlay_opacity': '0.5', |
---|
| 466 | 'buttons': ['Sim', 'Não'], |
---|
| 467 | 'onClose': function(clicked) { |
---|
| 468 | if(clicked == 'Sim'){ |
---|
| 469 | DataLayer.remove('calendarSignature', ''+signatureId); |
---|
[5617] | 470 | DataLayer.commit( false, false, function( received ){ |
---|
| 471 | delete Calendar.currentViewKey; |
---|
| 472 | Calendar.load(); |
---|
| 473 | refresh_calendars(); |
---|
| 474 | }); |
---|
[5592] | 475 | } |
---|
| 476 | } |
---|
| 477 | }); |
---|
| 478 | } |
---|