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