
function Send_Action(params)
{this.nodes=[];this.source=null;this.callback=null;this.name='Send';this.ml_name='ml_share';this.params=params;this.set_params=function(nodes,source,params,callback)
{if(!nodes)return false;this.nodes=nodes;if(!source)return false;this.source=source;if(callback)this.callback=callback;if(params)this.params=params;}
this.start=function()
{if(typeof this.nodes=='undefined')return false;var node=(this.nodes.length==1)?this.nodes[0]:{};var node_id=node.id||-1;var node_name=node.name||$t('selected items','popup_myfiles_share_js_selected_items')
var node_type=node.type||3;var me=this;popups.sharePopup.create(node_id,node_name,function(item_id,emails,msg)
{me.submit(item_id,emails,msg);},false,node_type);}
this.submit=function(item_id,emails,msg)
{var query={};if(!this.nodes)
{popups.sharePopup.destroy(1);return false;}
if(this.source=='files'&&this.nodes.length>0)
{var ids=[];for(i in this.nodes)
{ids.push(this.nodes[i].typed_id);}
query.node_id=ids.join(',');query.email=emails.join(',');}
else if(this.source=='box')
{query.type='box';query.emails=emails;query.item_id=this.nodes[0].typed_id;query.box_id=box_id;}
else if(this.source=='inbox'||this.source=='shared_page')
{query.update_id=this.nodes[0].params.update.update_id;query.item_type=this.nodes[0].type;if(query.item_type=='file')
{query.update_file_id=this.nodes[0].params.update_file_id;query.item_id=this.nodes[0].id;}
else
{query.update_folder_id=this.nodes[0].params.folder_id;query.item_id=this.nodes[0].params.id;}
query.emails=emails;}
if(msg)query.message=msg;var callback=this.callback;var message=(this.nodes.length==1)?$t('Success. %1 was successfully shared with','popup_myfiles_share_js_result_message_item',$j.text(this.nodes[0].name)):$t('Selected items were successfully shared with','popup_myfiles_share_js_result_message');var tip=null;var type=this.nodes[0].type;if(this.nodes.length==1)tip='<b>Tip:</b> You can also share this '+type+' from your email or IM by clicking "<a href="#" onclick="box_event.set_category(\'Files - Just sent tip\');Canvas.get().target_item.share();return false">Link to this '+type+'</a>" in the menu.';var url=site_root+'index.php?rm=';if(this.source=='files')url+='box_v2_invite_share';if(this.source=='box')url+='box_box_share';if(this.source=='inbox'||this.source=='shared_page')url+='box_inbox_share';var q=$j.box.formatQuery(query);$j.getJSON(url,q,function(json)
{popups.sharePopup.destroy(1);if(json.email_count!=null)
{friend_text=(json.email_count==1)?emails[0]:json.email_count+' '+$t('people.','popup_myfiles_share_js_result_message_friends');}
message+=' '+friend_text;Canvas.get().show_confirmation(message,null,tip,null);if(callback)callback({'shared_link':(json.shared_link?json.shared_link:''),'direct_shared_link':(json.direct_shared_link?json.direct_shared_link:'')});});}
this.execute=function()
{if(!this.can_execute())
{alert('You cannot send the selected items');return;}
this.start();}
this.can_execute=function()
{if(Canvas.get().user.is_subuser&&!user_can_share())return false;if(!this.nodes||this.nodes.length<1)return false;for(i in this.nodes)
{var item=this.nodes[i];if(!item||!item.permissions.share)return false;if(item.type=='web_link'||item.type=='discussion')return false;}
return true;}}