').find('.shared-calendar.active').html(html).dialog({
resizable: false,
modal:true,
autoOpen: false,
width:620,
position: 'center',
close: function(event, ui) {
//Implementações de cancelar
DataLayer.rollback('calendarToPermission');
currentUsers = {};
}
});
} else {
UI.dialogs.sharedCalendar.html(html);
}
/*Seleciona a agenda selecionada para compartilhamento*/
UI.dialogs.sharedCalendar.find('option[value="'+calendarId+'"]').attr('selected','selected').trigger('change');
UI.dialogs.sharedCalendar.find('input[name="isPublic"]').change(function(event){
$(this).parent().find('.free-busy').toggleClass('hidden');
changePublic = changePublic ? false: true;
});
UI.dialogs.sharedCalendar.find('.button').button()
.filter('.cancel').click(function(evt){
UI.dialogs.sharedCalendar.dialog("close");
}).end()
.filter('.save').click(function(evt){
//TODO - API ainda não suporta
//UI.dialogs.sharedCalendar.find('form').submit();
var calendarSelected = UI.dialogs.sharedCalendar.find('option:selected').val();
var save = function(){
if($('li.not-user').length == 0)
$.each(UI.dialogs.sharedCalendar.find('.user-list li.new'), function( i , element ){
var user = $(element).find('input[name="user[]"]').val();
var acl = $(element).find('input[name="attendeeAcl[]"]').val();
if(acl == "")
return true;
DataLayer.put('calendarToPermission', {
calendar: calendarSelected,
type: 0,
user: user,
acl: acl
});
});
$.each(UI.dialogs.sharedCalendar.find('.user-list li.current'), function( i , element ){
var id = $(element).find('input[type="checkbox"]').val();
var acl = $(element).find('input[name="attendeeAcl[]"]').val();
if(acl == "")
DataLayer.remove('calendarToPermission', id);
else
DataLayer.put('calendarToPermission', {
calendar: calendarSelected,
type: 0,
id: id,
acl: acl
});
});
DataLayer.commit();
UI.dialogs.sharedCalendar.dialog("close");
};
//Trata a criação de um acesso público a agenda
if(changePublic){
if(UI.dialogs.sharedCalendar.find('input[name="isPublic"]').is(':checked')){
var acl = UI.dialogs.sharedCalendar.find('input[name="busy"]').is(':checked') ? 'b' : 'w';
DataLayer.put('calendarToPermission', {
calendar: calendarSelected,
type: '1',
user: '0',
acl: acl
});
}else{
//TODO - remover quando for implementado remove com criteria
var permission = DataLayer.get('calendarToPermission', {
filter: ['AND', ['=', 'calendar', calendarId], ['=', 'user', '0']]
}, true);
if($.isArray(permission))
permission = permission[0];
DataLayer.remove('calendarToPermission', permission.id);
}
}
if(!!UI.dialogs.sharedCalendar.find('.user-list li input[name="attendeeAcl[]"][value=""]').length){
$.Zebra_Dialog('Alguns usuários estão sem permissões e serão automáticamente removidos, deseja continuar ?', {
'type': 'question',
'overlay_opacity': '0.5',
'buttons': ['Continuar', 'Cancelar'],
'onClose': function(clicked) {
if(clicked == 'Continuar') {
save();
}
}
});
}else
save();
});
UI.dialogs.sharedCalendar.find('.add-user-search .ui-icon-search').click(function(event) {
UI.dialogs.sharedCalendar.find('.add-user-search input').keydown();
});
var incompatibleAcl = function (obj, acls, buttons){
for (var i = 0; i < acls.length; i++){
var objremove = obj.parent().find('.'+buttons[i]+'');
if(objremove.hasClass('attendee-permissions-change-button'))
changeAcl(objremove, acls[i]);
}
}
var removeAcl = function(current, acl){
var acls = '';
for(var i = 0; i < current.length; i++)
if(current.charAt(i) != acl)
acls += current.charAt(i) ;
return acls;
}
var dependsAcl = function(obj, acls, buttons){
for (var i = 0; i < acls.length; i++){
var objremove = obj.parent().find('.'+buttons[i]+'');
if(!objremove.hasClass('attendee-permissions-change-button'))
changeAcl(objremove, acls[i]);
}
}
var changeAcl = function(obj, acl){
if(obj.hasClass('attendee-permissions-change-button')){
obj.parent().siblings('input[name="attendeeAcl[]"]').val(removeAcl( obj.parent().siblings('input[name="attendeeAcl[]"]').val(), acl)) ;
}else{
var acls = obj.parent().siblings('input[name="attendeeAcl[]"]').val();
obj.parent().siblings('input[name="attendeeAcl[]"]').val(acls + acl);
}
obj.toggleClass('attendee-permissions-change-button')
.find('span:first').toggleClass('attendee-permissions-change').end();
}
UI.dialogs.sharedCalendar.find('.add-user-search input').keydown(function(event) {
if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') {
var result = DataLayer.get('user', ["*", "name", $(this).val()], true);
/**
* TODO: trocar por template
*/
UI.dialogs.sharedCalendar.find('ul.search-result-list').empty().css('overflow', 'hidden');
if (!result) {
UI.dialogs.sharedCalendar.find('ul.search-result-list').append('
');
}
for(i=0; i
').find('.shared-calendar.active').html(html).dialog({
resizable: false,
modal:true,
autoOpen: false,
width:620,
position: 'center',
close: function(event, ui) {
//Implementações de cancelar :D
currentCalendars = {};
$('.signed-calendars').find('.calendar-shared-search input').val('').Watermark('Pesquisar agendas...');
}
});
} else {
UI.dialogs.sharedCalendar.html(html);
}
UI.dialogs.sharedCalendar.find('.button').button()
.filter('.cancel').click(function(evt){
DataLayer.rollback('calendarSignature');
UI.dialogs.sharedCalendar.dialog("close");
}).end()
.filter('.save').click(function(evt){
$.each(UI.dialogs.sharedCalendar.find('.user-list li.new'), function( i , element ){
var idPermission = $(element).find('input[name="idpermission[]"]').val();
var calendarId = $(element).find('input[name="calendar[]"]').val();
var type = parseInt($(element).find('input[name="type[]"]').val());
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
} : {} ));
});
DataLayer.commit( false, false, function( received ){
delete Calendar.currentViewKey;
Calendar.load();
refresh_calendars();
});
UI.dialogs.sharedCalendar.dialog("close");
});
UI.dialogs.sharedCalendar.find('.add-user-search .ui-icon-search').click(function(event) {
UI.dialogs.sharedCalendar.find('.add-user-search input').keydown();
});
UI.dialogs.sharedCalendar.find('.add-user-search input').keydown(function(event) {
if(event.keyCode == '13' || typeof(event.keyCode) == 'undefined') {
var result = DataLayer.get('calendarToPermission', {
filter: ['AND', ['=','user',User.me.id], ['OR', ['i*','name',$(this).val()], ["i*", "description", $(this).val()]]] ,
criteria: {
deepness: 2
}
}, true);
var resultPublic = DataLayer.get('calendarToPermission', {
filter: ['AND', ['=','type',1], ['OR', ['i*','name',$(this).val()], ["i*", "description", $(this).val()]], ['!IN','calendar', Calendar.calendarIds]] ,
criteria: {
deepness: 2
}
}, true);
/**
* TODO: trocar por template
*/
UI.dialogs.sharedCalendar.find('ul.search-result-list').empty().css('overflow', 'hidden');
if (!result && !resultPublic) {
UI.dialogs.sharedCalendar.find('ul.search-result-list').append('
');
}
if(resultPublic){
var notConflict = [];
var conflit = false;
for(var i = 0; i < resultPublic.length; i++){
for(var j = 0; j < result.length; j++){
if(resultPublic[i].id == result[j].calendar.id)
conflit = true;
}
if(!conflit){
notConflict.push(resultPublic[i]);
conflit = false;
}
}
}
resultPublic = notConflict;
var resultNormalize = [];
for(i=0; i