Files
leanote/public/js/app/share-min.js

1 line
12 KiB
JavaScript
Raw Normal View History

2014-05-07 13:06:24 +08:00
Share.defaultNotebookId="share0";Share.defaultNotebookTitle="默认共享";Share.sharedUserInfos={};Share.userNavs={};Share.notebookCache={};Share.cache={};Share.dialogIsNote=true;Share.setCache=function(note){if(!note||!note.NoteId){return}Share.cache[note.NoteId]=note};Share.renderShareNotebooks=function(sharedUserInfos,shareNotebooks){if(isEmpty(sharedUserInfos)){return}if(!shareNotebooks||typeof shareNotebooks!="object"||shareNotebooks.length<0){return}var $shareNotebooks=$("#shareNotebooks");for(var i in sharedUserInfos){var userInfo=sharedUserInfos[i];var userNotebooks=shareNotebooks[userInfo.UserId]||[];userNotebooks=[{NotebookId:Share.defaultNotebookId,Title:Share.defaultNotebookTitle}].concat(userNotebooks);var username=userInfo.Username||userInfo.Email;userInfo.Username=username;Share.sharedUserInfos[userInfo.UserId]=userInfo;var userId=userInfo.UserId;var header=t('<li class="each-user"><div class="" fromUserId="?"><i class="fa fa-angle-down"></i><span>?</span></div>',userInfo.UserId,username);var friendId="friendContainer"+i;var body='<ul class="" id="'+friendId+'">';var forList="";var forNew="";for(var j in userNotebooks){var notebook=userNotebooks[j];notebook.IsShared=true;notebook.UserId=userId;Share.notebookCache[notebook.NotebookId]=notebook;Notebook.cache[notebook.NotebookId]=notebook;body+=t('<li><a notebookId="?" fromUserId="?">?</a></li>',notebook.NotebookId,userId,notebook.Title);var each=t('<li role="presentation"><a role="menuitem" tabindex="-1" href="#" userId="?" notebookId="?">?</a></li>',userId,notebook.NotebookId,notebook.Title);forList+=each;if(j!=0&&notebook.Perm){forNew+=t('<li role="presentation" class="clearfix" userId="?" notebookId="?"><div class="new-note-left pull-left">?</div><div class="new-note-right pull-left">Markdown</div></li>',userId,notebook.NotebookId,notebook.Title)}}body+="</ul>";Share.userNavs[userId]={forList:forList,forNew:forNew};$shareNotebooks.append(header+body+"</div>");$("#minShareNotebooks").append('<div class="minContainer" target="#'+friendId+'" title="'+username+' 的分享"><i class="fa fa-user"></i><ul class="dropdown-menu"></ul></li>')}};Share.isDefaultNotebookId=function(notebookId){return Share.defaultNotebookId==notebookId};Share.toggleToSharedNav=function(userId,notebookId){$("#sharedNotebookNavForListNote").html(Share.userNavs[userId].forList);$("#sharedNotebookNavForListNav").show();$("#curSharedNotebookForListNote").html(Share.notebookCache[notebookId].Title+"("+Share.sharedUserInfos[userId].Username+")");$("#myNotebookNavForListNav").hide();var forNew=Share.userNavs[userId].forNew;if(forNew){$("#notebookNavForNewSharedNote").html(forNew);var curNotebookId="";var curNotebookTitle="";if(Share.notebookCache[notebookId].Perm){curNotebookId=notebookId;curNotebookTitle=Share.notebookCache[notebookId].Title}else{var $f=$("#notebookNavForNewSharedNote li").eq(0);curNotebookId=$f.attr("notebookId");curNotebookTitle=$f.text()}$("#curNotebookForNewSharedNote").html(curNotebookTitle+"("+Share.sharedUserInfos[userId].Username+")");$("#curNotebookForNewSharedNote").attr("notebookId",curNotebookId);$("#curNotebookForNewSharedNote").attr("userId",userId);$("#newSharedNote").show();$("#newMyNote").hide()}$("#tagSearch").hide()};Share.changeNotebook=function(userId,notebookId){Notebook.selectNotebook($(t('#shareNotebooks a[notebookId="?"]',notebookId)));Share.toggleToSharedNav(userId,notebookId);Note.curChangedSaveIt();Note.clearAll();var url="/share/ListShareNotes/";var param={userId:userId};if(!Share.isDefaultNotebookId(notebookId)){param.notebookId=notebookId}ajaxGet(url,param,function(ret){if(param.notebookId){}Note.renderNotes(ret,false,true);if(!isEmpty(ret)){Note.changeNote(ret[0].NoteId,true)}else{}})};Share.hasUpdatePerm=function(notebookId){var note=Share.cache[notebookId];if(!note||!note.Perm){return false}return true};Share.deleteShareNotebook=function(target){var notebookId=$(target).attr("notebookId");var fromUserId=$(target).attr("fromUserId");ajaxGet("/share/DeleteShareNotebookBySharedUser",{notebookId:notebookId,fromUserId:fromUserId},function(ret)