AttachmentController.js 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541
  1. o2.widget = o2.widget || {};
  2. if( !o2.widget.UUID )o2.require("o2.widget.UUID", null, false);
  3. o2.widget.AttachmentController = o2.widget.ATTER = new Class({
  4. Extends: o2.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "listStyle": "icon",
  9. "size": "max",
  10. "resize": true,
  11. "attachmentCount": 0,
  12. "isUpload": true,
  13. "isDelete": true,
  14. "isReplace": true,
  15. "isDownload": true,
  16. "isPreviewAtt": true,
  17. "isPreviewAtt": true,
  18. "isSizeChange": true,
  19. "isConfig": true,
  20. "isOrder": true,
  21. "readonly": false,
  22. "availableListStyles" : ["list","seq","icon","preview"],
  23. "toolbarGroupHidden" : [], //edit read list view
  24. "images": ["bmp", "gif", "png", "jpeg", "jpg", "jpe", "ico"],
  25. "audios": ["mp3", "wav", "wma", "wmv"],
  26. "videos": ["avi", "mkv", "mov", "ogg", "mp4", "mpa", "mpe", "mpeg", "mpg", "rmvb"],
  27. "actionShowText" : false
  28. },
  29. initialize: function(container, module, options){
  30. this.setOptions(options);
  31. this.pages = [];
  32. this.path = o2.session.path+"/widget/$AttachmentController/";
  33. this.cssPath = o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/css.wcss";
  34. this._loadCss();
  35. var iconUrl = this.options.iconConfigUrl ? this.options.iconConfigUrl : "../x_component_File/$Main/icon.json";
  36. o2.getJSON(iconUrl, function(json){
  37. this.icons = json;
  38. }.bind(this), false);
  39. this.module = module;
  40. this.actions = [];
  41. this.attachments = [];
  42. this.selectedAttachments = [];
  43. this.container = $(container);
  44. },
  45. load: function(){
  46. // if (!layout.mobile){
  47. if (this.options.size==="min"){
  48. this.loadMin();
  49. }else{
  50. this.loadMax();
  51. }
  52. // }else{
  53. // this.loadMobile();
  54. // }
  55. },
  56. reloadAttachments: function(){
  57. if (this.options.size==="min"){
  58. this.minContent.empty();
  59. var atts = this.attachments;
  60. this.attachments = [];
  61. while (atts.length){
  62. var att = atts.shift();
  63. this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this));
  64. }
  65. }else{
  66. this.content.empty();
  67. var atts = this.attachments;
  68. this.attachments = [];
  69. while (atts.length){
  70. var att = atts.shift();
  71. this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this));
  72. }
  73. }
  74. this.checkActions();
  75. },
  76. getAttachmentById: function(attId){
  77. for( var i=0; i<this.attachments.length; i++ ){
  78. if( this.attachments[i].data.id === attId ){
  79. return this.attachments[i];
  80. }
  81. }
  82. return null;
  83. },
  84. loadMax: function(){
  85. if (!this.node) this.node = new Element("div", {"styles": this.css.container});
  86. this.createTopNode();
  87. if (!this.contentScrollNode){
  88. //this.createTopNode();
  89. this.createContentNode();
  90. if (this.options.resize){
  91. this.createBottomNode();
  92. this.createResizeNode();
  93. }
  94. this.node.inject(this.container);
  95. //if (this.options.readonly) this.setReadonly();
  96. this.checkActions();
  97. this.setEvent();
  98. }else{
  99. // this.contentScrollNode.setStyle("display", "block");
  100. // if (this.bottomNode) this.bottomNode.setStyle("display", "block");
  101. // if (this.titleNode) this.titleNode.setStyle("display", "block");
  102. this.contentScrollNode.show();
  103. if (this.bottomNode) this.bottomNode.show();
  104. if (this.titleNode) this.titleNode.show();
  105. //this.topNode.setStyle("display", "block");
  106. this.content.empty();
  107. }
  108. var atts = this.attachments;
  109. this.attachments = [];
  110. while (atts.length){
  111. var att = atts.shift();
  112. this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this));
  113. }
  114. this.checkActions();
  115. //this.attachments = atts;
  116. if( layout.mobile ){
  117. this.checkActionsZoom();
  118. }
  119. },
  120. loadMin: function(){
  121. if (!this.node) this.node = new Element("div", {"styles": this.css.container_min});
  122. if (!this.minActionAreaNode){
  123. this.minActionAreaNode = new Element("div", {"styles": this.css.minActionAreaNode }).inject(this.node);
  124. //this.minContent = new Element("div", {"styles": this.css.minContentNode}).inject(this.node);
  125. this.loadMinActions();
  126. this.node.inject(this.container);
  127. //if (this.options.readonly) this.setReadonly();
  128. //this.checkActions();
  129. this.setEvent();
  130. }else{
  131. this.minActionAreaNode.show();
  132. //this.minContent.setStyle("display", "block");
  133. //this.minContent.empty();
  134. this.minActionAreaNode.empty();
  135. this.loadMinActions();
  136. this.setEvent();
  137. }
  138. var hiddenGroup = this.options.toolbarGroupHidden;
  139. var flag = hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("view");
  140. if( flag )this.minActionAreaNode.setStyle("display","none");
  141. if( !this.minContent ){
  142. this.minContent = new Element("div", {"styles":
  143. layout.mobile ? this.css.minContentNode_mobile : this.css.minContentNode
  144. }).inject(this.node);
  145. if( layout.mobile ){
  146. this.minContent.setStyle("clear","both");
  147. }
  148. }else{
  149. this.minContent.setStyle("display", "block");
  150. this.minContent.empty();
  151. }
  152. var atts = this.attachments;
  153. this.attachments = [];
  154. while (atts.length){
  155. var att = atts.shift();
  156. this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this));
  157. }
  158. this.checkActions();
  159. //this.attachments = atts;
  160. },
  161. loadMobile: function(){
  162. },
  163. loadMinActions: function(){
  164. var hiddenGroup = this.options.toolbarGroupHidden;
  165. if (!hiddenGroup.contains("edit")) {
  166. this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", o2.LP.widget.upload, function (e, node) {
  167. this.uploadAttachment(e, node);
  168. }.bind(this));
  169. this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", o2.LP.widget["delete"], function (e, node) {
  170. this.deleteAttachment(e, node);
  171. }.bind(this));
  172. if( !this.options.isReplaceHidden ){
  173. this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", o2.LP.widget.replace, function (e, node) {
  174. this.replaceAttachment(e, node);
  175. }.bind(this));
  176. }
  177. }
  178. if (!hiddenGroup.contains("read")) {
  179. this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", o2.LP.widget.download, function (e, node) {
  180. this.downloadAttachment(e, node);
  181. }.bind(this));
  182. }
  183. var hasChangeSize = this.options.isSizeChange && !hiddenGroup.contains("view");
  184. if( (!hiddenGroup.contains("edit") || !hiddenGroup.contains("read")) && hasChangeSize ) {
  185. this.createSeparate(this.minActionAreaNode);
  186. }
  187. if (hasChangeSize){
  188. this.sizeAction = this.createAction(this.minActionAreaNode, "max", o2.LP.widget.min, function () {
  189. this.changeControllerSize();
  190. }.bind(this));
  191. }
  192. },
  193. setEvent: function(){
  194. if (this.contentScrollNode && !this.isContentSetEvent){
  195. this.contentScrollNode.addEventListener("dragover", function( e ) {
  196. e.preventDefault();
  197. e.stopPropagation();
  198. }, false);
  199. this.contentScrollNode.addEventListener("drop", function( e ) {
  200. this.uploadAttachment(e, null, e.dataTransfer.files);
  201. event.preventDefault();
  202. }.bind(this), false);
  203. this.contentScrollNode.addEvents({
  204. "mousedown": this.unSelectedAttachments.bind(this)
  205. });
  206. this.isContentSetEvent = true;
  207. }
  208. if (this.minContent && !this.isMinContentSetEvent){
  209. this.minContent.addEventListener("dragover", function( e ) {
  210. e.preventDefault();
  211. e.stopPropagation();
  212. }, false);
  213. this.minContent.addEventListener("drop", function (e) {
  214. this.uploadAttachment(e, null, e.dataTransfer.files);
  215. event.preventDefault();
  216. }.bind(this), false);
  217. this.minContent.addEvents({
  218. "mousedown": this.unSelectedAttachments.bind(this)
  219. });
  220. this.isMinContentSetEvent = true;
  221. }
  222. },
  223. resetToolbarGroupHidden : function( hiddenGroup ){
  224. this.options.toolbarGroupHidden = hiddenGroup;
  225. if( this.options.size == "max" ){
  226. this.reloadTopNode();
  227. }else{
  228. this.loadMin();
  229. }
  230. },
  231. resetToolbarAvailableListStyle : function( availableListStyle ){
  232. this.options.availableListStyles = availableListStyle;
  233. if( this.options.size == "max" ){
  234. this.reloadTopNode();
  235. }else{
  236. this.loadMin();
  237. }
  238. },
  239. createContentNode: function(){
  240. this.contentScrollNode = new Element("div.contentScrollNode", {"styles": this.css.contentScrollNode}).inject(this.node);
  241. this.content = new Element("div.content", {"styles": this.css.contentNode}).inject(this.contentScrollNode);
  242. var scrollFlag = this.contentScrollNode.getStyle("overflow-y");
  243. if (scrollFlag!=="auto" && scrollFlag!=="scroll"){
  244. o2.require("o2.widget.ScrollBar", function(){
  245. new o2.widget.ScrollBar(this.contentScrollNode, {
  246. "style":"attachment", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true}
  247. });
  248. }.bind(this));
  249. }
  250. },
  251. createBottomNode: function(){
  252. this.bottomNode = new Element("div", {"styles": this.css.bottomNode}).inject(this.node);
  253. },
  254. createResizeNode: function(){
  255. this.resizeNode = new Element("div", {"styles": this.css.resizeNode}).inject(this.bottomNode);
  256. this.resizeDrag = new Drag(this.resizeNode, {
  257. "snap": "2",
  258. "onStart": function(el, e){
  259. el.store("startY", e.event.y);
  260. el.store("nodeHeight", this.node.getSize().y);
  261. var minHeight = this.node.getStyle("min-height");
  262. el.store("nodeMinHeight", minHeight ? minHeight.toFloat() : "");
  263. var contentScrollNodeMinHeight = this.contentScrollNode.getStyle("min-height");
  264. el.store("contentScrollNodeMinHeight", contentScrollNodeMinHeight ? contentScrollNodeMinHeight.toFloat() : "");
  265. if (!this.nodeHeight){
  266. this.nodeHeight = minHeight.toFloat();
  267. }
  268. }.bind(this),
  269. "onDrag": function(el, e){
  270. var y = el.retrieve("startY");
  271. var nodeHeight = el.retrieve("nodeHeight");
  272. var nodeMinHeight = el.retrieve("nodeMinHeight");
  273. var contentScrollNodeMinHeight = el.retrieve("contentScrollNodeMinHeight");
  274. var setY = (e.event.y-y)+nodeHeight;
  275. if( nodeMinHeight && setY < nodeMinHeight && e.event.y<y)return;
  276. if (setY<this.nodeHeight) setY = this.nodeHeight;
  277. var setContentY = setY-81;
  278. if( contentScrollNodeMinHeight && setContentY < contentScrollNodeMinHeight && e.event.y<y )return;
  279. this.node.setStyle("height", ""+setY+"px");
  280. this.contentScrollNode.setStyle("height", ""+setContentY+"px");
  281. }.bind(this)
  282. });
  283. },
  284. createTopNode: function(){
  285. if (this.options.title){
  286. if (!this.titleNode) this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
  287. }
  288. if( !this.topNode ){
  289. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  290. }else{
  291. this.topNode.empty();
  292. this.editActionBoxNode = null;
  293. this.editActionsGroupNode=null;
  294. // this.topNode.setStyle("display","");
  295. this.topNode.show();
  296. if( this.isHiddenTop ){
  297. if( this.oldContentScrollNodeHeight && this.contentScrollNode ){
  298. this.contentScrollNode.setStyle("min-height",this.oldContentScrollNodeHeight);
  299. this.oldContentScrollNodeHeight = null;
  300. }
  301. this.isHiddenTop = false;
  302. }
  303. }
  304. var hiddenGroup = this.options.toolbarGroupHidden;
  305. if( hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") && hiddenGroup.contains("view")){
  306. if(this.contentScrollNode){
  307. this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
  308. this.contentScrollNode.setStyle("min-height",this.node.getStyle("min-height"));
  309. this.topNode.setStyle("display","none");
  310. }
  311. this.isHiddenTop = true;
  312. return;
  313. }
  314. if( !hiddenGroup.contains("edit") )this.createEditGroupActions();
  315. if( !hiddenGroup.contains("read") )this.createReadGroupActions();
  316. if( !hiddenGroup.contains("list") )this.createListGroupActions();
  317. if( !hiddenGroup.contains("view") )this.createViewGroupActions();
  318. if( layout.mobile ){
  319. this.checkActionsZoom();
  320. }
  321. //this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  322. //this.createEditGroupActions();
  323. //this.createReadGroupActions();
  324. //this.createListGroupActions();
  325. //this.createViewGroupActions();
  326. //this.createConfigGroupActions();
  327. },
  328. checkActionsZoom: function(){
  329. var width = 0;
  330. this.topNode.getChildren().each(function( node ){
  331. if(node.offsetParent)width = width + node.getSize().x + this.getOffsetX(node)
  332. }.bind(this));
  333. var topSize = this.topNode.getSize();
  334. if( (topSize.x - 5) < width ){
  335. var zoom = this.getDecimals((topSize.x - 5) / width);
  336. this.topNode.setStyle( "zoom", zoom*100+"%" );
  337. }
  338. },
  339. getDecimals: function(v){ //截取两位小数
  340. var decimals = 4;
  341. var p = Math.pow(10,decimals);
  342. var f_x = Math.round(v*p)/p;
  343. var str = f_x.toString();
  344. if (decimals>0){
  345. var pos_decimal = str.indexOf('.');
  346. if (pos_decimal < 0){
  347. pos_decimal = str.length;
  348. str += '.';
  349. }
  350. var decimalStr = (str).substr(pos_decimal+1, (str).length);
  351. while (decimalStr.length < decimals){
  352. str += '0';
  353. decimalStr += 0;
  354. }
  355. }
  356. return str;
  357. },
  358. getOffsetX : function(node){
  359. return (node.getStyle("margin-left").toInt() || 0 ) +
  360. (node.getStyle("margin-right").toInt() || 0 ) +
  361. (node.getStyle("padding-left").toInt() || 0 ) +
  362. (node.getStyle("padding-right").toInt() || 0 )+
  363. (node.getStyle("border-left-width").toInt() || 0 ) +
  364. (node.getStyle("border-right-width").toInt() || 0 );
  365. },
  366. reloadTopNode : function(){
  367. this.createTopNode();
  368. },
  369. createEditGroupActions: function(){
  370. if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  371. if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
  372. this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", o2.LP.widget.upload, function(e, node){
  373. this.uploadAttachment(e, node);
  374. }.bind(this));
  375. this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", o2.LP.widget["delete"], function(e, node){
  376. this.deleteAttachment(e, node);
  377. }.bind(this));
  378. if( !this.options.isReplaceHidden ){
  379. this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function(e, node){
  380. this.replaceAttachment(e, node);
  381. }.bind(this));
  382. }
  383. // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){
  384. // this.openInOfficeControl(e, node);
  385. // }.bind(this));
  386. if( !this.options.toolbarGroupHidden.contains("read") )this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
  387. },
  388. createReadGroupActions: function(){
  389. //this.readActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  390. //this.readActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.readActionBoxNode);
  391. if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  392. if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
  393. this.downloadAction = this.createAction(this.editActionsGroupNode, "download", o2.LP.widget.download, function(){
  394. this.downloadAttachment();
  395. }.bind(this));
  396. //this.createAction(this.readActionsGroupNode, "share", o2.LP.widget.share, function(){
  397. // this.transAttachment();
  398. //}.bind(this));
  399. //this.downloadAllAction = this.createAction(this.editActionsGroupNode, "downloadAll", o2.LP.widget.downloadAll, function(){
  400. // this.downloadAllAttachment();
  401. //}.bind(this));
  402. },
  403. createListGroupActions: function(){
  404. var availableListStyles = this.options.availableListStyles;
  405. if( availableListStyles && availableListStyles.length > 0 ){
  406. this.listActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  407. this.listActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.listActionBoxNode);
  408. if( availableListStyles.contains("list") ){
  409. this.listAction = this.createAction(this.listActionsGroupNode, "list", o2.LP.widget.list, function(){
  410. this.changeListStyle("list");
  411. }.bind(this));
  412. }
  413. if( availableListStyles.contains("seq") ) {
  414. this.sequenceAction = this.createAction(this.listActionsGroupNode, "seq", o2.LP.widget.sequence, function () {
  415. this.changeListStyle("sequence");
  416. }.bind(this));
  417. }
  418. if( availableListStyles.contains("icon") ) {
  419. this.iconAction = this.createAction(this.listActionsGroupNode, "icon", o2.LP.widget.icon, function () {
  420. this.changeListStyle("icon");
  421. }.bind(this));
  422. }
  423. if( availableListStyles.contains("preview") ) {
  424. this.previewAction = this.createAction(this.listActionsGroupNode, "preview", o2.LP.widget.preview, function () {
  425. this.changeListStyle("preview");
  426. }.bind(this));
  427. }
  428. }
  429. },
  430. createViewGroupActions: function(){
  431. if (this.options.isSizeChange){
  432. this.viewActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  433. this.viewActionBoxNode.setStyles({"float": "right", "margin-right": "7px"});
  434. this.viewActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.viewActionBoxNode);
  435. this.sizeAction = this.createAction(this.viewActionsGroupNode, "min", o2.LP.widget.min, function(){
  436. this.changeControllerSize();
  437. }.bind(this));
  438. }
  439. },
  440. createSeparate: function(groupNode){
  441. var separateNode = new Element("div.separateNode", {"styles": this.css.separateNode}).inject(groupNode);
  442. return separateNode;
  443. },
  444. createAction: function(groupNode, img, title, click){
  445. var actionNode = new Element("div", {"styles": this.css.actionNode, "title": title}).inject(groupNode);
  446. var actionIconNode = new Element("div", {"styles": this.css.actionIconNode}).inject(actionNode);
  447. actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/icon/"+img+".png)");
  448. var _self = this;
  449. actionNode.addEvents({
  450. "mouseover": function(){
  451. if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.options.style+"/overbg.png)");
  452. },
  453. "mouseout": function(){
  454. if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "transparent");
  455. },
  456. "click": function(e){
  457. if (!this.retrieve("disabled")) _self.doAction(e, this, click);
  458. e.stopPropagation();
  459. }
  460. });
  461. this.actions.push(actionNode);
  462. return actionNode;
  463. },
  464. checkActions: function(){
  465. // if (this.options.readonly){
  466. // this.setReadonly();
  467. // }else{
  468. this.checkUploadAction();
  469. this.checkDeleteAction();
  470. this.checkReplaceAction();
  471. //this.checkOfficeAction();
  472. this.checkDownloadAction();
  473. this.checkSizeAction();
  474. this.checkListStyleAction();
  475. if( this.options.size === "max" ){
  476. this.checkEditActionBox();
  477. }
  478. },
  479. checkEditActionBox: function(){
  480. var isShowEdit = false;
  481. ["isUpload", "isDelete", "isReplace"].each(function( key ){
  482. if( key === "isReplace" && this.options.isReplaceHidden )return;
  483. if( this.options[key] !== "hidden" )isShowEdit = true;
  484. }.bind(this));
  485. var isShowRead = false;
  486. ["isDownload"].each(function( key ){
  487. if( this.options[key] !== "hidden" )isShowRead = true;
  488. }.bind(this));
  489. if(this.editActionSeparateNode)this.editActionSeparateNode.setStyle( "display", isShowEdit && isShowRead ? "" : "none" );
  490. if(this.editActionBoxNode )this.editActionBoxNode.setStyle( "display", isShowEdit || isShowRead ? "" : "none" );
  491. },
  492. checkUploadAction: function(){
  493. if (this.options.readonly) {
  494. if (this.options.isUpload === "hidden") {
  495. this.setActionHidden(this.uploadAction);
  496. this.setActionHidden(this.min_uploadAction);
  497. } else {
  498. this.setActionDisabled(this.uploadAction);
  499. this.setActionDisabled(this.min_uploadAction);
  500. }
  501. return false;
  502. }
  503. if (this.options.isUpload === "hidden" ){
  504. this.setActionHidden(this.uploadAction);
  505. this.setActionHidden(this.min_uploadAction);
  506. }else if (!this.options.isUpload){
  507. this.setActionDisabled(this.uploadAction);
  508. this.setActionDisabled(this.min_uploadAction);
  509. }else{
  510. if (this.options.attachmentCount.toInt() > 0){
  511. if (this.attachments.length>=this.options.attachmentCount.toInt()){
  512. this.setActionDisabled(this.uploadAction);
  513. this.setActionDisabled(this.min_uploadAction);
  514. }else{
  515. this.setActionEnabled(this.uploadAction);
  516. this.setActionEnabled(this.min_uploadAction);
  517. }
  518. }else{
  519. this.setActionEnabled(this.uploadAction);
  520. this.setActionEnabled(this.min_uploadAction);
  521. }
  522. }
  523. },
  524. checkDeleteAction: function(){
  525. if (this.options.readonly){
  526. if (this.options.isDelete === "hidden") {
  527. this.setActionHidden(this.deleteAction);
  528. this.setActionHidden(this.min_deleteAction);
  529. } else {
  530. this.setActionDisabled(this.deleteAction);
  531. this.setActionDisabled(this.min_deleteAction);
  532. }
  533. this.setAttachmentsAction("delete", false );
  534. return false;
  535. }
  536. if (this.options.isDelete === "hidden") {
  537. this.setActionHidden(this.deleteAction);
  538. this.setActionHidden(this.min_deleteAction);
  539. this.setAttachmentsAction("delete", false );
  540. } else if (!this.options.isDelete){
  541. this.setActionDisabled(this.deleteAction);
  542. this.setActionDisabled(this.min_deleteAction);
  543. this.setAttachmentsAction("delete", false );
  544. }else{
  545. if (this.selectedAttachments.length){
  546. this.setActionEnabled(this.deleteAction);
  547. this.setActionEnabled(this.min_deleteAction);
  548. }else{
  549. this.setActionDisabled(this.deleteAction);
  550. this.setActionDisabled(this.min_deleteAction);
  551. }
  552. this.setAttachmentsAction("delete", true );
  553. }
  554. },
  555. isAttDeleteAvailable : function( att ){
  556. if (this.options.readonly)return false;
  557. if( this.options.toolbarGroupHidden.contains("edit") )return false;
  558. return this.options.isDelete && this.options.isDelete !== "hidden";
  559. },
  560. isAttEditAvailable : function( att ){
  561. if (this.options.readonly)return false;
  562. if( this.options.toolbarGroupHidden.contains("edit") )return false;
  563. return this.options.isEditAtt && this.options.isEditAtt !== "hidden";
  564. },
  565. // checkOfficeAction: function(){
  566. // if (this.officeAction) this.officeAction.setStyle("display", "none");
  567. // if (this.min_officeAction) this.min_officeAction.setStyle("display", "none");
  568. // },
  569. checkReplaceAction: function(){
  570. if( this.options.isReplaceHidden )return;
  571. if (this.options.readonly){
  572. if( this.options.isReplace === "hidden" ){
  573. this.setActionHidden(this.replaceAction);
  574. this.setActionHidden(this.min_replaceAction);
  575. }else{
  576. this.setActionDisabled(this.replaceAction);
  577. this.setActionDisabled(this.min_replaceAction);
  578. }
  579. this.setAttachmentsAction("replace", false );
  580. return false;
  581. }
  582. if( this.options.isReplace === "hidden" ){
  583. this.setActionHidden(this.replaceAction);
  584. this.setActionHidden(this.min_replaceAction);
  585. this.setAttachmentsAction("replace", false );
  586. }else if (!this.options.isReplace){
  587. this.setActionDisabled(this.replaceAction);
  588. this.setActionDisabled(this.min_replaceAction);
  589. this.setAttachmentsAction("replace", false );
  590. }else{
  591. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  592. this.setActionEnabled(this.replaceAction);
  593. this.setActionEnabled(this.min_replaceAction);
  594. }else{
  595. this.setActionDisabled(this.replaceAction);
  596. this.setActionDisabled(this.min_replaceAction);
  597. }
  598. this.setAttachmentsAction("replace", true );
  599. }
  600. },
  601. isAttReplaceAvailable : function( att ){
  602. if (this.options.readonly)return false;
  603. if( this.options.toolbarGroupHidden.contains("edit") )return false;
  604. return this.options.isReplace && this.options.isReplace !== "hidden";
  605. },
  606. checkDownloadAction: function(){
  607. if( this.options.isDownload === "hidden" ){
  608. this.setActionHidden(this.downloadAction);
  609. this.setActionHidden(this.min_downloadAction);
  610. this.setActionHidden(this.downloadAllAction);
  611. this.setAttachmentsAction("download", false );
  612. }else if (!this.options.isDownload){
  613. this.setActionDisabled(this.downloadAction);
  614. this.setActionDisabled(this.min_downloadAction);
  615. this.setActionDisabled(this.downloadAllAction);
  616. this.setAttachmentsAction("download", false );
  617. }else{
  618. if (this.selectedAttachments.length){
  619. this.setActionEnabled(this.downloadAction);
  620. this.setActionEnabled(this.min_downloadAction);
  621. }else{
  622. this.setActionDisabled(this.downloadAction);
  623. this.setActionDisabled(this.min_downloadAction);
  624. }
  625. this.setActionEnabled(this.downloadAllAction);
  626. this.setAttachmentsAction("download", true );
  627. }
  628. },
  629. isAttDblclickAvailable : function( att ){
  630. return this.options.dblclick && this.options.dblclick !== "hidden";
  631. },
  632. isAttDownloadAvailable : function( att ){
  633. if( this.options.toolbarGroupHidden.contains("read") )return false;
  634. return this.options.isDownload && this.options.isDownload !== "hidden";
  635. },
  636. checkSizeAction: function(){
  637. if( this.sizeAction ){
  638. if (this.options.isSizeChange){
  639. this.setActionEnabled(this.sizeAction);
  640. }else{
  641. this.setActionDisabled(this.sizeAction);
  642. }
  643. }
  644. },
  645. checkListStyleAction: function(){
  646. switch (this.options.listStyle){
  647. case "list":
  648. this.setActionSelcted(this.listAction);
  649. this.setActionUnSelcted(this.iconAction);
  650. this.setActionUnSelcted(this.previewAction);
  651. this.setActionUnSelcted(this.sequenceAction);
  652. break;
  653. case "icon":
  654. this.setActionUnSelcted(this.listAction);
  655. this.setActionSelcted(this.iconAction);
  656. this.setActionUnSelcted(this.previewAction);
  657. this.setActionUnSelcted(this.sequenceAction);
  658. break;
  659. case "preview":
  660. this.setActionUnSelcted(this.listAction);
  661. this.setActionUnSelcted(this.iconAction);
  662. this.setActionSelcted(this.previewAction);
  663. this.setActionUnSelcted(this.sequenceAction);
  664. break;
  665. case "sequence":
  666. this.setActionUnSelcted(this.listAction);
  667. this.setActionUnSelcted(this.iconAction);
  668. this.setActionUnSelcted(this.previewAction);
  669. this.setActionSelcted(this.sequenceAction);
  670. break;
  671. }
  672. },
  673. setActionSelcted: function(action){
  674. if (action){
  675. if (!action.retrieve("selected")){
  676. action.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/selectedbg.png)");
  677. action.store("selected", true);
  678. }
  679. }
  680. },
  681. setActionUnSelcted: function(action){
  682. if (action){
  683. if (action.retrieve("selected")){
  684. action.setStyle("background", "");
  685. action.store("selected", false);
  686. }
  687. }
  688. },
  689. setActionEnabled: function(action){
  690. if (action){
  691. action.show();
  692. if (action.retrieve("disabled")){
  693. var iconNode = action.getFirst();
  694. var icon = iconNode.getStyle("background-image");
  695. var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
  696. icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext;
  697. iconNode.setStyle("background-image", icon);
  698. action.store("disabled", false);
  699. }
  700. }
  701. },
  702. setActionDisabled: function(action){
  703. if (action){
  704. if (!action.retrieve("disabled")){
  705. var iconNode = action.getFirst();
  706. var icon = iconNode.getStyle("background-image");
  707. var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
  708. icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext;
  709. iconNode.setStyle("background-image", icon);
  710. action.store("disabled", true);
  711. }
  712. }
  713. },
  714. setActionHidden: function(action){
  715. if (action)action.hide();
  716. },
  717. setReadonly: function() {
  718. this.actions.each(function(action){
  719. this.setActionDisabled(action);
  720. this.setAttachmentsAction("all", false );
  721. }.bind(this));
  722. },
  723. setAttachmentsAction : function(type, enable){
  724. this.attachments.each( function( att ){
  725. this.setAttachmentAction( att, type, enable )
  726. }.bind(this))
  727. },
  728. setAttachmentAction : function(att, type, enable){
  729. var action;
  730. if( type === "all" ){
  731. ( att.actions || [] ).each( function(action){
  732. att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
  733. })
  734. }else{
  735. switch( type ){
  736. case "download" :
  737. action = att.downloadAction;
  738. break;
  739. case "config" :
  740. action = att.configAction;
  741. break;
  742. case "delete" :
  743. action = att.deleteAction;
  744. break;
  745. case "replace" :
  746. action = att.replaceAction;
  747. break;
  748. }
  749. if( !action )return;
  750. if( type === "config" ){
  751. var flag = enable;
  752. if( flag ){
  753. var user = layout.session.user.distinguishedName;
  754. if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid;
  755. if ((!att.data.control.allowControl ) && att.data.person!==user){ //|| !att.data.control.allowEdit
  756. flag = false;
  757. }
  758. }
  759. att[ flag ? "setActionEnabled" : "setActionDisabled" ](action);
  760. }else{
  761. att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
  762. }
  763. }
  764. },
  765. doAction: function(e, node, action){
  766. if (action){
  767. action.apply(this, [e, node]);
  768. }
  769. },
  770. uploadAttachment: function(e, node, files){
  771. debugger;
  772. if (this.module) this.module.uploadAttachment(e, node, files);
  773. },
  774. doUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){
  775. if ( !this.options.readonly && ( this.options.isUpload && this.options.isUpload !== "hidden") ){
  776. if (FormData.expiredIE){
  777. this.doInputUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery);
  778. }else{
  779. this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files);
  780. }
  781. }else{
  782. var text = o2.LP.widget.notUploadNotice;
  783. if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
  784. }
  785. },
  786. addUploadMessage: function(fileName){
  787. var contentHTML = "";
  788. contentHTML = "<div style=\"overflow: hidden\"><div style=\"height: 2px; border:0px solid #999; margin: 3px 0px\">" +
  789. "<div style=\"height: 2px; background-color: #acdab9; width: 0px;\"></div></div>" +
  790. "<div style=\"height: 20px; line-height: 20px\">"+o2.LP.desktop.action.uploadTitle+"</div></div>" +
  791. "<iframe name='o2_upload_iframe' style='display:none'></iframe>" ;
  792. var msg = {
  793. "subject": o2.LP.desktop.action.uploadTitle,
  794. "content": fileName+"<br/>"+contentHTML
  795. };
  796. if (layout.desktop.message){
  797. var messageItem = layout.desktop.message.addMessage(msg);
  798. messageItem.close = function(callback, e){
  799. if (!messageItem.completed){
  800. }else{
  801. messageItem.closeItem(callback, e);
  802. }
  803. };
  804. }
  805. window.setTimeout(function(){
  806. if (layout.desktop.message) if (!layout.desktop.message.isShow) layout.desktop.message.show();
  807. }.bind(this), 300);
  808. return messageItem;
  809. },
  810. setMessageTitle: function(messageItem, text){
  811. if (messageItem) messageItem.subjectNode.set("text", text);
  812. },
  813. setMessageText: function(messageItem, text){
  814. if (messageItem){
  815. var progressNode = messageItem.contentNode.getFirst("div").getFirst("div");
  816. var progressPercentNode = progressNode.getFirst("div");
  817. var progressInforNode = messageItem.contentNode.getFirst("div").getLast("div");
  818. progressInforNode.set("text", text);
  819. messageItem.dateNode.set("text", (new Date()).format("db"));
  820. }
  821. },
  822. doInputUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, failureEvery){
  823. var restActions = action;
  824. if (typeOf(action)=="string"){
  825. restActions = o2.Actions.get(action).action;
  826. }
  827. restActions.getActions(function(){
  828. var url = restActions.actions[invokeUrl];
  829. url = restActions.address+url.uri;
  830. Object.each(parameter, function(v, k){
  831. url = url.replace("{"+k+"}", v);
  832. });
  833. var maskNode = this.module.content;
  834. if (!maskNode){
  835. if (this.module.form){
  836. maskNode = this.module.form.app.content;
  837. }
  838. }
  839. if (!maskNode) maskNode = this.node;
  840. //var maskNode = this.module.content || this.module.node;
  841. if (maskNode){
  842. maskNode.mask({
  843. "style": {
  844. "opacity": 0.7,
  845. "background-color": "#999"
  846. }
  847. });
  848. }
  849. this.inputUploadAreaNode = new Element("div", {"styles": this.css.inputUploadAreaNode}).inject(this.container);
  850. this.inputUploadAreaNode.position({
  851. relativeTo: this.module.content,
  852. position: "center"
  853. });
  854. var messageItem = null;
  855. document.O2UploadCallbackFun = function(str){
  856. var json = JSON.decode(str);
  857. messageItem.completed = true;
  858. if (json.type==="success"){
  859. if (every) every(json.data);
  860. this.setMessageTitle(messageItem, o2.LP.desktop.action.uploadComplete);
  861. this.setMessageText(messageItem, o2.LP.desktop.action.uploadComplete);
  862. if(finish) finish();
  863. }else{
  864. //formNode.unmask();
  865. // if(failureEvery)failureEvery(json);
  866. this.setMessageTitle(messageItem, o2.LP.desktop.action.sendError);
  867. this.setMessageText(messageItem, o2.LP.desktop.action.sendError+": "+json.message);
  868. o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
  869. }
  870. }.bind(this);
  871. var formNode = new Element("form", {
  872. "method": "POST",
  873. "action": url+"/callback/window.frameElement.ownerDocument.O2UploadCallbackFun",
  874. //"action": url,
  875. "enctype": "multipart/form-data",
  876. "target": "o2_upload_iframe"
  877. }).inject(this.inputUploadAreaNode);
  878. var titleNode = new Element("div", {"styles": this.css.inputUploadAreaTitleNode, "text": o2.LP.widget.uploadTitle}).inject(formNode);
  879. var inforNode = new Element("div", {"styles": this.css.inputUploadAreaInforNode, "text": o2.LP.widget.uploadInfor}).inject(formNode);
  880. var inputAreaNode = new Element("div", {"styles": this.css.inputUploadAreaInputAreaNode}).inject(formNode);
  881. var inputNode = new Element("input", {"name":"file", "type": "file", "styles": this.css.inputUploadAreaInputNode}).inject(inputAreaNode);
  882. var inputNameNode = new Element("input", {"type": "hidden", "name": "fileName"}).inject(inputAreaNode);
  883. Object.each(obj, function(v, k){
  884. new Element("input", {"type": "hidden", "name": k, "value": v}).inject(inputAreaNode);
  885. });
  886. var actionNode = new Element("div", {"styles": this.css.inputUploadActionNode}).inject(formNode);
  887. var cancelButton = new Element("button", {"styles": this.css.inputUploadCancelButton, "text": o2.LP.widget.cancel}).inject(actionNode);
  888. var okButton = new Element("input", {"type": "button", "styles": this.css.inputUploadOkButton, "value": o2.LP.widget.ok}).inject(actionNode);
  889. inputNode.addEvent("change", function(){
  890. var fileName = inputNode.get("value");
  891. if (fileName){
  892. var tmpv = fileName.replace(/\\/g, "/");
  893. var i = tmpv.lastIndexOf("/");
  894. var fname = (i===-1) ? tmpv : tmpv.substr(i+1, tmpv.length-i);
  895. inputNameNode.set("value", fname);
  896. }
  897. }.bind(this));
  898. cancelButton.addEvent("click", function(){
  899. if (maskNode) maskNode.unmask();
  900. this.inputUploadAreaNode.destroy();
  901. }.bind(this));
  902. okButton.addEvent("click", function(){
  903. formNode.mask({
  904. "style": {
  905. "opacity": 0.7,
  906. "background-color": "#999"
  907. }
  908. });
  909. var isContinue = true;
  910. if (beforeUpload) isContinue = beforeUpload([inputNameNode.get("value")]);
  911. if (isContinue){
  912. messageItem = this.addUploadMessage(inputNameNode.get("value"));
  913. formNode.submit();
  914. if (maskNode) maskNode.unmask();
  915. if (this.inputUploadAreaNode) this.inputUploadAreaNode.destroy();
  916. }
  917. }.bind(this));
  918. }.bind(this));
  919. },
  920. doFormDataUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){
  921. var uploadChange = function(uploadfiles){
  922. var files = uploadfiles || this.fileUploadNode.files;
  923. if (files.length){
  924. var count = files.length;
  925. var current = 0;
  926. var hasFailUpload = false;
  927. var restActions = action;
  928. if (typeOf(action)=="string"){
  929. restActions = o2.Actions.get(action).action;
  930. }
  931. //var url = restActions.action.actions[invokeUri];
  932. var callback = function(){
  933. if (current == count){
  934. if(finish) finish( hasFailUpload );
  935. }
  936. };
  937. var isContinue = true;
  938. if (beforeUpload) isContinue = beforeUpload(files);
  939. if (isContinue){
  940. var accepts = (accept) ? accept.split(o2.splitStr) : null;
  941. for (var i = 0; i < files.length; i++) {
  942. var file = files.item(i);
  943. var ext = file.name.substr(file.name.lastIndexOf("."), file.name.length);
  944. ext = ext.toLowerCase();
  945. if (accepts && (accepts.indexOf(ext)===-1 && accepts.indexOf("*")===-1 && accepts.indexOf("*/*")===-1)){
  946. var msg = {
  947. "subject": o2.LP.widget.refuseUpload,
  948. "content": o2.LP.widget.refuseUploadHTML.replace("{filename}", file.name)
  949. };
  950. if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
  951. if (layout.desktop.message) layout.desktop.message.addMessage(msg);
  952. var text = o2.LP.widget.refuseUploadNotice.replace("{filename}", file.name);
  953. if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
  954. }else if (size && file.size> size*1024*1024){
  955. var msg = {
  956. "subject": o2.LP.widget.refuseUpload,
  957. "content": o2.LP.widget.refuseUploadHTML_size.replace("{filename}", file.name).replace("{size}", size)
  958. };
  959. if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
  960. if (layout.desktop.message) layout.desktop.message.addMessage(msg);
  961. var text = o2.LP.widget.refuseUploadNotice_size.replace("{filename}", file.name).replace("{size}", size);
  962. if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
  963. }else{
  964. var formData = new FormData();
  965. Object.each(obj, function(v, k){
  966. formData.append(k, v)
  967. });
  968. formData.append('file', file);
  969. if(parameter.fileMd5){
  970. o2.load("../o2_lib/CryptoJS/components/spark-md5-min.js", function(){
  971. var fileReader = new FileReader(), box = document.getElementById('box');
  972. var blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice;
  973. var chunkSize = 20971520;
  974. // read in chunks of 20MB
  975. var chunks = Math.ceil(file.size / chunkSize), currentChunk = 0, spark = new SparkMD5();
  976. fileReader.onload = function(e) {
  977. console.log("read chunk nr", currentChunk + 1, "of", chunks);
  978. spark.appendBinary(e.target.result);
  979. currentChunk++;
  980. if (currentChunk < chunks) {
  981. loadNext();
  982. } else {
  983. console.log("finished loading");
  984. var fileMd5 = spark.end();
  985. restActions.invoke({
  986. "name": "checkFileExist",
  987. "async": true,
  988. "parameter": {"fileMd5":fileMd5},
  989. "success": function(json){
  990. if(json.data.value){
  991. var formData2 = new FormData();
  992. formData2.append("fileMd5",fileMd5);
  993. formData2.append("fileName",file.name);
  994. restActions.invoke({
  995. "name": "addAttachmentMd5",
  996. "async": true,
  997. "data": formData2,
  998. "parameter": parameter,
  999. "success": function(json){
  1000. current++;
  1001. if (every) every(json, current, count);
  1002. callback();
  1003. },
  1004. "failure": function (xhr) {
  1005. var json = JSON.decode(xhr.responseText);
  1006. if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
  1007. current++;
  1008. hasFailUpload = true;
  1009. if (failureEvery) failureEvery(xhr, current, count);
  1010. callback();
  1011. }
  1012. });
  1013. }else{
  1014. restActions.invoke({
  1015. "name": invokeUrl,
  1016. "async": true,
  1017. "data": formData,
  1018. "file": file,
  1019. "parameter": parameter,
  1020. "success": function(json){
  1021. current++;
  1022. if (every) every(json, current, count);
  1023. callback();
  1024. },
  1025. "failure": function (xhr) {
  1026. var json = JSON.decode(xhr.responseText);
  1027. if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
  1028. current++;
  1029. hasFailUpload = true;
  1030. if (failureEvery) failureEvery(xhr, current, count);
  1031. callback();
  1032. }
  1033. });
  1034. }
  1035. }
  1036. });
  1037. // compute hash
  1038. }
  1039. };
  1040. function loadNext() {
  1041. var start = currentChunk * chunkSize, end = start + chunkSize >= file.size ? file.size : start + chunkSize;
  1042. fileReader.readAsBinaryString(blobSlice.call(file, start, end));
  1043. }
  1044. loadNext();
  1045. }.bind(this),null,false);
  1046. }else{
  1047. restActions.targetModule = {"module": this, "file": file};
  1048. restActions.invoke({
  1049. "name": invokeUrl,
  1050. "async": true,
  1051. "data": formData,
  1052. "file": file,
  1053. "parameter": parameter,
  1054. "success": function(json){
  1055. current++;
  1056. if (every) every(json, current, count);
  1057. callback();
  1058. },
  1059. "failure": function (xhr) {
  1060. var json = JSON.decode(xhr.responseText);
  1061. if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
  1062. current++;
  1063. hasFailUpload = true;
  1064. if (failureEvery) failureEvery(xhr, current, count);
  1065. callback();
  1066. }
  1067. });
  1068. }
  1069. }
  1070. }
  1071. }
  1072. this.uploadFileAreaNode.destroy();
  1073. this.uploadFileAreaNode = null;
  1074. }
  1075. }.bind(this);
  1076. if (!this.uploadFileAreaNode){
  1077. this.uploadFileAreaNode = new Element("div");
  1078. var html = "<input name=\"file\" multiple type=\"file\" accept=\"*/*\"/>";
  1079. this.uploadFileAreaNode.set("html", html);
  1080. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1081. this.fileUploadNode.addEvent("change", function(){
  1082. uploadChange();
  1083. });
  1084. }
  1085. this.fileUploadNode.set("accept", accept || "*/*");
  1086. this.fileUploadNode.set("multiple", (multiple!==false));
  1087. if (!files || !files.length){
  1088. this.fileUploadNode.click();
  1089. }else{
  1090. uploadChange(files)
  1091. }
  1092. },
  1093. addFormDataMessage: function(file){
  1094. return this.addAttachmentMessage(file);
  1095. },
  1096. addAttachmentMessage: function(file){
  1097. var messageItem;
  1098. if (this.options.size=="min"){
  1099. messageItem = new o2.widget.AttachmentController.AttachmentMessageMin(file, this);
  1100. }else{
  1101. messageItem = new o2.widget.AttachmentController.AttachmentMessage(file, this);
  1102. }
  1103. if (!this.messageItemList) this.messageItemList = {};
  1104. this.messageItemList[messageItem.data.id] = messageItem;
  1105. return messageItem;
  1106. },
  1107. openInOfficeControl: function(e, node){},
  1108. deleteAttachment: function(e, node){
  1109. if (this.selectedAttachments.length){
  1110. if (this.module) this.module.deleteAttachments(e, node, this.selectedAttachments);
  1111. }
  1112. },
  1113. replaceAttachment: function(e, node){
  1114. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  1115. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  1116. }
  1117. },
  1118. doReplaceAttachment: function(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size){
  1119. if (FormData.expiredIE){
  1120. this.doInputUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
  1121. }else{
  1122. this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
  1123. }
  1124. },
  1125. previewAttachment: function(e, node){
  1126. if (this.selectedAttachments.length){
  1127. if (this.module) this.module.previewAttachment(this.selectedAttachments);
  1128. }
  1129. },
  1130. editAttachment: function(e, node){
  1131. if (this.selectedAttachments.length){
  1132. if (this.module) this.module.editAttachment(this.selectedAttachments);
  1133. }
  1134. },
  1135. downloadAttachment: function(e, node){
  1136. if (this.selectedAttachments.length){
  1137. if (this.module) this.module.downloadAttachment(e, node, this.selectedAttachments);
  1138. }
  1139. },
  1140. openAttachment: function(e, node, attachment){
  1141. if( !this.options.dblclick ){
  1142. if( !this.options.isDownload || this.options.isDownload === "hidden" )return; //兼容以前的配置
  1143. }
  1144. if (attachment){
  1145. if (this.module) this.module.openAttachment(e, node, attachment);
  1146. }
  1147. },
  1148. dblclickAttachment: function(e, node, attachment){
  1149. if( !attachment || !this.module || this.options.dblclick === "disable" ){
  1150. return;
  1151. }else if( this.options.dblclick === "preview" ){
  1152. if( this.checkPreviewAttachment ){
  1153. this.checkPreviewAttachment(e, node, attachment);
  1154. }else{
  1155. this.module.openAttachment(e, node, attachment);
  1156. }
  1157. }else{
  1158. this.module.openAttachment(e, node, attachment);
  1159. }
  1160. },
  1161. downloadAllAttachment: function(e, node){
  1162. if (this.module) this.module.downloadAttachment(e, node, this.attachments);
  1163. },
  1164. changeListStyle: function(style){
  1165. this.options.listStyle = style;
  1166. this.listStyle = style;
  1167. this.attachments.each(function(attachment){
  1168. attachment.changeListStyle(style);
  1169. }.bind(this));
  1170. this.checkListStyleAction();
  1171. },
  1172. changeControllerSize: function(e, node){
  1173. if (this.options.size=="max"){
  1174. this.changeControllerSizeToMin();
  1175. }else{
  1176. this.changeControllerSizeToMax();
  1177. }
  1178. },
  1179. changeControllerSizeToMin: function(){
  1180. if (this.options.size!="min"){
  1181. // if (this.contentScrollNode) this.contentScrollNode.setStyle("display", "none");
  1182. // if (this.bottomNode) this.bottomNode.setStyle("display", "none");
  1183. // if (this.topNode) this.topNode.setStyle("display", "none");
  1184. // if (this.titleNode) this.titleNode.setStyle("display", "none");
  1185. if (this.contentScrollNode) this.contentScrollNode.hide();
  1186. if (this.bottomNode) this.bottomNode.hide();
  1187. if (this.topNode) this.topNode.hide();
  1188. if (this.titleNode) this.titleNode.hide();
  1189. if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100});
  1190. this.nodeMorph.start(this.css.container_min).chain(function(){
  1191. this.options.size = "min";
  1192. this.loadMin();
  1193. }.bind(this));
  1194. }
  1195. },
  1196. changeControllerSizeToMax: function(){
  1197. debugger;
  1198. if (this.options.size!="max") {
  1199. // if (this.minActionAreaNode) this.minActionAreaNode.setStyle("display", "none");
  1200. // if (this.minContent) this.minContent.setStyle("display", "none");
  1201. if (this.minActionAreaNode) this.minActionAreaNode.hide();
  1202. if (this.minContent) this.minContent.hide();
  1203. if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100});
  1204. this.nodeMorph.start(this.css.container).chain(function () {
  1205. this.options.size = "max";
  1206. this.loadMax();
  1207. }.bind(this));
  1208. }
  1209. },
  1210. getAttachmentNames: function(){
  1211. var names = [];
  1212. this.attachments.each(function(attachment){
  1213. names.push(attachment.data.name);
  1214. });
  1215. return names;
  1216. },
  1217. addAttachment: function(data, messageId, isCheckPosition){
  1218. if (this.options.size=="min"){
  1219. this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(data, this, messageId, isCheckPosition));
  1220. }else{
  1221. this.attachments.push(new o2.widget.AttachmentController.Attachment(data, this, messageId, isCheckPosition));
  1222. }
  1223. this.checkActions();
  1224. },
  1225. removeAttachment: function(attachment){
  1226. this.attachments.erase(attachment);
  1227. this.selectedAttachments.erase(attachment);
  1228. attachment.node.destroy();
  1229. delete attachment;
  1230. },
  1231. unSelectedAttachments: function(){
  1232. while (this.selectedAttachments.length){
  1233. var attachment = this.selectedAttachments.shift();
  1234. attachment.unSelected();
  1235. }
  1236. this.checkActions();
  1237. },
  1238. clear: function(){
  1239. this.selectedAttachments = [];
  1240. this.attachments.each(function(att){
  1241. att.node.destroy();
  1242. o2.release(att);
  1243. });
  1244. this.attachments = [];
  1245. var content = (this.minContent || this.content);
  1246. if (content) content.empty();
  1247. }
  1248. });
  1249. o2.widget.AttachmentController.Attachment = new Class({
  1250. Implements: [Events],
  1251. initialize: function(data, controller, messageId, isCheckPosition){
  1252. this.data = data;
  1253. if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
  1254. this.controller = controller;
  1255. this.css = this.controller.css;
  1256. this.listStyle = this.controller.options.listStyle;
  1257. this.content = this.controller.content;
  1258. this.isSelected = false;
  1259. this.seq = this.controller.attachments.length+1;
  1260. this.isCheckPosition = isCheckPosition;
  1261. this.actions = [];
  1262. if (messageId && this.controller.messageItemList) {
  1263. this.message = this.controller.messageItemList[messageId];
  1264. }
  1265. this.load();
  1266. },
  1267. _getLnkPar: function(url){
  1268. return {
  1269. "icon": this.getIcon(),
  1270. "title": this.data.name,
  1271. "par": "@url#"+url
  1272. };
  1273. },
  1274. isNumber : function( d ){
  1275. return parseFloat(d).toString() !== "NaN"
  1276. },
  1277. load: function(){
  1278. if( this.controller.module && this.controller.module.fireEvent ){
  1279. this.controller.module.fireEvent("beforeLoadAttachment", [this]);
  1280. }
  1281. if (this.message){
  1282. this.node = new Element("div").inject(this.message.node, "after");
  1283. this.message.node.destroy();
  1284. delete this.controller.messageItemList[this.message.data.id];
  1285. }else{
  1286. this.node = new Element("div").inject(this.content);
  1287. }
  1288. if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){
  1289. var attList = this.controller.attachments;
  1290. for( var i=0; i<attList.length; i++ ){
  1291. var att = attList[i];
  1292. if( !this.isNumber(att.data.orderNumber) || this.data.orderNumber < att.data.orderNumber ){
  1293. this.node.inject( att.node, "before" );
  1294. break;
  1295. }
  1296. }
  1297. }
  1298. switch (this.controller.options.listStyle){
  1299. case "list":
  1300. this.loadList();
  1301. break;
  1302. case "icon":
  1303. this.loadIcon();
  1304. break;
  1305. case "preview":
  1306. this.loadPreview();
  1307. break;
  1308. case "sequence":
  1309. this.loadSequence();
  1310. break;
  1311. }
  1312. this.controller.module.getAttachmentUrl(this, function(url){
  1313. this.node.makeLnk({
  1314. "par": this._getLnkPar(url)
  1315. });
  1316. }.bind(this));
  1317. this.createInforNode(function(){
  1318. if (!Browser.Platform.ios){
  1319. this.tooltip = new mBox.Tooltip({
  1320. content: this.inforNode,
  1321. setStyles: {content: {padding: 15, lineHeight: 20}},
  1322. attach: this.node,
  1323. transition: 'flyin'
  1324. });
  1325. }
  1326. }.bind(this));
  1327. this.setEvent();
  1328. if( this.controller.module && this.controller.module.fireEvent ){
  1329. this.controller.module.fireEvent("loadAttachment", [this]);
  1330. }
  1331. },
  1332. createInforNode: function(callback){
  1333. var size = "";
  1334. var k = this.data.length/1024;
  1335. if (k>1024){
  1336. var m = k/1024;
  1337. m = Math.round(m*100)/100;
  1338. size = m+"M";
  1339. }else{
  1340. k = Math.round(k*100)/100;
  1341. size = k+"K";
  1342. }
  1343. this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode});
  1344. var html = "<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";
  1345. html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploader+": </div><div style='width:120px; float:left; margin-left:10px'>"+( this.data.person || this.data.creatorUid )+"</div></div>";
  1346. html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploadTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.createTime+"</div></div>";
  1347. html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.modifyTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.lastUpdateTime+"</div></div>";
  1348. if(this.data.activityName)html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploadActivity+": </div><div style='width:120px; float:left; margin-left:10px'>"+(this.data.activityName || o2.LP.widget.unknow)+"</div></div>";
  1349. html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.size+": </div><div style='width:120px; float:left; margin-left:10px'>"+size+"</div></div>";
  1350. this.inforNode.set("html", html);
  1351. if (callback) callback();
  1352. },
  1353. getIcon: function(){
  1354. if (!this.data.extension) this.data.extension="unkonw";
  1355. var iconName = this.controller.icons[this.data.extension.toLowerCase()] || this.controller.icons.unknow;
  1356. var iconFolderUrl = this.controller.options.iconFolderUrl ? this.controller.options.iconFolderUrl : "../x_component_File/$Main/default/file/";
  1357. return iconFolderUrl+iconName;
  1358. },
  1359. loadList: function(){
  1360. this.node.setStyles(this.css.attachmentNode_list);
  1361. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_list_selected);
  1362. this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
  1363. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
  1364. this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  1365. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1366. this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_list}).inject(this.node);
  1367. this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
  1368. // this.textTitleNode.set("text", this.data.name);
  1369. if (this.data.objectSecurityPromise){
  1370. this.data.objectSecurityPromise.then(function(label){
  1371. this.textTitleNode.set("text", "("+label+") " + this.data.name);
  1372. }.bind(this));
  1373. }else{
  1374. this.textTitleNode.set("text", this.data.name);
  1375. }
  1376. var size = "";
  1377. var k = this.data.length/1024;
  1378. if (k>1024){
  1379. var m = k/1024;
  1380. m = Math.round(m*100)/100;
  1381. size = m+"M";
  1382. }else{
  1383. k = Math.round(k*100)/100;
  1384. size = k+"K";
  1385. }
  1386. this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
  1387. this.textSizeNode.set("text", size);
  1388. this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
  1389. this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid ));
  1390. this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
  1391. this.textTimeNode.set("text", this.data.lastUpdateTime);
  1392. if(this.data.activityName){
  1393. this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
  1394. this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);
  1395. }
  1396. this.custom_List();
  1397. },
  1398. custom_List: function(){},
  1399. loadSequence: function(){
  1400. this.node.setStyles(this.css.attachmentNode_sequence);
  1401. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_sequence_selected);
  1402. this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);
  1403. this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_sequence || this.css.attachmentIconNode_list}).inject(this.node);
  1404. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
  1405. this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  1406. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1407. this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_sequence}).inject(this.node);
  1408. this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
  1409. // this.textTitleNode.set("text", this.data.name);
  1410. if (this.data.objectSecurityPromise){
  1411. this.data.objectSecurityPromise.then(function(label){
  1412. this.textTitleNode.set("text", "("+label+") " + this.data.name);
  1413. }.bind(this));
  1414. }else{
  1415. this.textTitleNode.set("text", this.data.name);
  1416. }
  1417. var size = "";
  1418. var k = this.data.length/1024;
  1419. if (k>1024){
  1420. var m = k/1024;
  1421. m = Math.round(m*100)/100;
  1422. size = m+"M";
  1423. }else{
  1424. k = Math.round(k*100)/100;
  1425. size = k+"K";
  1426. }
  1427. this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
  1428. this.textSizeNode.set("text", size);
  1429. this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
  1430. this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid));
  1431. this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
  1432. this.textTimeNode.set("text", this.data.lastUpdateTime);
  1433. if(this.data.activityName){
  1434. this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
  1435. this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);
  1436. }
  1437. this.custom_Sequence();
  1438. },
  1439. custom_Sequence: function(){},
  1440. loadIcon: function(){
  1441. this.node.setStyles(this.css.attachmentNode_icon);
  1442. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_icon_selected);
  1443. this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode}).inject(this.node);
  1444. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode}).inject(this.iconNode);
  1445. this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode}).inject(this.iconImgAreaNode);
  1446. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1447. this.textNode = new Element("div", {"styles": this.css.attachmentTextNode}).inject(this.node);
  1448. if (this.data.objectSecurityPromise){
  1449. this.data.objectSecurityPromise.then(function(label){
  1450. this.textNode.set("text", "("+label+") " + this.data.name);
  1451. }.bind(this));
  1452. }else{
  1453. this.textNode.set("text", this.data.name);
  1454. }
  1455. this.custom_Icon();
  1456. },
  1457. custom_Icon: function(){},
  1458. loadPreview: function(){
  1459. this.node.setStyles(this.css.attachmentNode_preview);
  1460. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_preview_selected);
  1461. this.iconNode = new Element("div", {"styles": this.css.attachmentPreviewIconNode}).inject(this.node);
  1462. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentPreviewIconImgAreaNode}).inject(this.iconNode);
  1463. this.iconImgNode = new Element("img", {"styles": this.css.attachmentPreviewIconImgNode}).inject(this.iconImgAreaNode);
  1464. var icon = this.getIcon();
  1465. if (this.controller.options.images.indexOf(this.data.extension.toLowerCase())!==-1){
  1466. if (this.type!=="message") this.controller.module.getAttachmentUrl(this, function(url){
  1467. this.iconImgAreaNode.hide();
  1468. this.iconImgNode.hide();
  1469. this.iconNode.setStyles({
  1470. "background-image": "url("+url+")",
  1471. });
  1472. }.bind(this));
  1473. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  1474. if (this.data.objectSecurityPromise){
  1475. this.data.objectSecurityPromise.then(function(label){
  1476. this.textNode.set("text", "("+label+") " + this.data.name);
  1477. }.bind(this));
  1478. }else{
  1479. this.textNode.set("text", this.data.name);
  1480. }
  1481. // this.textNode.set("text", this.data.name);
  1482. }else if (this.controller.options.audios.indexOf(this.data.extension.toLowerCase())!==-1){
  1483. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  1484. if (this.data.objectSecurityPromise){
  1485. this.data.objectSecurityPromise.then(function(label){
  1486. this.textNode.set("text", "("+label+") " + this.data.name);
  1487. }.bind(this));
  1488. }else{
  1489. this.textNode.set("text", this.data.name);
  1490. }
  1491. // this.textNode.set("text", this.data.name);
  1492. this.controller.module.getAttachmentUrl(this, function(url){
  1493. this.iconImgNode.set({"src": icon, "border": 0});
  1494. this.iconAudioNode = new Element("div", {
  1495. "styles": this.css.attachmentPreviewAudioNode,
  1496. "html": "<audio preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+url+"\" type=\"audio/mpeg\"></source></audio>"
  1497. //"html": "<audio controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+o2.session.path+"/xApplication/File/$Main/qnyh.mp3\"></source></audio>"
  1498. }).inject(this.textNode, "after");
  1499. this.iconAudioNode.addEvent("dblclick", function(e){e.stopPropagation();});
  1500. }.bind(this));
  1501. }else if (this.controller.options.videos.indexOf(this.data.extension.toLowerCase())!==-1){
  1502. this.controller.module.getAttachmentUrl(this, function(url){
  1503. this.iconNode.empty();
  1504. this.iconVideoNode = new Element("div", {
  1505. "styles": this.css.attachmentPreviewVideoNode,
  1506. //"html": "<video preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+o2.session.path+"/xApplication/File/$Main/IMG_1615.MOV\"></source></video>"
  1507. "html": "<video preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+url+"\"></source></video>"
  1508. }).inject(this.iconNode);
  1509. this.iconVideoNode.addEvent("dblclick", function(e){e.stopPropagation();});
  1510. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  1511. if (this.data.objectSecurityPromise){
  1512. this.data.objectSecurityPromise.then(function(label){
  1513. this.textNode.set("text", "("+label+") " + this.data.name);
  1514. }.bind(this));
  1515. }else{
  1516. this.textNode.set("text", this.data.name);
  1517. }
  1518. // this.textNode.set("text", this.data.name);
  1519. }.bind(this));
  1520. }else{
  1521. this.iconImgNode.set({"src": icon, "border": 0});
  1522. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  1523. if (this.data.objectSecurityPromise){
  1524. this.data.objectSecurityPromise.then(function(label){
  1525. this.textNode.set("text", "("+label+") " + this.data.name);
  1526. }.bind(this));
  1527. }else{
  1528. this.textNode.set("text", this.data.name);
  1529. }
  1530. // this.textNode.set("text", this.data.name);
  1531. }
  1532. this.custom_Preview();
  1533. },
  1534. custom_Preview: function(){},
  1535. getPreviewImgSize: function(icon, callback){
  1536. var areaSize = this.iconNode.getSize();
  1537. var img = new Element("img", {"src": icon}).inject($(document.body));
  1538. img.set("src", icon);
  1539. var size = img.getSize();
  1540. img.destroy();
  1541. var x, y;
  1542. var zoom = areaSize.x/size.x;
  1543. var y = size.y*zoom;
  1544. if (y<=areaSize.y){
  1545. x = areaSize.x;
  1546. }else{
  1547. zoom = areaSize.y/size.y;
  1548. x = size.x*zoom;
  1549. y = areaSize.y;
  1550. }
  1551. var size = {"x": x, "y": y, "top": (areaSize.y-y)/2};
  1552. if (callback) callback(size);
  1553. },
  1554. setEvent: function(){
  1555. this.node.addEvents({
  1556. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"])}.bind(this),
  1557. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle])}.bind(this),
  1558. "mousedown": function(e){this.selected(e); e.stopPropagation();}.bind(this),
  1559. "click": function(e){e.stopPropagation();}.bind(this),
  1560. "dblclick": function(e){
  1561. if( this.controller.options.dblclick ){
  1562. this.controller.dblclickAttachment(e, null, [this]);
  1563. }else{
  1564. this.openAttachment(e);
  1565. }
  1566. }.bind(this)
  1567. });
  1568. if (this.iconImgNode){
  1569. this.iconImgNode.set("draggable", false);
  1570. }
  1571. },
  1572. selected: function(e){
  1573. if (!e.event.ctrlKey) this.controller.unSelectedAttachments();
  1574. //if (!this.isSelected){
  1575. this.controller.selectedAttachments.push(this);
  1576. this.isSelected = true;
  1577. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]);
  1578. //}
  1579. if( this.controller.module && this.controller.module.fireEvent ){
  1580. this.controller.module.fireEvent("select", [this]);
  1581. }
  1582. if (e) e.stopPropagation();
  1583. this.controller.checkActions();
  1584. },
  1585. unSelected: function(){
  1586. this.isSelected = false;
  1587. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
  1588. this.controller.selectedAttachments.erase(this);
  1589. if( this.controller.module && this.controller.module.fireEvent ){
  1590. this.controller.module.fireEvent("unselect", [this]);
  1591. }
  1592. },
  1593. changeListStyle: function(style){
  1594. if (this.listStyle!=style){
  1595. this.node.empty();
  1596. switch (style){
  1597. case "list":
  1598. this.loadList();
  1599. break;
  1600. case "icon":
  1601. this.loadIcon();
  1602. break;
  1603. case "preview":
  1604. this.loadPreview();
  1605. break;
  1606. case "sequence":
  1607. this.loadSequence();
  1608. break;
  1609. }
  1610. this.listStyle = style;
  1611. }
  1612. },
  1613. reload: function(){
  1614. var node = new Element("div").inject(this.node, "after");
  1615. this.inforNode.destroy();
  1616. this.inforNode = null;
  1617. if (this.tooltip) this.tooltip.destroy();
  1618. this.tooltip = null;
  1619. this.node.destroy();
  1620. delete this.node;
  1621. this.node = node;
  1622. switch (this.listStyle){
  1623. case "list":
  1624. this.loadList();
  1625. break;
  1626. case "icon":
  1627. this.loadIcon();
  1628. break;
  1629. case "preview":
  1630. this.loadPreview();
  1631. break;
  1632. case "sequence":
  1633. this.loadSequence();
  1634. break;
  1635. }
  1636. this.createInforNode();
  1637. if (!Browser.Platform.ios){
  1638. this.tooltip = new mBox.Tooltip({
  1639. content: this.inforNode,
  1640. setStyles: {content: {padding: 15, lineHeight: 20}},
  1641. attach: this.node,
  1642. transition: 'flyin'
  1643. });
  1644. }
  1645. this.setEvent();
  1646. },
  1647. openAttachment: function(e){
  1648. if( !this.controller.options.dblclick ){
  1649. if (!this.controller.options.isDownload || this.controller.options.isDownload === "hidden") return; //兼容以前的配置
  1650. }
  1651. if (this.controller.module) this.controller.module.openAttachment(e, null, [this]);
  1652. },
  1653. setActionEnabled: function(action){
  1654. if (action){
  1655. action.setStyle("display","");
  1656. action.store("disabled", false);
  1657. //if (action.retrieve("disabled")){
  1658. // var iconNode = action.getFirst();
  1659. // var icon = iconNode.getStyle("background-image");
  1660. // var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
  1661. // icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext;
  1662. // iconNode.setStyle("background-image", icon);
  1663. // action.store("disabled", false);
  1664. //}
  1665. }
  1666. },
  1667. setActionDisabled: function(action){
  1668. if (action){
  1669. action.setStyle("display","none");
  1670. action.store("disabled", true);
  1671. //if (!action.retrieve("disabled")){
  1672. // var iconNode = action.getFirst();
  1673. // var icon = iconNode.getStyle("background-image");
  1674. // var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
  1675. // icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext;
  1676. // iconNode.setStyle("background-image", icon);
  1677. // action.store("disabled", true);
  1678. //}
  1679. }
  1680. },
  1681. createAction: function(node, img, img_over, title, click, text){
  1682. var actionNode;
  1683. if( this.controller.options.actionShowText ){
  1684. actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "text": text || title, "title" : title }).inject(node);
  1685. var _self = this;
  1686. actionNode.addEvents({
  1687. "mouseover": function( e ){
  1688. if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over){
  1689. actionNode.setStyles( _self.controller.css.minActionNode_over );
  1690. }
  1691. }.bind( { actionNode : actionNode } ),
  1692. "mouseout": function(){
  1693. if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over ){
  1694. actionNode.setStyles( _self.controller.css.minActionNode );
  1695. }
  1696. }.bind( { actionNode : actionNode } ),
  1697. "click": function(e){
  1698. if (!this.retrieve("disabled")){
  1699. click.apply(_self.controller, [e, this]);
  1700. e.stopPropagation();
  1701. }
  1702. }
  1703. });
  1704. }else{
  1705. actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "title": title}).inject(node);
  1706. var actionIconNode = new Element("div", {"styles": this.controller.css.minActionIconNode}).inject(actionNode);
  1707. actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.controller.options.style+"/icon/"+img+".png)");
  1708. var _self = this;
  1709. actionNode.addEvents({
  1710. "mouseover": function( e ){
  1711. if (!this.actionNode.retrieve("disabled")){
  1712. this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)");
  1713. }
  1714. }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img_over } ),
  1715. "mouseout": function(){
  1716. if (!this.actionNode.retrieve("disabled")){
  1717. this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)");
  1718. }
  1719. }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img } ),
  1720. "click": function(e){
  1721. if (!this.retrieve("disabled")){
  1722. click.apply(_self.controller, [e, this]);
  1723. e.stopPropagation();
  1724. }
  1725. }
  1726. });
  1727. }
  1728. if( !this.actions )this.actions = [];
  1729. this.actions.push(actionNode);
  1730. return actionNode;
  1731. }
  1732. });
  1733. o2.widget.AttachmentController.AttachmentMin = new Class({
  1734. Extends: o2.widget.AttachmentController.Attachment,
  1735. initialize: function(data, controller, messageId, isCheckPosition){
  1736. this.data = data;
  1737. if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
  1738. this.controller = controller;
  1739. this.css = this.controller.css;
  1740. this.listStyle = this.controller.options.listStyle;
  1741. this.content = this.controller.minContent;
  1742. this.isSelected = false;
  1743. this.isCheckPosition = isCheckPosition;
  1744. this.seq = this.controller.attachments.length+1;
  1745. if (messageId && this.controller.messageItemList) {
  1746. this.message = this.controller.messageItemList[messageId];
  1747. }
  1748. this.load();
  1749. },
  1750. load: function(){
  1751. if( this.controller.module && this.controller.module.fireEvent ){
  1752. this.controller.module.fireEvent("beforeLoadAttachment", [this]);
  1753. }
  1754. if (this.message){
  1755. this.node = new Element("div").inject(this.message.node, "after");
  1756. this.message.node.destroy();
  1757. delete this.controller.messageItemList[this.message.data.id];
  1758. }else{
  1759. this.node = new Element("div").inject(this.content);
  1760. }
  1761. if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){
  1762. var attList = this.controller.attachments;
  1763. for( var i=0; i<attList.length; i++ ){
  1764. var att = attList[i];
  1765. if( !this.isNumber(att.data.orderNumber) || this.data.orderNumber < att.data.orderNumber ){
  1766. this.node.inject( att.node, "before" );
  1767. break;
  1768. }
  1769. }
  1770. }
  1771. //this.node = new Element("div").inject(this.content);
  1772. //this.loadList();
  1773. switch (this.controller.options.listStyle){
  1774. case "list":
  1775. this.loadList();
  1776. break;
  1777. case "icon":
  1778. this.loadIcon();
  1779. break;
  1780. case "preview":
  1781. this.loadPreview();
  1782. break;
  1783. case "sequence":
  1784. this.loadSequence();
  1785. break;
  1786. }
  1787. this.createInforNode();
  1788. if (!Browser.Platform.ios && !layout.mobile){
  1789. this.tooltip = new mBox.Tooltip({
  1790. content: this.inforNode,
  1791. setStyles: {content: {padding: 15, lineHeight: 20}},
  1792. attach: this.iconImgNode,
  1793. transition: 'flyin'
  1794. });
  1795. }
  1796. this.setEvent();
  1797. if( this.controller.module && this.controller.module.fireEvent ){
  1798. this.controller.module.fireEvent("loadAttachment", [this]);
  1799. }
  1800. },
  1801. loadList: function() {
  1802. this.node.setStyles( layout.mobile ? this.css.minAttachmentNode_list_mobile : this.css.minAttachmentNode_list);
  1803. if( !layout.mobile ){
  1804. this.sepNode = new Element("div", {"styles": this.css.minAttachmentSepNode_list}).inject(this.node);
  1805. }
  1806. this.actionAreaNode = new Element("div", {"styles": this.css.minAttachmentActionAreaNode}).inject(this.node);
  1807. if( this.controller.isAttDblclickAvailable(this) ){
  1808. this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) {
  1809. this.controller.dblclickAttachment(e, node, [this]);
  1810. }.bind(this));
  1811. }
  1812. if ( this.controller.isAttDownloadAvailable(this) ) {
  1813. this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) {
  1814. this.controller.downloadAttachment(e, node);
  1815. }.bind(this));
  1816. }
  1817. //this.actions.push( this.downloadAction );
  1818. if ( this.controller.isAttDeleteAvailable(this) ) {
  1819. this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) {
  1820. this.controller.deleteAttachment(e, node);
  1821. }.bind(this));
  1822. }
  1823. if ( this.controller.isAttEditAvailable(this) ) {
  1824. this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) {
  1825. this.controller.editAttachment(e, node);
  1826. }.bind(this));
  1827. }
  1828. //this.actions.push( this.deleteAction );
  1829. if (this.controller.configAttachment) {
  1830. if ( this.controller.isAttConfigAvailable(this) ) {
  1831. this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", o2.LP.widget.configAttachment, function (e, node) {
  1832. this.controller.configAttachment(e, node);
  1833. }.bind(this), o2.LP.widget.configAttachmentText );
  1834. //this.actions.push( this.configAction );
  1835. }
  1836. }
  1837. if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected);
  1838. this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node);
  1839. this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode);
  1840. this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  1841. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1842. this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node);
  1843. if (this.data.objectSecurityPromise){
  1844. this.data.objectSecurityPromise.then(function(label){
  1845. this.textNode.set("text", "("+label+") " + this.data.name);
  1846. }.bind(this));
  1847. }else{
  1848. this.textNode.set("text", this.data.name);
  1849. }
  1850. // this.textNode.set("text", this.data.name);
  1851. var size = "";
  1852. var k = this.data.length/1024;
  1853. if (k>1024){
  1854. var m = k/1024;
  1855. m = Math.round(m*100)/100;
  1856. size = m+"M";
  1857. }else{
  1858. k = Math.round(k*100)/100;
  1859. size = k+"K";
  1860. }
  1861. this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode);
  1862. this.textSizeNode.set("text", "("+size+")");
  1863. this.node.set("title",this.data.name + "("+size+")");
  1864. },
  1865. loadSequence: function(){
  1866. this.node.setStyles(this.css.minAttachmentNode_sequence);
  1867. this.actionAreaNode = new Element("div", {"styles":this.css.minAttachmentActionAreaNode}).inject(this.node);
  1868. if( this.controller.isAttDblclickAvailable(this) ){
  1869. this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) {
  1870. this.controller.dblclickAttachment(e, node, [this]);
  1871. }.bind(this));
  1872. }
  1873. if ( this.controller.isAttDownloadAvailable(this) ) {
  1874. this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) {
  1875. this.controller.downloadAttachment(e, node);
  1876. }.bind(this));
  1877. }
  1878. //this.actions.push( this.downloadAction );
  1879. if ( this.controller.isAttDeleteAvailable(this) ) {
  1880. this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) {
  1881. this.controller.deleteAttachment(e, node);
  1882. }.bind(this));
  1883. }
  1884. if ( this.controller.isAttEditAvailable(this) ) {
  1885. this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) {
  1886. this.controller.editAttachment(e, node);
  1887. }.bind(this));
  1888. }
  1889. //this.actions.push( this.deleteAction );
  1890. if (this.controller.configAttachment) {
  1891. if ( this.controller.isAttConfigAvailable(this) ) {
  1892. this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", MWF.LP.widget.configAttachment, function (e, node) {
  1893. this.controller.configAttachment(e, node);
  1894. }.bind(this));
  1895. //this.actions.push( this.configAction );
  1896. }
  1897. }
  1898. if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected);
  1899. this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);
  1900. this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node);
  1901. this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode);
  1902. this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  1903. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1904. this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node);
  1905. if (this.data.objectSecurityPromise){
  1906. this.data.objectSecurityPromise.then(function(label){
  1907. this.textNode.set("text", "("+label+") " + this.data.name);
  1908. }.bind(this));
  1909. }else{
  1910. this.textNode.set("text", this.data.name);
  1911. }
  1912. // this.textNode.set("text", this.data.name);
  1913. var size = "";
  1914. var k = this.data.length/1024;
  1915. if (k>1024){
  1916. var m = k/1024;
  1917. m = Math.round(m*100)/100;
  1918. size = m+"M";
  1919. }else{
  1920. k = Math.round(k*100)/100;
  1921. size = k+"K";
  1922. }
  1923. this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode);
  1924. this.textSizeNode.set("text", "("+size+")");
  1925. },
  1926. setEvent: function(){
  1927. this.node.addEvents({
  1928. "mouseover": function(){
  1929. if (!this.isSelected){
  1930. if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
  1931. this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_over"]);
  1932. }else{
  1933. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"]);
  1934. }
  1935. }
  1936. }.bind(this),
  1937. "mouseout": function(){
  1938. if (!this.isSelected){
  1939. if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
  1940. var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
  1941. this.node.setStyles(this.css[cssKey]);
  1942. }else{
  1943. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
  1944. }
  1945. }
  1946. }.bind(this),
  1947. "mousedown": function(e){this.selected(e);e.stopPropagation();}.bind(this),
  1948. "click": function(e){e.stopPropagation();}.bind(this),
  1949. "dblclick": function(e){
  1950. if( this.controller.options.dblclick ){
  1951. this.controller.dblclickAttachment(e, null, [this]);
  1952. }else{
  1953. this.openAttachment(e);
  1954. }
  1955. }.bind(this)
  1956. });
  1957. if (this.iconImgNode){
  1958. this.iconImgNode.set("draggable", false);
  1959. }
  1960. },
  1961. selected: function(e){
  1962. if (!e.event.ctrlKey) this.controller.unSelectedAttachments();
  1963. //if (!this.isSelected){
  1964. this.controller.selectedAttachments.push(this);
  1965. this.isSelected = true;
  1966. if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
  1967. //this.node.setStyles(this.css["minAttachmentNode_list_selected"]);
  1968. this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_selected"]);
  1969. }else{
  1970. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]);
  1971. //this.node.setStyles(this.css["minAttachmentNode_list_selected"]);
  1972. }
  1973. if( this.controller.module && this.controller.module.fireEvent ){
  1974. this.controller.module.fireEvent("select", [this]);
  1975. }
  1976. //}
  1977. if (e) e.stopPropagation();
  1978. this.controller.checkActions();
  1979. },
  1980. reload: function(){
  1981. var node = new Element("div").inject(this.node, "after");
  1982. this.inforNode.destroy();
  1983. this.inforNode = null;
  1984. if (this.tooltip) this.tooltip.destroy();
  1985. this.tooltip = null;
  1986. this.node.destroy();
  1987. delete this.node;
  1988. this.node = node;
  1989. debugger;
  1990. switch (this.listStyle){
  1991. case "list":
  1992. this.loadList();
  1993. break;
  1994. case "icon":
  1995. this.loadIcon();
  1996. break;
  1997. case "preview":
  1998. this.loadPreview();
  1999. break;
  2000. case "sequence":
  2001. this.loadSequence();
  2002. break;
  2003. }
  2004. this.createInforNode();
  2005. if (!Browser.Platform.ios){
  2006. this.tooltip = new mBox.Tooltip({
  2007. content: this.inforNode,
  2008. setStyles: {content: {padding: 15, lineHeight: 20}},
  2009. attach: this.node,
  2010. transition: 'flyin'
  2011. });
  2012. }
  2013. this.setEvent();
  2014. },
  2015. unSelected: function(){
  2016. this.isSelected = false;
  2017. //this.node.setStyles(this.css["minAttachmentNode_list"]);
  2018. if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
  2019. var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
  2020. this.node.setStyles(this.css[cssKey]);
  2021. }else{
  2022. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
  2023. }
  2024. if( this.controller.module && this.controller.module.fireEvent ){
  2025. this.controller.module.fireEvent("unselect", [this]);
  2026. }
  2027. this.controller.selectedAttachments.erase(this);
  2028. }
  2029. });
  2030. o2.widget.AttachmentController.AttachmentMessage = new Class({
  2031. Extends: o2.widget.AttachmentController.Attachment,
  2032. Implements: [Events],
  2033. initialize: function(file, controller){
  2034. var d = (new Date).format("db");
  2035. var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length);
  2036. this.file = file;
  2037. this.type = "message";
  2038. this.data = {
  2039. activity: "",
  2040. activityName: "",
  2041. activityToken: "",
  2042. activityType: "manual",
  2043. application: "",
  2044. completed: false,
  2045. control: {allowRead:true, allowEdit:false, allowControl:false},
  2046. controllerIdentityList: [],
  2047. controllerUnitList: [],
  2048. createTime: d,
  2049. deepPath: false,
  2050. divisionList: [],
  2051. editIdentityList: [],
  2052. editUnitList: [],
  2053. extension: extension,
  2054. id: (new o2.widget.UUID()).toString(),
  2055. job: "",
  2056. lastUpdatePerson: (layout) ? layout.session.user.name : "",
  2057. lastUpdateTime: d,
  2058. length: file.size,
  2059. name: file.name,
  2060. person: (layout) ? layout.session.user.name : "",
  2061. process: "",
  2062. readIdentityList: [],
  2063. readUnitList: [],
  2064. site: "$doc",
  2065. storage: file.size,
  2066. type: "",
  2067. updateTime: d,
  2068. workCreateTime: ""
  2069. }
  2070. if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
  2071. this.controller = controller;
  2072. this.css = this.controller.css;
  2073. this.listStyle = this.controller.options.listStyle;
  2074. this.content = this.controller.content;
  2075. this.isSelected = false;
  2076. this.seq = this.controller.attachments.length+1;
  2077. this.actions = [];
  2078. this.load();
  2079. },
  2080. load: function(){
  2081. this.node = new Element("div").inject(this.content);
  2082. switch (this.controller.options.listStyle){
  2083. case "list":
  2084. this.loadList();
  2085. break;
  2086. case "icon":
  2087. this.loadIcon();
  2088. break;
  2089. case "preview":
  2090. this.loadPreview();
  2091. break;
  2092. case "sequence":
  2093. this.loadSequence();
  2094. break;
  2095. }
  2096. this.setEvent();
  2097. this.loadMessage();
  2098. },
  2099. loadMessage: function(){
  2100. var size = this.node.getSize();
  2101. this.node.setStyle("position", "relative");
  2102. this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node);
  2103. this.messageMaskNode.setStyles({
  2104. "width": ""+size.x+"px",
  2105. "height": ""+size.y+"px"
  2106. });
  2107. this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node);
  2108. switch (this.controller.options.listStyle){
  2109. case "list":
  2110. case "sequence":
  2111. this.messageNode.setStyles({
  2112. "width": "0px",
  2113. "height": ""+size.y+"px"
  2114. });
  2115. break;
  2116. case "icon":
  2117. case "preview":
  2118. this.messageNode.setStyles({
  2119. "width": ""+size.x+"px",
  2120. "height": ""+size.y+"px"
  2121. });
  2122. break;
  2123. }
  2124. this.messageText = new Element("div", {
  2125. "styles": this.css.messageText,
  2126. "text": "0%"
  2127. }).inject(this.node);
  2128. this.messageText.setStyles({
  2129. "width": ""+size.x+"px",
  2130. "height": ""+size.y+"px",
  2131. "line-height": ""+size.y+"px"
  2132. });
  2133. },
  2134. updateProgress: function(percent){
  2135. var size = this.node.getSize();
  2136. switch (this.controller.options.listStyle){
  2137. case "list":
  2138. case "sequence":
  2139. var w = size.x*(percent/100);
  2140. this.messageNode.setStyles({
  2141. "width":""+w+"px"
  2142. });
  2143. break;
  2144. case "icon":
  2145. case "preview":
  2146. var h = size.y*(1-percent/100);
  2147. this.messageNode.setStyle("height", ""+h+"px");
  2148. break;
  2149. }
  2150. var p = (percent*100).toInt()/100;
  2151. this.messageText.set("text", ""+p+"%")
  2152. },
  2153. transferComplete: function(){
  2154. this.messageText.set("text", "loading...")
  2155. }
  2156. });
  2157. o2.widget.AttachmentController.AttachmentMessageMin = new Class({
  2158. Extends: o2.widget.AttachmentController.AttachmentMin,
  2159. Implements: [Events],
  2160. initialize: function(file, controller){
  2161. var d = (new Date).format("db");
  2162. var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length);
  2163. this.file = file;
  2164. this.data = {
  2165. activity: "",
  2166. activityName: "",
  2167. activityToken: "",
  2168. activityType: "manual",
  2169. application: "",
  2170. completed: false,
  2171. control: {allowRead:true, allowEdit:false, allowControl:false},
  2172. controllerIdentityList: [],
  2173. controllerUnitList: [],
  2174. createTime: d,
  2175. deepPath: false,
  2176. divisionList: [],
  2177. editIdentityList: [],
  2178. editUnitList: [],
  2179. extension: extension,
  2180. id: (new o2.widget.UUID()).toString(),
  2181. job: "",
  2182. lastUpdatePerson: (layout) ? layout.session.user.name : "",
  2183. lastUpdateTime: d,
  2184. length: file.size,
  2185. name: file.name,
  2186. person: (layout) ? layout.session.user.name : "",
  2187. process: "",
  2188. readIdentityList: [],
  2189. readUnitList: [],
  2190. site: "$doc",
  2191. storage: file.size,
  2192. type: "",
  2193. updateTime: d,
  2194. workCreateTime: ""
  2195. }
  2196. if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
  2197. this.controller = controller;
  2198. this.css = this.controller.css;
  2199. this.listStyle = this.controller.options.listStyle;
  2200. this.content = this.controller.minContent;
  2201. this.isSelected = false;
  2202. this.seq = this.controller.attachments.length+1;
  2203. this.actions = [];
  2204. this.load();
  2205. },
  2206. load: function(){
  2207. this.node = new Element("div").inject(this.content);
  2208. switch (this.controller.options.listStyle){
  2209. case "list":
  2210. this.loadList();
  2211. break;
  2212. case "icon":
  2213. this.loadIcon();
  2214. break;
  2215. case "preview":
  2216. this.loadPreview();
  2217. break;
  2218. case "sequence":
  2219. this.loadSequence();
  2220. break;
  2221. }
  2222. this.setEvent();
  2223. this.loadMessage();
  2224. },
  2225. loadMessage: function(){
  2226. var size = this.node.getSize();
  2227. this.node.setStyle("position", "relative");
  2228. this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node);
  2229. this.messageMaskNode.setStyles({
  2230. "width": ""+size.x+"px",
  2231. "height": ""+size.y+"px"
  2232. });
  2233. this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node);
  2234. switch (this.controller.options.listStyle){
  2235. case "list":
  2236. case "sequence":
  2237. this.messageNode.setStyles({
  2238. "width": "0px",
  2239. "height": ""+size.y+"px"
  2240. });
  2241. break;
  2242. case "icon":
  2243. case "preview":
  2244. this.messageNode.setStyles({
  2245. "width": ""+size.x+"px",
  2246. "height": ""+size.y+"px"
  2247. });
  2248. break;
  2249. }
  2250. this.messageText = new Element("div", {
  2251. "styles": this.css.messageText,
  2252. "text": "0%"
  2253. }).inject(this.node);
  2254. this.messageText.setStyles({
  2255. "width": ""+size.x+"px",
  2256. "height": ""+size.y+"px",
  2257. "line-height": ""+size.y+"px"
  2258. });
  2259. },
  2260. updateProgress: function(percent){
  2261. var size = this.node.getSize();
  2262. switch (this.controller.options.listStyle){
  2263. case "list":
  2264. case "sequence":
  2265. var w = size.x*(percent/100);
  2266. this.messageNode.setStyles({
  2267. "width":""+w+"px"
  2268. });
  2269. break;
  2270. case "icon":
  2271. case "preview":
  2272. var h = size.y*(1-percent/100);
  2273. this.messageNode.setStyle("height", ""+h+"px");
  2274. break;
  2275. }
  2276. var p = (percent*100).toInt()/100;
  2277. this.messageText.set("text", ""+p+"%")
  2278. },
  2279. transferComplete: function(){
  2280. this.messageText.set("text", "loading...")
  2281. }
  2282. });