Implements DND for et2-select-email tags

This commit is contained in:
Hadi Nategh
2022-06-21 16:21:23 +02:00
parent 1894a19a86
commit ac171a1076
6 changed files with 89 additions and 190 deletions

View File

@ -344,9 +344,6 @@ app.classes.mail = AppJS.extend(
// Init key handler
this.init_keyHandler();
//Call drag_n_drop initialization for emails on compose
this.init_dndCompose();
// Set focus on To/body field
// depending on To field value
var to = this.et2.getWidgetById('to');
@ -5070,182 +5067,6 @@ app.classes.mail = AppJS.extend(
});
},
/**
* Initialize dropping targets for draggable emails
* -
*/
init_dndCompose: function ()
{
var self = this;
var emailTags = jQuery('#mail-compose_to,#mail-compose_cc,#mail-compose_bcc');
//Call to make new items draggable
emailTags.hover(function(){
self.set_dragging_dndCompose();
});
//Make used email-tag list widgets in mail compose droppable
emailTags.droppable({
accept:'.ms-sel-item',
/**
* Run after a draggable email item dropped over one of the email-taglists
* -Set the dropped item to the dropped current target widget
*
* @param {type} event
* @param {type} ui
*/
drop:function (event, ui)
{
var widget = self.et2.getWidgetById(this.getAttribute('name'));
var emails, distLists = [];
var fromWidget = {};
var parentWidgetDOM = ui.draggable.siblings().filter('input');
if (parentWidgetDOM != 'undefined' && parentWidgetDOM.length > 0)
{
fromWidget = self.et2.getWidgetById(parentWidgetDOM.attr('name'));
}
var draggedValue = ui.draggable.text();
// index of draggable item in selection list
var dValueKey = draggedValue;
var distItem = ui.draggable.find('.mailinglist');
if (distItem.length>0)
{
var distItemId = parseInt(distItem.attr('data'));
if (distItemId)
{
var fromDistLists = resolveDistList(fromWidget);
for (var i=0;i<fromDistLists.length;i++)
{
if (distItemId == fromDistLists[i]['id'])
{
draggedValue = fromDistLists[i];
// dist list item index
dValueKey = fromDistLists[i]['id'];
}
}
}
}
if (typeof widget != 'undefined')
{
emails = widget.get_value();
if (emails) emails = emails.concat([draggedValue]);
// Resolve the dist list and normal emails
distLists = resolveDistList(widget, emails);
// Add normal emails
if (emails) widget.set_value(emails);
// check if there's any dist list to be added
if (distLists.length>0) widget.taglist.addToSelection(distLists);
if (!jQuery.isEmptyObject(fromWidget)
&& !(ui.draggable.attr('class').search('mailCompose_copyEmail') > -1))
{
if (widget.node != fromWidget.node && !_removeDragged(fromWidget, dValueKey))
{
//Not successful remove, returns the item to its origin
jQuery(ui.draggable).draggable('option','revert',true);
}
}
else
{
ui.draggable
.removeClass('mailCompose_copyEmail')
.css('cursor','move');
}
var dragItems = jQuery('div.ms-sel-item');
dragItems.each(function(i,item){
var $isErr = jQuery(item).find('.ui-state-error');
if ($isErr.length > 0)
{
delete dragItems.splice(i,1);
}
});
}
}
});
/**
* Remove dragged item from the widget which the item was dragged
*
* @param {type} _widget
* @param {type} _value
* @return {boolean} true if successul | false unsuccessul
*/
var _removeDragged = function (_widget, _value)
{
if (_widget && _value)
{
var emails = _widget.get_value();
var itemIndex = emails.indexOf(_value);
var dist = [];
if (itemIndex > -1)
{
emails.splice(itemIndex,1);
// Resolve the dist list and normal emails
var dist = resolveDistList(_widget, emails);
// Add normal emails
_widget.set_value(emails);
//check if there's any dist list to be added
if (dist)
{
for(var i=0;i<dist.length;i++)
{
if (dist[i]['id'] == _value) dist.splice(i,1);
}
_widget.taglist.addToSelection(dist);
}
}
else
{
return false;
}
}
return true;
};
/**
* Resolve taglist widget which has distribution list
*
* @param {type} _widget
* @param {type} _emails
* @returns {Array} returns an array of distribution lists in selected widget
*/
var resolveDistList = function (_widget, _emails)
{
var list = [];
var selectedList = _widget.taglist.getSelection();
// Make a list of distribution list from the selection
for (var i=0;i<selectedList.length;i++)
{
if (!isNaN(selectedList[i]['id']) && selectedList[i]['class'] === 'mailinglist')
{
list.push(selectedList[i]);
}
}
// Remove dist list from emails list
for(var key in _emails)
{
if (!isNaN(_emails[key]))
{
_emails.splice(key,1);
}
}
// returns distlist
return list;
};
},
/**
* Check sharing mode and disable not available options
*