1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521 |
- o2.widget = o2.widget || {};
- if( !o2.widget.UUID )o2.require("o2.widget.UUID", null, false);
- o2.widget.AttachmentController = o2.widget.ATTER = new Class({
- Extends: o2.widget.Common,
- Implements: [Options, Events],
- options: {
- "style": "default",
- "listStyle": "icon",
- "size": "max",
- "resize": true,
- "attachmentCount": 0,
- "isUpload": true,
- "isDelete": true,
- "isReplace": true,
- "isDownload": true,
- "isPreviewAtt": true,
- "isSizeChange": true,
- "isConfig": true,
- "isOrder": true,
- "readonly": false,
- "availableListStyles" : ["list","seq","icon","preview"],
- "toolbarGroupHidden" : [], //edit read list view
- "images": ["bmp", "gif", "png", "jpeg", "jpg", "jpe", "ico"],
- "audios": ["mp3", "wav", "wma", "wmv"],
- "videos": ["avi", "mkv", "mov", "ogg", "mp4", "mpa", "mpe", "mpeg", "mpg", "rmvb"],
- "actionShowText" : false
- },
- initialize: function(container, module, options){
- this.setOptions(options);
- this.pages = [];
- this.path = o2.session.path+"/widget/$AttachmentController/";
- this.cssPath = o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/css.wcss";
- this._loadCss();
- var iconUrl = this.options.iconConfigUrl ? this.options.iconConfigUrl : "../x_component_File/$Main/icon.json";
- o2.getJSON(iconUrl, function(json){
- this.icons = json;
- }.bind(this), false);
- this.module = module;
- this.actions = [];
- this.attachments = [];
- this.selectedAttachments = [];
- this.container = $(container);
- },
- load: function(){
- // if (!layout.mobile){
- if (this.options.size==="min"){
- this.loadMin();
- }else{
- this.loadMax();
- }
- // }else{
- // this.loadMobile();
- // }
- },
- reloadAttachments: function(){
- if (this.options.size==="min"){
- this.minContent.empty();
- var atts = this.attachments;
- this.attachments = [];
- while (atts.length){
- var att = atts.shift();
- this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this));
- }
- }else{
- this.content.empty();
- var atts = this.attachments;
- this.attachments = [];
- while (atts.length){
- var att = atts.shift();
- this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this));
- }
- }
- this.checkActions();
- },
- getAttachmentById: function(attId){
- for( var i=0; i<this.attachments.length; i++ ){
- if( this.attachments[i].data.id === attId ){
- return this.attachments[i];
- }
- }
- return null;
- },
- loadMax: function(){
- if (!this.node) this.node = new Element("div", {"styles": this.css.container});
- this.createTopNode();
- if (!this.contentScrollNode){
- //this.createTopNode();
- this.createContentNode();
- if (this.options.resize){
- this.createBottomNode();
- this.createResizeNode();
- }
- this.node.inject(this.container);
- //if (this.options.readonly) this.setReadonly();
- this.checkActions();
- this.setEvent();
- }else{
- this.contentScrollNode.setStyle("display", "block");
- if (this.bottomNode) this.bottomNode.setStyle("display", "block");
- if (this.titleNode) this.titleNode.setStyle("display", "block");
- //this.topNode.setStyle("display", "block");
- this.content.empty();
- }
- var atts = this.attachments;
- this.attachments = [];
- while (atts.length){
- var att = atts.shift();
- this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this));
- }
- this.checkActions();
- //this.attachments = atts;
- if( layout.mobile ){
- this.checkActionsZoom();
- }
- },
- loadMin: function(){
- if (!this.node) this.node = new Element("div", {"styles": this.css.container_min});
- if (!this.minActionAreaNode){
- this.minActionAreaNode = new Element("div", {"styles": this.css.minActionAreaNode }).inject(this.node);
- //this.minContent = new Element("div", {"styles": this.css.minContentNode}).inject(this.node);
- this.loadMinActions();
- this.node.inject(this.container);
- //if (this.options.readonly) this.setReadonly();
- //this.checkActions();
- this.setEvent();
- }else{
- this.minActionAreaNode.setStyle("display", "");
- //this.minContent.setStyle("display", "block");
- //this.minContent.empty();
- this.minActionAreaNode.empty();
- this.loadMinActions();
- this.setEvent();
- }
- var hiddenGroup = this.options.toolbarGroupHidden;
- var flag = hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("view");
- if( flag )this.minActionAreaNode.setStyle("display","none");
- if( !this.minContent ){
- this.minContent = new Element("div", {"styles":
- layout.mobile ? this.css.minContentNode_mobile : this.css.minContentNode
- }).inject(this.node);
- if( layout.mobile ){
- this.minContent.setStyle("clear","both");
- }
- }else{
- this.minContent.setStyle("display", "block");
- this.minContent.empty();
- }
- var atts = this.attachments;
- this.attachments = [];
- while (atts.length){
- var att = atts.shift();
- this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this));
- }
- this.checkActions();
- //this.attachments = atts;
- },
- loadMobile: function(){
- },
- loadMinActions: function(){
- var hiddenGroup = this.options.toolbarGroupHidden;
- if (!hiddenGroup.contains("edit")) {
- this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", o2.LP.widget.upload, function (e, node) {
- this.uploadAttachment(e, node);
- }.bind(this));
- this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", o2.LP.widget["delete"], function (e, node) {
- this.deleteAttachment(e, node);
- }.bind(this));
- if( !this.options.isReplaceHidden ){
- this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", o2.LP.widget.replace, function (e, node) {
- this.replaceAttachment(e, node);
- }.bind(this));
- }
- }
- if (!hiddenGroup.contains("read")) {
- this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", o2.LP.widget.download, function (e, node) {
- this.downloadAttachment(e, node);
- }.bind(this));
- }
- var hasChangeSize = this.options.isSizeChange && !hiddenGroup.contains("view");
- if( (!hiddenGroup.contains("edit") || !hiddenGroup.contains("read")) && hasChangeSize ) {
- this.createSeparate(this.minActionAreaNode);
- }
- if (hasChangeSize){
- this.sizeAction = this.createAction(this.minActionAreaNode, "max", o2.LP.widget.min, function () {
- this.changeControllerSize();
- }.bind(this));
- }
- },
- setEvent: function(){
- if (this.contentScrollNode && !this.isContentSetEvent){
- this.contentScrollNode.addEventListener("dragover", function( e ) {
- e.preventDefault();
- e.stopPropagation();
- }, false);
- this.contentScrollNode.addEventListener("drop", function( e ) {
- this.uploadAttachment(e, null, e.dataTransfer.files);
- event.preventDefault();
- }.bind(this), false);
- this.contentScrollNode.addEvents({
- "mousedown": this.unSelectedAttachments.bind(this)
- });
- this.isContentSetEvent = true;
- }
- if (this.minContent && !this.isMinContentSetEvent){
- this.minContent.addEventListener("dragover", function( e ) {
- e.preventDefault();
- e.stopPropagation();
- }, false);
- this.minContent.addEventListener("drop", function( e ) {
- this.uploadAttachment(e, null, e.dataTransfer.files);
- event.preventDefault();
- }.bind(this), false);
- this.minContent.addEvents({
- "mousedown": this.unSelectedAttachments.bind(this)
- });
- this.isMinContentSetEvent = true;
- }
- },
- resetToolbarGroupHidden : function( hiddenGroup ){
- this.options.toolbarGroupHidden = hiddenGroup;
- if( this.options.size == "max" ){
- this.reloadTopNode();
- }else{
- this.loadMin();
- }
- },
- resetToolbarAvailableListStyle : function( availableListStyle ){
- this.options.availableListStyles = availableListStyle;
- if( this.options.size == "max" ){
- this.reloadTopNode();
- }else{
- this.loadMin();
- }
- },
- createContentNode: function(){
- this.contentScrollNode = new Element("div.contentScrollNode", {"styles": this.css.contentScrollNode}).inject(this.node);
- this.content = new Element("div.content", {"styles": this.css.contentNode}).inject(this.contentScrollNode);
- o2.require("o2.widget.ScrollBar", function(){
- new o2.widget.ScrollBar(this.contentScrollNode, {
- "style":"attachment", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true}
- });
- }.bind(this));
- },
- createBottomNode: function(){
- this.bottomNode = new Element("div", {"styles": this.css.bottomNode}).inject(this.node);
- },
- createResizeNode: function(){
- this.resizeNode = new Element("div", {"styles": this.css.resizeNode}).inject(this.bottomNode);
- this.resizeDrag = new Drag(this.resizeNode, {
- "snap": "2",
- "onStart": function(el, e){
- el.store("startY", e.event.y);
- el.store("nodeHeight", this.node.getSize().y);
- var minHeight = this.node.getStyle("min-height");
- el.store("nodeMinHeight", minHeight ? minHeight.toFloat() : "");
- var contentScrollNodeMinHeight = this.contentScrollNode.getStyle("min-height");
- el.store("contentScrollNodeMinHeight", contentScrollNodeMinHeight ? contentScrollNodeMinHeight.toFloat() : "");
- if (!this.nodeHeight){
- this.nodeHeight = minHeight.toFloat();
- }
- }.bind(this),
- "onDrag": function(el, e){
- var y = el.retrieve("startY");
- var nodeHeight = el.retrieve("nodeHeight");
- var nodeMinHeight = el.retrieve("nodeMinHeight");
- var contentScrollNodeMinHeight = el.retrieve("contentScrollNodeMinHeight");
- var setY = (e.event.y-y)+nodeHeight;
- if( nodeMinHeight && setY < nodeMinHeight && e.event.y<y)return;
- if (setY<this.nodeHeight) setY = this.nodeHeight;
- var setContentY = setY-81;
- if( contentScrollNodeMinHeight && setContentY < contentScrollNodeMinHeight && e.event.y<y )return;
- this.node.setStyle("height", ""+setY+"px");
- this.contentScrollNode.setStyle("height", ""+setContentY+"px");
- }.bind(this)
- });
- },
- createTopNode: function(){
- if (this.options.title){
- if (!this.titleNode) this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
- }
- if( !this.topNode ){
- this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
- }else{
- this.topNode.empty();
- this.editActionBoxNode = null;
- this.editActionsGroupNode=null;
- this.topNode.setStyle("display","");
- if( this.isHiddenTop ){
- if( this.oldContentScrollNodeHeight && this.contentScrollNode ){
- this.contentScrollNode.setStyle("min-height",this.oldContentScrollNodeHeight);
- this.oldContentScrollNodeHeight = null;
- }
- this.isHiddenTop = false;
- }
- }
- var hiddenGroup = this.options.toolbarGroupHidden;
- if( hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") && hiddenGroup.contains("view")){
- if(this.contentScrollNode){
- this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
- this.contentScrollNode.setStyle("min-height",this.node.getStyle("min-height"));
- this.topNode.setStyle("display","none");
- }
- this.isHiddenTop = true;
- return;
- }
- if( !hiddenGroup.contains("edit") )this.createEditGroupActions();
- if( !hiddenGroup.contains("read") )this.createReadGroupActions();
- if( !hiddenGroup.contains("list") )this.createListGroupActions();
- if( !hiddenGroup.contains("view") )this.createViewGroupActions();
- if( layout.mobile ){
- this.checkActionsZoom();
- }
- //this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
- //this.createEditGroupActions();
- //this.createReadGroupActions();
- //this.createListGroupActions();
- //this.createViewGroupActions();
- //this.createConfigGroupActions();
- },
- checkActionsZoom: function(){
- var width = 0;
- this.topNode.getChildren().each(function( node ){
- if(node.offsetParent)width = width + node.getSize().x + this.getOffsetX(node)
- }.bind(this));
- var topSize = this.topNode.getSize();
- if( (topSize.x - 5) < width ){
- var zoom = this.getDecimals((topSize.x - 5) / width);
- this.topNode.setStyle( "zoom", zoom*100+"%" );
- }
- },
- getDecimals: function(v){ //截取两位小数
- var decimals = 4;
- var p = Math.pow(10,decimals);
- var f_x = Math.round(v*p)/p;
- var str = f_x.toString();
- if (decimals>0){
- var pos_decimal = str.indexOf('.');
- if (pos_decimal < 0){
- pos_decimal = str.length;
- str += '.';
- }
- var decimalStr = (str).substr(pos_decimal+1, (str).length);
- while (decimalStr.length < decimals){
- str += '0';
- decimalStr += 0;
- }
- }
- return str;
- },
- getOffsetX : function(node){
- return (node.getStyle("margin-left").toInt() || 0 ) +
- (node.getStyle("margin-right").toInt() || 0 ) +
- (node.getStyle("padding-left").toInt() || 0 ) +
- (node.getStyle("padding-right").toInt() || 0 )+
- (node.getStyle("border-left-width").toInt() || 0 ) +
- (node.getStyle("border-right-width").toInt() || 0 );
- },
- reloadTopNode : function(){
- this.createTopNode();
- },
- createEditGroupActions: function(){
- if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
- if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
- this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", o2.LP.widget.upload, function(e, node){
- this.uploadAttachment(e, node);
- }.bind(this));
- this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", o2.LP.widget["delete"], function(e, node){
- this.deleteAttachment(e, node);
- }.bind(this));
- if( !this.options.isReplaceHidden ){
- this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function(e, node){
- this.replaceAttachment(e, node);
- }.bind(this));
- }
- // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){
- // this.openInOfficeControl(e, node);
- // }.bind(this));
- if( !this.options.toolbarGroupHidden.contains("read") )this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
- },
- createReadGroupActions: function(){
- //this.readActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
- //this.readActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.readActionBoxNode);
- if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
- if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
- this.downloadAction = this.createAction(this.editActionsGroupNode, "download", o2.LP.widget.download, function(){
- this.downloadAttachment();
- }.bind(this));
- //this.createAction(this.readActionsGroupNode, "share", o2.LP.widget.share, function(){
- // this.transAttachment();
- //}.bind(this));
- //this.downloadAllAction = this.createAction(this.editActionsGroupNode, "downloadAll", o2.LP.widget.downloadAll, function(){
- // this.downloadAllAttachment();
- //}.bind(this));
- },
- createListGroupActions: function(){
- var availableListStyles = this.options.availableListStyles;
- if( availableListStyles && availableListStyles.length > 0 ){
- this.listActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
- this.listActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.listActionBoxNode);
- if( availableListStyles.contains("list") ){
- this.listAction = this.createAction(this.listActionsGroupNode, "list", o2.LP.widget.list, function(){
- this.changeListStyle("list");
- }.bind(this));
- }
- if( availableListStyles.contains("seq") ) {
- this.sequenceAction = this.createAction(this.listActionsGroupNode, "seq", o2.LP.widget.sequence, function () {
- this.changeListStyle("sequence");
- }.bind(this));
- }
- if( availableListStyles.contains("icon") ) {
- this.iconAction = this.createAction(this.listActionsGroupNode, "icon", o2.LP.widget.icon, function () {
- this.changeListStyle("icon");
- }.bind(this));
- }
- if( availableListStyles.contains("preview") ) {
- this.previewAction = this.createAction(this.listActionsGroupNode, "preview", o2.LP.widget.preview, function () {
- this.changeListStyle("preview");
- }.bind(this));
- }
- }
- },
- createViewGroupActions: function(){
- if (this.options.isSizeChange){
- this.viewActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
- this.viewActionBoxNode.setStyles({"float": "right", "margin-right": "7px"});
- this.viewActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.viewActionBoxNode);
- this.sizeAction = this.createAction(this.viewActionsGroupNode, "min", o2.LP.widget.min, function(){
- this.changeControllerSize();
- }.bind(this));
- }
- },
- createSeparate: function(groupNode){
- var separateNode = new Element("div.separateNode", {"styles": this.css.separateNode}).inject(groupNode);
- return separateNode;
- },
- createAction: function(groupNode, img, title, click){
- var actionNode = new Element("div", {"styles": this.css.actionNode, "title": title}).inject(groupNode);
- var actionIconNode = new Element("div", {"styles": this.css.actionIconNode}).inject(actionNode);
- actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/icon/"+img+".png)");
- var _self = this;
- actionNode.addEvents({
- "mouseover": function(){
- if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.options.style+"/overbg.png)");
- },
- "mouseout": function(){
- if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "transparent");
- },
- "click": function(e){
- if (!this.retrieve("disabled")) _self.doAction(e, this, click);
- e.stopPropagation();
- }
- });
- this.actions.push(actionNode);
- return actionNode;
- },
- checkActions: function(){
- // if (this.options.readonly){
- // this.setReadonly();
- // }else{
- this.checkUploadAction();
- this.checkDeleteAction();
- this.checkReplaceAction();
- //this.checkOfficeAction();
- this.checkDownloadAction();
- this.checkSizeAction();
- this.checkListStyleAction();
- if( this.options.size === "max" ){
- this.checkEditActionBox();
- }
- },
- checkEditActionBox: function(){
- var isShowEdit = false;
- ["isUpload", "isDelete", "isReplace"].each(function( key ){
- if( key === "isReplace" && this.options.isReplaceHidden )return;
- if( this.options[key] !== "hidden" )isShowEdit = true;
- }.bind(this));
- var isShowRead = false;
- ["isDownload"].each(function( key ){
- if( this.options[key] !== "hidden" )isShowRead = true;
- }.bind(this));
- if(this.editActionSeparateNode)this.editActionSeparateNode.setStyle( "display", isShowEdit && isShowRead ? "" : "none" );
- if(this.editActionBoxNode )this.editActionBoxNode.setStyle( "display", isShowEdit || isShowRead ? "" : "none" );
- },
- checkUploadAction: function(){
- if (this.options.readonly) {
- if (this.options.isUpload === "hidden") {
- this.setActionHidden(this.uploadAction);
- this.setActionHidden(this.min_uploadAction);
- } else {
- this.setActionDisabled(this.uploadAction);
- this.setActionDisabled(this.min_uploadAction);
- }
- return false;
- }
- if (this.options.isUpload === "hidden" ){
- this.setActionHidden(this.uploadAction);
- this.setActionHidden(this.min_uploadAction);
- }else if (!this.options.isUpload){
- this.setActionDisabled(this.uploadAction);
- this.setActionDisabled(this.min_uploadAction);
- }else{
- if (this.options.attachmentCount.toInt() > 0){
- if (this.attachments.length>=this.options.attachmentCount.toInt()){
- this.setActionDisabled(this.uploadAction);
- this.setActionDisabled(this.min_uploadAction);
- }else{
- this.setActionEnabled(this.uploadAction);
- this.setActionEnabled(this.min_uploadAction);
- }
- }else{
- this.setActionEnabled(this.uploadAction);
- this.setActionEnabled(this.min_uploadAction);
- }
- }
- },
- checkDeleteAction: function(){
- if (this.options.readonly){
- if (this.options.isDelete === "hidden") {
- this.setActionHidden(this.deleteAction);
- this.setActionHidden(this.min_deleteAction);
- } else {
- this.setActionDisabled(this.deleteAction);
- this.setActionDisabled(this.min_deleteAction);
- }
- this.setAttachmentsAction("delete", false );
- return false;
- }
- if (this.options.isDelete === "hidden") {
- this.setActionHidden(this.deleteAction);
- this.setActionHidden(this.min_deleteAction);
- this.setAttachmentsAction("delete", false );
- } else if (!this.options.isDelete){
- this.setActionDisabled(this.deleteAction);
- this.setActionDisabled(this.min_deleteAction);
- this.setAttachmentsAction("delete", false );
- }else{
- if (this.selectedAttachments.length){
- this.setActionEnabled(this.deleteAction);
- this.setActionEnabled(this.min_deleteAction);
- }else{
- this.setActionDisabled(this.deleteAction);
- this.setActionDisabled(this.min_deleteAction);
- }
- this.setAttachmentsAction("delete", true );
- }
- },
- isAttDeleteAvailable : function( att ){
- if (this.options.readonly)return false;
- if( this.options.toolbarGroupHidden.contains("edit") )return false;
- return this.options.isDelete && this.options.isDelete !== "hidden";
- },
- isAttEditAvailable : function( att ){
- if (this.options.readonly)return false;
- if( this.options.toolbarGroupHidden.contains("edit") )return false;
- return this.options.isEditAtt && this.options.isEditAtt !== "hidden";
- },
- // checkOfficeAction: function(){
- // if (this.officeAction) this.officeAction.setStyle("display", "none");
- // if (this.min_officeAction) this.min_officeAction.setStyle("display", "none");
- // },
- checkReplaceAction: function(){
- if( this.options.isReplaceHidden )return;
- if (this.options.readonly){
- if( this.options.isReplace === "hidden" ){
- this.setActionHidden(this.replaceAction);
- this.setActionHidden(this.min_replaceAction);
- }else{
- this.setActionDisabled(this.replaceAction);
- this.setActionDisabled(this.min_replaceAction);
- }
- this.setAttachmentsAction("replace", false );
- return false;
- }
- if( this.options.isReplace === "hidden" ){
- this.setActionHidden(this.replaceAction);
- this.setActionHidden(this.min_replaceAction);
- this.setAttachmentsAction("replace", false );
- }else if (!this.options.isReplace){
- this.setActionDisabled(this.replaceAction);
- this.setActionDisabled(this.min_replaceAction);
- this.setAttachmentsAction("replace", false );
- }else{
- if (this.selectedAttachments.length && this.selectedAttachments.length==1){
- this.setActionEnabled(this.replaceAction);
- this.setActionEnabled(this.min_replaceAction);
- }else{
- this.setActionDisabled(this.replaceAction);
- this.setActionDisabled(this.min_replaceAction);
- }
- this.setAttachmentsAction("replace", true );
- }
- },
- isAttReplaceAvailable : function( att ){
- if (this.options.readonly)return false;
- if( this.options.toolbarGroupHidden.contains("edit") )return false;
- return this.options.isReplace && this.options.isReplace !== "hidden";
- },
- checkDownloadAction: function(){
- if( this.options.isDownload === "hidden" ){
- this.setActionHidden(this.downloadAction);
- this.setActionHidden(this.min_downloadAction);
- this.setActionHidden(this.downloadAllAction);
- this.setAttachmentsAction("download", false );
- }else if (!this.options.isDownload){
- this.setActionDisabled(this.downloadAction);
- this.setActionDisabled(this.min_downloadAction);
- this.setActionDisabled(this.downloadAllAction);
- this.setAttachmentsAction("download", false );
- }else{
- if (this.selectedAttachments.length){
- this.setActionEnabled(this.downloadAction);
- this.setActionEnabled(this.min_downloadAction);
- }else{
- this.setActionDisabled(this.downloadAction);
- this.setActionDisabled(this.min_downloadAction);
- }
- this.setActionEnabled(this.downloadAllAction);
- this.setAttachmentsAction("download", true );
- }
- },
- isAttDblclickAvailable : function( att ){
- return this.options.dblclick && this.options.dblclick !== "hidden";
- },
- isAttDownloadAvailable : function( att ){
- if( this.options.toolbarGroupHidden.contains("read") )return false;
- return this.options.isDownload && this.options.isDownload !== "hidden";
- },
- checkSizeAction: function(){
- if( this.sizeAction ){
- if (this.options.isSizeChange){
- this.setActionEnabled(this.sizeAction);
- }else{
- this.setActionDisabled(this.sizeAction);
- }
- }
- },
- checkListStyleAction: function(){
- switch (this.options.listStyle){
- case "list":
- this.setActionSelcted(this.listAction);
- this.setActionUnSelcted(this.iconAction);
- this.setActionUnSelcted(this.previewAction);
- this.setActionUnSelcted(this.sequenceAction);
- break;
- case "icon":
- this.setActionUnSelcted(this.listAction);
- this.setActionSelcted(this.iconAction);
- this.setActionUnSelcted(this.previewAction);
- this.setActionUnSelcted(this.sequenceAction);
- break;
- case "preview":
- this.setActionUnSelcted(this.listAction);
- this.setActionUnSelcted(this.iconAction);
- this.setActionSelcted(this.previewAction);
- this.setActionUnSelcted(this.sequenceAction);
- break;
- case "sequence":
- this.setActionUnSelcted(this.listAction);
- this.setActionUnSelcted(this.iconAction);
- this.setActionUnSelcted(this.previewAction);
- this.setActionSelcted(this.sequenceAction);
- break;
- }
- },
- setActionSelcted: function(action){
- if (action){
- if (!action.retrieve("selected")){
- action.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/selectedbg.png)");
- action.store("selected", true);
- }
- }
- },
- setActionUnSelcted: function(action){
- if (action){
- if (action.retrieve("selected")){
- action.setStyle("background", "");
- action.store("selected", false);
- }
- }
- },
- setActionEnabled: function(action){
- if (action){
- action.show();
- if (action.retrieve("disabled")){
- var iconNode = action.getFirst();
- var icon = iconNode.getStyle("background-image");
- var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
- icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext;
- iconNode.setStyle("background-image", icon);
- action.store("disabled", false);
- }
- }
- },
- setActionDisabled: function(action){
- if (action){
- if (!action.retrieve("disabled")){
- var iconNode = action.getFirst();
- var icon = iconNode.getStyle("background-image");
- var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
- icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext;
- iconNode.setStyle("background-image", icon);
- action.store("disabled", true);
- }
- }
- },
- setActionHidden: function(action){
- if (action)action.hide();
- },
- setReadonly: function() {
- this.actions.each(function(action){
- this.setActionDisabled(action);
- this.setAttachmentsAction("all", false );
- }.bind(this));
- },
- setAttachmentsAction : function(type, enable){
- this.attachments.each( function( att ){
- this.setAttachmentAction( att, type, enable )
- }.bind(this))
- },
- setAttachmentAction : function(att, type, enable){
- var action;
- if( type === "all" ){
- ( att.actions || [] ).each( function(action){
- att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
- })
- }else{
- switch( type ){
- case "download" :
- action = att.downloadAction;
- break;
- case "config" :
- action = att.configAction;
- break;
- case "delete" :
- action = att.deleteAction;
- break;
- case "replace" :
- action = att.replaceAction;
- break;
- }
- if( !action )return;
- if( type === "config" ){
- var flag = enable;
- if( flag ){
- var user = layout.session.user.distinguishedName;
- if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid;
- if ((!att.data.control.allowControl ) && att.data.person!==user){ //|| !att.data.control.allowEdit
- flag = false;
- }
- }
- att[ flag ? "setActionEnabled" : "setActionDisabled" ](action);
- }else{
- att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
- }
- }
- },
- doAction: function(e, node, action){
- if (action){
- action.apply(this, [e, node]);
- }
- },
- uploadAttachment: function(e, node, files){
- debugger;
- if (this.module) this.module.uploadAttachment(e, node, files);
- },
- doUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){
- if (this.options.isUpload && this.options.isUpload !== "hidden" ){
- if (FormData.expiredIE){
- this.doInputUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery);
- }else{
- this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files);
- }
- }else{
- var text = o2.LP.widget.notUploadNotice;
- if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
- }
- },
- addUploadMessage: function(fileName){
- var contentHTML = "";
- contentHTML = "<div style=\"overflow: hidden\"><div style=\"height: 2px; border:0px solid #999; margin: 3px 0px\">" +
- "<div style=\"height: 2px; background-color: #acdab9; width: 0px;\"></div></div>" +
- "<div style=\"height: 20px; line-height: 20px\">"+o2.LP.desktop.action.uploadTitle+"</div></div>" +
- "<iframe name='o2_upload_iframe' style='display:none'></iframe>" ;
- var msg = {
- "subject": o2.LP.desktop.action.uploadTitle,
- "content": fileName+"<br/>"+contentHTML
- };
- if (layout.desktop.message){
- var messageItem = layout.desktop.message.addMessage(msg);
- messageItem.close = function(callback, e){
- if (!messageItem.completed){
- }else{
- messageItem.closeItem(callback, e);
- }
- };
- }
- window.setTimeout(function(){
- if (layout.desktop.message) if (!layout.desktop.message.isShow) layout.desktop.message.show();
- }.bind(this), 300);
- return messageItem;
- },
- setMessageTitle: function(messageItem, text){
- if (messageItem) messageItem.subjectNode.set("text", text);
- },
- setMessageText: function(messageItem, text){
- if (messageItem){
- var progressNode = messageItem.contentNode.getFirst("div").getFirst("div");
- var progressPercentNode = progressNode.getFirst("div");
- var progressInforNode = messageItem.contentNode.getFirst("div").getLast("div");
- progressInforNode.set("text", text);
- messageItem.dateNode.set("text", (new Date()).format("db"));
- }
- },
- doInputUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, failureEvery){
- var restActions = action;
- if (typeOf(action)=="string"){
- restActions = o2.Actions.get(action).action;
- }
- restActions.getActions(function(){
- var url = restActions.actions[invokeUrl];
- url = restActions.address+url.uri;
- Object.each(parameter, function(v, k){
- url = url.replace("{"+k+"}", v);
- });
- var maskNode = this.module.content;
- if (!maskNode){
- if (this.module.form){
- maskNode = this.module.form.app.content;
- }
- }
- if (!maskNode) maskNode = this.node;
- //var maskNode = this.module.content || this.module.node;
- if (maskNode){
- maskNode.mask({
- "style": {
- "opacity": 0.7,
- "background-color": "#999"
- }
- });
- }
- this.inputUploadAreaNode = new Element("div", {"styles": this.css.inputUploadAreaNode}).inject(this.container);
- this.inputUploadAreaNode.position({
- relativeTo: this.module.content,
- position: "center"
- });
- var messageItem = null;
- document.O2UploadCallbackFun = function(str){
- var json = JSON.decode(str);
- messageItem.completed = true;
- if (json.type==="success"){
- if (every) every(json.data);
- this.setMessageTitle(messageItem, o2.LP.desktop.action.uploadComplete);
- this.setMessageText(messageItem, o2.LP.desktop.action.uploadComplete);
- if(finish) finish();
- }else{
- //formNode.unmask();
- // if(failureEvery)failureEvery(json);
- this.setMessageTitle(messageItem, o2.LP.desktop.action.sendError);
- this.setMessageText(messageItem, o2.LP.desktop.action.sendError+": "+json.message);
- o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
- }
- }.bind(this);
- var formNode = new Element("form", {
- "method": "POST",
- "action": url+"/callback/window.frameElement.ownerDocument.O2UploadCallbackFun",
- //"action": url,
- "enctype": "multipart/form-data",
- "target": "o2_upload_iframe"
- }).inject(this.inputUploadAreaNode);
- var titleNode = new Element("div", {"styles": this.css.inputUploadAreaTitleNode, "text": o2.LP.widget.uploadTitle}).inject(formNode);
- var inforNode = new Element("div", {"styles": this.css.inputUploadAreaInforNode, "text": o2.LP.widget.uploadInfor}).inject(formNode);
- var inputAreaNode = new Element("div", {"styles": this.css.inputUploadAreaInputAreaNode}).inject(formNode);
- var inputNode = new Element("input", {"name":"file", "type": "file", "styles": this.css.inputUploadAreaInputNode}).inject(inputAreaNode);
- var inputNameNode = new Element("input", {"type": "hidden", "name": "fileName"}).inject(inputAreaNode);
- Object.each(obj, function(v, k){
- new Element("input", {"type": "hidden", "name": k, "value": v}).inject(inputAreaNode);
- });
- var actionNode = new Element("div", {"styles": this.css.inputUploadActionNode}).inject(formNode);
- var cancelButton = new Element("button", {"styles": this.css.inputUploadCancelButton, "text": o2.LP.widget.cancel}).inject(actionNode);
- var okButton = new Element("input", {"type": "button", "styles": this.css.inputUploadOkButton, "value": o2.LP.widget.ok}).inject(actionNode);
- inputNode.addEvent("change", function(){
- var fileName = inputNode.get("value");
- if (fileName){
- var tmpv = fileName.replace(/\\/g, "/");
- var i = tmpv.lastIndexOf("/");
- var fname = (i===-1) ? tmpv : tmpv.substr(i+1, tmpv.length-i);
- inputNameNode.set("value", fname);
- }
- }.bind(this));
- cancelButton.addEvent("click", function(){
- if (maskNode) maskNode.unmask();
- this.inputUploadAreaNode.destroy();
- }.bind(this));
- okButton.addEvent("click", function(){
- formNode.mask({
- "style": {
- "opacity": 0.7,
- "background-color": "#999"
- }
- });
- var isContinue = true;
- if (beforeUpload) isContinue = beforeUpload([inputNameNode.get("value")]);
- if (isContinue){
- messageItem = this.addUploadMessage(inputNameNode.get("value"));
- formNode.submit();
- if (maskNode) maskNode.unmask();
- if (this.inputUploadAreaNode) this.inputUploadAreaNode.destroy();
- }
- }.bind(this));
- }.bind(this));
- },
- doFormDataUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){
- var uploadChange = function(uploadfiles){
- var files = uploadfiles || this.fileUploadNode.files;
- if (files.length){
- var count = files.length;
- var current = 0;
- var hasFailUpload = false;
- var restActions = action;
- if (typeOf(action)=="string"){
- restActions = o2.Actions.get(action).action;
- }
- //var url = restActions.action.actions[invokeUri];
- var callback = function(){
- if (current == count){
- if(finish) finish( hasFailUpload );
- }
- };
- var isContinue = true;
- if (beforeUpload) isContinue = beforeUpload(files);
- if (isContinue){
- var accepts = (accept) ? accept.split(o2.splitStr) : null;
- for (var i = 0; i < files.length; i++) {
- var file = files.item(i);
- var ext = file.name.substr(file.name.lastIndexOf("."), file.name.length);
- ext = ext.toLowerCase();
- if (accepts && (accepts.indexOf(ext)===-1 && accepts.indexOf("*")===-1 && accepts.indexOf("*/*")===-1)){
- var msg = {
- "subject": o2.LP.widget.refuseUpload,
- "content": o2.LP.widget.refuseUploadHTML.replace("{filename}", file.name)
- };
- if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
- if (layout.desktop.message) layout.desktop.message.addMessage(msg);
- var text = o2.LP.widget.refuseUploadNotice.replace("{filename}", file.name);
- if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
- }else if (size && file.size> size*1024*1024){
- var msg = {
- "subject": o2.LP.widget.refuseUpload,
- "content": o2.LP.widget.refuseUploadHTML_size.replace("{filename}", file.name).replace("{size}", size)
- };
- if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
- if (layout.desktop.message) layout.desktop.message.addMessage(msg);
- var text = o2.LP.widget.refuseUploadNotice_size.replace("{filename}", file.name).replace("{size}", size);
- if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
- }else{
- var formData = new FormData();
- Object.each(obj, function(v, k){
- formData.append(k, v)
- });
- formData.append('file', file);
- if(parameter.fileMd5){
- o2.load("../o2_lib/CryptoJS/components/spark-md5-min.js", function(){
- var fileReader = new FileReader(), box = document.getElementById('box');
- var blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice;
- var chunkSize = 20971520;
- // read in chunks of 20MB
- var chunks = Math.ceil(file.size / chunkSize), currentChunk = 0, spark = new SparkMD5();
- fileReader.onload = function(e) {
- console.log("read chunk nr", currentChunk + 1, "of", chunks);
- spark.appendBinary(e.target.result);
- currentChunk++;
- if (currentChunk < chunks) {
- loadNext();
- } else {
- console.log("finished loading");
- var fileMd5 = spark.end();
- restActions.invoke({
- "name": "checkFileExist",
- "async": true,
- "parameter": {"fileMd5":fileMd5},
- "success": function(json){
- if(json.data.value){
- var formData2 = new FormData();
- formData2.append("fileMd5",fileMd5);
- formData2.append("fileName",file.name);
- restActions.invoke({
- "name": "addAttachmentMd5",
- "async": true,
- "data": formData2,
- "parameter": parameter,
- "success": function(json){
- current++;
- if (every) every(json, current, count);
- callback();
- },
- "failure": function (xhr) {
- var json = JSON.decode(xhr.responseText);
- if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
- current++;
- hasFailUpload = true;
- if (failureEvery) failureEvery(xhr, current, count);
- callback();
- }
- });
- }else{
- restActions.invoke({
- "name": invokeUrl,
- "async": true,
- "data": formData,
- "file": file,
- "parameter": parameter,
- "success": function(json){
- current++;
- if (every) every(json, current, count);
- callback();
- },
- "failure": function (xhr) {
- var json = JSON.decode(xhr.responseText);
- if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
- current++;
- hasFailUpload = true;
- if (failureEvery) failureEvery(xhr, current, count);
- callback();
- }
- });
- }
- }
- });
- // compute hash
- }
- };
- function loadNext() {
- var start = currentChunk * chunkSize, end = start + chunkSize >= file.size ? file.size : start + chunkSize;
- fileReader.readAsBinaryString(blobSlice.call(file, start, end));
- }
- loadNext();
- }.bind(this),null,false);
- }else{
- restActions.targetModule = {"module": this, "file": file};
- restActions.invoke({
- "name": invokeUrl,
- "async": true,
- "data": formData,
- "file": file,
- "parameter": parameter,
- "success": function(json){
- current++;
- if (every) every(json, current, count);
- callback();
- },
- "failure": function (xhr) {
- var json = JSON.decode(xhr.responseText);
- if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
- current++;
- hasFailUpload = true;
- if (failureEvery) failureEvery(xhr, current, count);
- callback();
- }
- });
- }
- }
- }
- }
- this.uploadFileAreaNode.destroy();
- this.uploadFileAreaNode = null;
- }
- }.bind(this);
- if (!this.uploadFileAreaNode){
- this.uploadFileAreaNode = new Element("div");
- var html = "<input name=\"file\" multiple type=\"file\" accept=\"*/*\"/>";
- this.uploadFileAreaNode.set("html", html);
- this.fileUploadNode = this.uploadFileAreaNode.getFirst();
- this.fileUploadNode.addEvent("change", function(){
- uploadChange();
- });
- }
- this.fileUploadNode.set("accept", accept || "*/*");
- this.fileUploadNode.set("multiple", (multiple!==false));
- if (!files || !files.length){
- this.fileUploadNode.click();
- }else{
- uploadChange(files)
- }
- },
- addFormDataMessage: function(file){
- return this.addAttachmentMessage(file);
- },
- addAttachmentMessage: function(file){
- var messageItem;
- if (this.options.size=="min"){
- messageItem = new o2.widget.AttachmentController.AttachmentMessageMin(file, this);
- }else{
- messageItem = new o2.widget.AttachmentController.AttachmentMessage(file, this);
- }
- if (!this.messageItemList) this.messageItemList = {};
- this.messageItemList[messageItem.data.id] = messageItem;
- return messageItem;
- },
- openInOfficeControl: function(e, node){},
- deleteAttachment: function(e, node){
- if (this.selectedAttachments.length){
- if (this.module) this.module.deleteAttachments(e, node, this.selectedAttachments);
- }
- },
- replaceAttachment: function(e, node){
- if (this.selectedAttachments.length && this.selectedAttachments.length==1){
- if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
- }
- },
- doReplaceAttachment: function(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size){
- if (FormData.expiredIE){
- this.doInputUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
- }else{
- this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
- }
- },
- previewAttachment: function(e, node){
- if (this.selectedAttachments.length){
- if (this.module) this.module.previewAttachment(this.selectedAttachments);
- }
- },
- editAttachment: function(e, node){
- if (this.selectedAttachments.length){
- if (this.module) this.module.editAttachment(this.selectedAttachments);
- }
- },
- downloadAttachment: function(e, node){
- if (this.selectedAttachments.length){
- if (this.module) this.module.downloadAttachment(e, node, this.selectedAttachments);
- }
- },
- openAttachment: function(e, node, attachment){
- if( !this.options.dblclick ){
- if( !this.options.isDownload || this.options.isDownload === "hidden" )return; //兼容以前的配置
- }
- if (attachment){
- if (this.module) this.module.openAttachment(e, node, attachment);
- }
- },
- dblclickAttachment: function(e, node, attachment){
- if( !attachment || !this.module || this.options.dblclick === "disable" ){
- return;
- }else if( this.options.dblclick === "preview" ){
- if( this.checkPreviewAttachment ){
- this.checkPreviewAttachment(e, node, attachment);
- }else{
- this.module.openAttachment(e, node, attachment);
- }
- }else{
- this.module.openAttachment(e, node, attachment);
- }
- },
- downloadAllAttachment: function(e, node){
- if (this.module) this.module.downloadAttachment(e, node, this.attachments);
- },
- changeListStyle: function(style){
- this.options.listStyle = style;
- this.listStyle = style;
- this.attachments.each(function(attachment){
- attachment.changeListStyle(style);
- }.bind(this));
- this.checkListStyleAction();
- },
- changeControllerSize: function(e, node){
- if (this.options.size=="max"){
- this.changeControllerSizeToMin();
- }else{
- this.changeControllerSizeToMax();
- }
- },
- changeControllerSizeToMin: function(){
- if (this.options.size!="min"){
- if (this.contentScrollNode) this.contentScrollNode.setStyle("display", "none");
- if (this.bottomNode) this.bottomNode.setStyle("display", "none");
- if (this.topNode) this.topNode.setStyle("display", "none");
- if (this.titleNode) this.titleNode.setStyle("display", "none");
- if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100});
- this.nodeMorph.start(this.css.container_min).chain(function(){
- this.options.size = "min";
- this.loadMin();
- }.bind(this));
- }
- },
- changeControllerSizeToMax: function(){
- if (this.options.size!="max") {
- if (this.minActionAreaNode) this.minActionAreaNode.setStyle("display", "none");
- if (this.minContent) this.minContent.setStyle("display", "none");
- if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100});
- this.nodeMorph.start(this.css.container).chain(function () {
- this.options.size = "max";
- this.loadMax();
- }.bind(this));
- }
- },
- getAttachmentNames: function(){
- var names = [];
- this.attachments.each(function(attachment){
- names.push(attachment.data.name);
- });
- return names;
- },
- addAttachment: function(data, messageId, isCheckPosition){
- if (this.options.size=="min"){
- this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(data, this, messageId, isCheckPosition));
- }else{
- this.attachments.push(new o2.widget.AttachmentController.Attachment(data, this, messageId, isCheckPosition));
- }
- this.checkActions();
- },
- removeAttachment: function(attachment){
- this.attachments.erase(attachment);
- this.selectedAttachments.erase(attachment);
- attachment.node.destroy();
- delete attachment;
- },
- unSelectedAttachments: function(){
- while (this.selectedAttachments.length){
- var attachment = this.selectedAttachments.shift();
- attachment.unSelected();
- }
- this.checkActions();
- },
- clear: function(){
- this.selectedAttachments = [];
- this.attachments.each(function(att){
- att.node.destroy();
- o2.release(att);
- });
- this.attachments = [];
- var content = (this.minContent || this.content);
- if (content) content.empty();
- }
- });
- o2.widget.AttachmentController.Attachment = new Class({
- Implements: [Events],
- initialize: function(data, controller, messageId, isCheckPosition){
- this.data = data;
- if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
- this.controller = controller;
- this.css = this.controller.css;
- this.listStyle = this.controller.options.listStyle;
- this.content = this.controller.content;
- this.isSelected = false;
- this.seq = this.controller.attachments.length+1;
- this.isCheckPosition = isCheckPosition;
- this.actions = [];
- if (messageId && this.controller.messageItemList) {
- this.message = this.controller.messageItemList[messageId];
- }
- this.load();
- },
- _getLnkPar: function(url){
- return {
- "icon": this.getIcon(),
- "title": this.data.name,
- "par": "@url#"+url
- };
- },
- isNumber : function( d ){
- return parseFloat(d).toString() !== "NaN"
- },
- load: function(){
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("beforeLoadAttachment", [this]);
- }
- if (this.message){
- this.node = new Element("div").inject(this.message.node, "after");
- this.message.node.destroy();
- delete this.controller.messageItemList[this.message.data.id];
- }else{
- this.node = new Element("div").inject(this.content);
- }
- if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){
- var attList = this.controller.attachments;
- for( var i=0; i<attList.length; i++ ){
- var att = attList[i];
- if( !this.isNumber(att.data.orderNumber) || this.data.orderNumber < att.data.orderNumber ){
- this.node.inject( att.node, "before" );
- break;
- }
- }
- }
- switch (this.controller.options.listStyle){
- case "list":
- this.loadList();
- break;
- case "icon":
- this.loadIcon();
- break;
- case "preview":
- this.loadPreview();
- break;
- case "sequence":
- this.loadSequence();
- break;
- }
- this.controller.module.getAttachmentUrl(this, function(url){
- this.node.makeLnk({
- "par": this._getLnkPar(url)
- });
- }.bind(this));
- this.createInforNode(function(){
- if (!Browser.Platform.ios){
- this.tooltip = new mBox.Tooltip({
- content: this.inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: this.node,
- transition: 'flyin'
- });
- }
- }.bind(this));
- this.setEvent();
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("loadAttachment", [this]);
- }
- },
- createInforNode: function(callback){
- var size = "";
- var k = this.data.length/1024;
- if (k>1024){
- var m = k/1024;
- m = Math.round(m*100)/100;
- size = m+"M";
- }else{
- k = Math.round(k*100)/100;
- size = k+"K";
- }
- this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode});
- var html = "<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";
- 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>";
- 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>";
- 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>";
- 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>";
- 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>";
- this.inforNode.set("html", html);
- if (callback) callback();
- },
- getIcon: function(){
- if (!this.data.extension) this.data.extension="unkonw";
- var iconName = this.controller.icons[this.data.extension.toLowerCase()] || this.controller.icons.unknow;
- var iconFolderUrl = this.controller.options.iconFolderUrl ? this.controller.options.iconFolderUrl : "../x_component_File/$Main/default/file/";
- return iconFolderUrl+iconName;
- },
- loadList: function(){
- this.node.setStyles(this.css.attachmentNode_list);
- if (this.isSelected) this.node.setStyles(this.css.attachmentNode_list_selected);
- this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
- this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
- this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
- this.iconImgNode.set({"src": this.getIcon(), "border": 0});
- this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_list}).inject(this.node);
- this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
- // this.textTitleNode.set("text", this.data.name);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textTitleNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textTitleNode.set("text", this.data.name);
- }
- var size = "";
- var k = this.data.length/1024;
- if (k>1024){
- var m = k/1024;
- m = Math.round(m*100)/100;
- size = m+"M";
- }else{
- k = Math.round(k*100)/100;
- size = k+"K";
- }
- this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
- this.textSizeNode.set("text", size);
- this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
- this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid ));
- this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
- this.textTimeNode.set("text", this.data.lastUpdateTime);
- if(this.data.activityName){
- this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
- this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);
- }
- this.custom_List();
- },
- custom_List: function(){},
- loadSequence: function(){
- this.node.setStyles(this.css.attachmentNode_sequence);
- if (this.isSelected) this.node.setStyles(this.css.attachmentNode_sequence_selected);
- this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);
- this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
- this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
- this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
- this.iconImgNode.set({"src": this.getIcon(), "border": 0});
- this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_sequence}).inject(this.node);
- this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
- // this.textTitleNode.set("text", this.data.name);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textTitleNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textTitleNode.set("text", this.data.name);
- }
- var size = "";
- var k = this.data.length/1024;
- if (k>1024){
- var m = k/1024;
- m = Math.round(m*100)/100;
- size = m+"M";
- }else{
- k = Math.round(k*100)/100;
- size = k+"K";
- }
- this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
- this.textSizeNode.set("text", size);
- this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
- this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid));
- this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
- this.textTimeNode.set("text", this.data.lastUpdateTime);
- if(this.data.activityName){
- this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
- this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);
- }
- this.custom_Sequence();
- },
- custom_Sequence: function(){},
- loadIcon: function(){
- this.node.setStyles(this.css.attachmentNode_icon);
- if (this.isSelected) this.node.setStyles(this.css.attachmentNode_icon_selected);
- this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode}).inject(this.node);
- this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode}).inject(this.iconNode);
- this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode}).inject(this.iconImgAreaNode);
- this.iconImgNode.set({"src": this.getIcon(), "border": 0});
- this.textNode = new Element("div", {"styles": this.css.attachmentTextNode}).inject(this.node);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- this.custom_Icon();
- },
- custom_Icon: function(){},
- loadPreview: function(){
- this.node.setStyles(this.css.attachmentNode_preview);
- if (this.isSelected) this.node.setStyles(this.css.attachmentNode_preview_selected);
- this.iconNode = new Element("div", {"styles": this.css.attachmentPreviewIconNode}).inject(this.node);
- this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentPreviewIconImgAreaNode}).inject(this.iconNode);
- this.iconImgNode = new Element("img", {"styles": this.css.attachmentPreviewIconImgNode}).inject(this.iconImgAreaNode);
- var icon = this.getIcon();
- if (this.controller.options.images.indexOf(this.data.extension.toLowerCase())!==-1){
- if (this.type!=="message") this.controller.module.getAttachmentUrl(this, function(url){
- this.iconImgAreaNode.hide();
- this.iconImgNode.hide();
- this.iconNode.setStyles({
- "background-image": "url("+url+")",
- });
- }.bind(this));
- this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // this.textNode.set("text", this.data.name);
- }else if (this.controller.options.audios.indexOf(this.data.extension.toLowerCase())!==-1){
- this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // this.textNode.set("text", this.data.name);
- this.controller.module.getAttachmentUrl(this, function(url){
- this.iconImgNode.set({"src": icon, "border": 0});
- this.iconAudioNode = new Element("div", {
- "styles": this.css.attachmentPreviewAudioNode,
- "html": "<audio preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+url+"\" type=\"audio/mpeg\"></source></audio>"
- //"html": "<audio controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+o2.session.path+"/xApplication/File/$Main/qnyh.mp3\"></source></audio>"
- }).inject(this.textNode, "after");
- this.iconAudioNode.addEvent("dblclick", function(e){e.stopPropagation();});
- }.bind(this));
- }else if (this.controller.options.videos.indexOf(this.data.extension.toLowerCase())!==-1){
- this.controller.module.getAttachmentUrl(this, function(url){
- this.iconNode.empty();
- this.iconVideoNode = new Element("div", {
- "styles": this.css.attachmentPreviewVideoNode,
- //"html": "<video preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+o2.session.path+"/xApplication/File/$Main/IMG_1615.MOV\"></source></video>"
- "html": "<video preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+url+"\"></source></video>"
- }).inject(this.iconNode);
- this.iconVideoNode.addEvent("dblclick", function(e){e.stopPropagation();});
- this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // this.textNode.set("text", this.data.name);
- }.bind(this));
- }else{
- this.iconImgNode.set({"src": icon, "border": 0});
- this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // this.textNode.set("text", this.data.name);
- }
- this.custom_Preview();
- },
- custom_Preview: function(){},
- getPreviewImgSize: function(icon, callback){
- var areaSize = this.iconNode.getSize();
- var img = new Element("img", {"src": icon}).inject($(document.body));
- img.set("src", icon);
- var size = img.getSize();
- img.destroy();
- var x, y;
- var zoom = areaSize.x/size.x;
- var y = size.y*zoom;
- if (y<=areaSize.y){
- x = areaSize.x;
- }else{
- zoom = areaSize.y/size.y;
- x = size.x*zoom;
- y = areaSize.y;
- }
- var size = {"x": x, "y": y, "top": (areaSize.y-y)/2};
- if (callback) callback(size);
- },
- setEvent: function(){
- this.node.addEvents({
- "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"])}.bind(this),
- "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle])}.bind(this),
- "mousedown": function(e){this.selected(e); e.stopPropagation();}.bind(this),
- "click": function(e){e.stopPropagation();}.bind(this),
- "dblclick": function(e){
- if( this.controller.options.dblclick ){
- this.controller.dblclickAttachment(e, null, [this]);
- }else{
- this.openAttachment(e);
- }
- }.bind(this)
- });
- if (this.iconImgNode){
- this.iconImgNode.set("draggable", false);
- }
- },
- selected: function(e){
- if (!e.event.ctrlKey) this.controller.unSelectedAttachments();
- //if (!this.isSelected){
- this.controller.selectedAttachments.push(this);
- this.isSelected = true;
- this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]);
- //}
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("select", [this]);
- }
- if (e) e.stopPropagation();
- this.controller.checkActions();
- },
- unSelected: function(){
- this.isSelected = false;
- this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
- this.controller.selectedAttachments.erase(this);
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("unselect", [this]);
- }
- },
- changeListStyle: function(style){
- if (this.listStyle!=style){
- this.node.empty();
- switch (style){
- case "list":
- this.loadList();
- break;
- case "icon":
- this.loadIcon();
- break;
- case "preview":
- this.loadPreview();
- break;
- case "sequence":
- this.loadSequence();
- break;
- }
- this.listStyle = style;
- }
- },
- reload: function(){
- var node = new Element("div").inject(this.node, "after");
- this.inforNode.destroy();
- this.inforNode = null;
- if (this.tooltip) this.tooltip.destroy();
- this.tooltip = null;
- this.node.destroy();
- delete this.node;
- this.node = node;
- switch (this.listStyle){
- case "list":
- this.loadList();
- break;
- case "icon":
- this.loadIcon();
- break;
- case "preview":
- this.loadPreview();
- break;
- case "sequence":
- this.loadSequence();
- break;
- }
- this.createInforNode();
- if (!Browser.Platform.ios){
- this.tooltip = new mBox.Tooltip({
- content: this.inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: this.node,
- transition: 'flyin'
- });
- }
- this.setEvent();
- },
- openAttachment: function(e){
- if( !this.controller.options.dblclick ){
- if (!this.controller.options.isDownload || this.controller.options.isDownload === "hidden") return; //兼容以前的配置
- }
- if (this.controller.module) this.controller.module.openAttachment(e, null, [this]);
- },
- setActionEnabled: function(action){
- if (action){
- action.setStyle("display","");
- action.store("disabled", false);
- //if (action.retrieve("disabled")){
- // var iconNode = action.getFirst();
- // var icon = iconNode.getStyle("background-image");
- // var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
- // icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext;
- // iconNode.setStyle("background-image", icon);
- // action.store("disabled", false);
- //}
- }
- },
- setActionDisabled: function(action){
- if (action){
- action.setStyle("display","none");
- action.store("disabled", true);
- //if (!action.retrieve("disabled")){
- // var iconNode = action.getFirst();
- // var icon = iconNode.getStyle("background-image");
- // var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
- // icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext;
- // iconNode.setStyle("background-image", icon);
- // action.store("disabled", true);
- //}
- }
- },
- createAction: function(node, img, img_over, title, click, text){
- var actionNode;
- if( this.controller.options.actionShowText ){
- actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "text": text || title, "title" : title }).inject(node);
- var _self = this;
- actionNode.addEvents({
- "mouseover": function( e ){
- if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over){
- actionNode.setStyles( _self.controller.css.minActionNode_over );
- }
- }.bind( { actionNode : actionNode } ),
- "mouseout": function(){
- if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over ){
- actionNode.setStyles( _self.controller.css.minActionNode );
- }
- }.bind( { actionNode : actionNode } ),
- "click": function(e){
- if (!this.retrieve("disabled")){
- click.apply(_self.controller, [e, this]);
- e.stopPropagation();
- }
- }
- });
- }else{
- actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "title": title}).inject(node);
- var actionIconNode = new Element("div", {"styles": this.controller.css.minActionIconNode}).inject(actionNode);
- actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.controller.options.style+"/icon/"+img+".png)");
- var _self = this;
- actionNode.addEvents({
- "mouseover": function( e ){
- if (!this.actionNode.retrieve("disabled")){
- this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)");
- }
- }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img_over } ),
- "mouseout": function(){
- if (!this.actionNode.retrieve("disabled")){
- this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)");
- }
- }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img } ),
- "click": function(e){
- if (!this.retrieve("disabled")){
- click.apply(_self.controller, [e, this]);
- e.stopPropagation();
- }
- }
- });
- }
- if( !this.actions )this.actions = [];
- this.actions.push(actionNode);
- return actionNode;
- }
- });
- o2.widget.AttachmentController.AttachmentMin = new Class({
- Extends: o2.widget.AttachmentController.Attachment,
- initialize: function(data, controller, messageId, isCheckPosition){
- this.data = data;
- if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
- this.controller = controller;
- this.css = this.controller.css;
- this.listStyle = this.controller.options.listStyle;
- this.content = this.controller.minContent;
- this.isSelected = false;
- this.isCheckPosition = isCheckPosition;
- this.seq = this.controller.attachments.length+1;
- if (messageId && this.controller.messageItemList) {
- this.message = this.controller.messageItemList[messageId];
- }
- this.load();
- },
- load: function(){
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("beforeLoadAttachment", [this]);
- }
- if (this.message){
- this.node = new Element("div").inject(this.message.node, "after");
- this.message.node.destroy();
- delete this.controller.messageItemList[this.message.data.id];
- }else{
- this.node = new Element("div").inject(this.content);
- }
- if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){
- var attList = this.controller.attachments;
- for( var i=0; i<attList.length; i++ ){
- var att = attList[i];
- if( !this.isNumber(att.data.orderNumber) || this.data.orderNumber < att.data.orderNumber ){
- this.node.inject( att.node, "before" );
- break;
- }
- }
- }
- //this.node = new Element("div").inject(this.content);
- //this.loadList();
- switch (this.controller.options.listStyle){
- case "list":
- this.loadList();
- break;
- case "icon":
- this.loadIcon();
- break;
- case "preview":
- this.loadPreview();
- break;
- case "sequence":
- this.loadSequence();
- break;
- }
- this.createInforNode();
- if (!Browser.Platform.ios && !layout.mobile){
- this.tooltip = new mBox.Tooltip({
- content: this.inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: this.iconImgNode,
- transition: 'flyin'
- });
- }
- this.setEvent();
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("loadAttachment", [this]);
- }
- },
- loadList: function() {
- this.node.setStyles( layout.mobile ? this.css.minAttachmentNode_list_mobile : this.css.minAttachmentNode_list);
- if( !layout.mobile ){
- this.sepNode = new Element("div", {"styles": this.css.minAttachmentSepNode_list}).inject(this.node);
- }
- this.actionAreaNode = new Element("div", {"styles": this.css.minAttachmentActionAreaNode}).inject(this.node);
- if( this.controller.isAttDblclickAvailable(this) ){
- this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) {
- this.controller.dblclickAttachment(e, node, [this]);
- }.bind(this));
- }
- if ( this.controller.isAttDownloadAvailable(this) ) {
- this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) {
- this.controller.downloadAttachment(e, node);
- }.bind(this));
- }
- //this.actions.push( this.downloadAction );
- if ( this.controller.isAttDeleteAvailable(this) ) {
- this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) {
- this.controller.deleteAttachment(e, node);
- }.bind(this));
- }
- if ( this.controller.isAttEditAvailable(this) ) {
- this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) {
- this.controller.editAttachment(e, node);
- }.bind(this));
- }
- //this.actions.push( this.deleteAction );
- if (this.controller.configAttachment) {
- if ( this.controller.isAttConfigAvailable(this) ) {
- this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", o2.LP.widget.configAttachment, function (e, node) {
- this.controller.configAttachment(e, node);
- }.bind(this), o2.LP.widget.configAttachmentText );
- //this.actions.push( this.configAction );
- }
- }
- if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected);
- this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node);
- this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode);
- this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode);
- this.iconImgNode.set({"src": this.getIcon(), "border": 0});
- this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // this.textNode.set("text", this.data.name);
- var size = "";
- var k = this.data.length/1024;
- if (k>1024){
- var m = k/1024;
- m = Math.round(m*100)/100;
- size = m+"M";
- }else{
- k = Math.round(k*100)/100;
- size = k+"K";
- }
- this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode);
- this.textSizeNode.set("text", "("+size+")");
- this.node.set("title",this.data.name + "("+size+")");
- },
- loadSequence: function(){
- this.node.setStyles(this.css.minAttachmentNode_sequence);
- this.actionAreaNode = new Element("div", {"styles":this.css.minAttachmentActionAreaNode}).inject(this.node);
- if( this.controller.isAttDblclickAvailable(this) ){
- this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) {
- this.controller.dblclickAttachment(e, node, [this]);
- }.bind(this));
- }
- if ( this.controller.isAttDownloadAvailable(this) ) {
- this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) {
- this.controller.downloadAttachment(e, node);
- }.bind(this));
- }
- //this.actions.push( this.downloadAction );
- if ( this.controller.isAttDeleteAvailable(this) ) {
- this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) {
- this.controller.deleteAttachment(e, node);
- }.bind(this));
- }
- if ( this.controller.isAttEditAvailable(this) ) {
- this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) {
- this.controller.editAttachment(e, node);
- }.bind(this));
- }
- //this.actions.push( this.deleteAction );
- if (this.controller.configAttachment) {
- if ( this.controller.isAttConfigAvailable(this) ) {
- this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", MWF.LP.widget.configAttachment, function (e, node) {
- this.controller.configAttachment(e, node);
- }.bind(this));
- //this.actions.push( this.configAction );
- }
- }
- if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected);
- this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);
- this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node);
- this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode);
- this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode);
- this.iconImgNode.set({"src": this.getIcon(), "border": 0});
- this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node);
- if (this.data.objectSecurityPromise){
- this.data.objectSecurityPromise.then(function(label){
- this.textNode.set("text", "("+label+") " + this.data.name);
- }.bind(this));
- }else{
- this.textNode.set("text", this.data.name);
- }
- // this.textNode.set("text", this.data.name);
- var size = "";
- var k = this.data.length/1024;
- if (k>1024){
- var m = k/1024;
- m = Math.round(m*100)/100;
- size = m+"M";
- }else{
- k = Math.round(k*100)/100;
- size = k+"K";
- }
- this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode);
- this.textSizeNode.set("text", "("+size+")");
- },
- setEvent: function(){
- this.node.addEvents({
- "mouseover": function(){
- if (!this.isSelected){
- if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
- this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_over"]);
- }else{
- this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"]);
- }
- }
- }.bind(this),
- "mouseout": function(){
- if (!this.isSelected){
- if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
- var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
- this.node.setStyles(this.css[cssKey]);
- }else{
- this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
- }
- }
- }.bind(this),
- "mousedown": function(e){this.selected(e);e.stopPropagation();}.bind(this),
- "click": function(e){e.stopPropagation();}.bind(this),
- "dblclick": function(e){
- if( this.controller.options.dblclick ){
- this.controller.dblclickAttachment(e, null, [this]);
- }else{
- this.openAttachment(e);
- }
- }.bind(this)
- });
- if (this.iconImgNode){
- this.iconImgNode.set("draggable", false);
- }
- },
- selected: function(e){
- if (!e.event.ctrlKey) this.controller.unSelectedAttachments();
- //if (!this.isSelected){
- this.controller.selectedAttachments.push(this);
- this.isSelected = true;
- if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
- //this.node.setStyles(this.css["minAttachmentNode_list_selected"]);
- this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_selected"]);
- }else{
- this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]);
- //this.node.setStyles(this.css["minAttachmentNode_list_selected"]);
- }
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("select", [this]);
- }
- //}
- if (e) e.stopPropagation();
- this.controller.checkActions();
- },
- reload: function(){
- var node = new Element("div").inject(this.node, "after");
- this.inforNode.destroy();
- this.inforNode = null;
- if (this.tooltip) this.tooltip.destroy();
- this.tooltip = null;
- this.node.destroy();
- delete this.node;
- this.node = node;
- debugger;
- switch (this.listStyle){
- case "list":
- this.loadList();
- break;
- case "icon":
- this.loadIcon();
- break;
- case "preview":
- this.loadPreview();
- break;
- case "sequence":
- this.loadSequence();
- break;
- }
- this.createInforNode();
- if (!Browser.Platform.ios){
- this.tooltip = new mBox.Tooltip({
- content: this.inforNode,
- setStyles: {content: {padding: 15, lineHeight: 20}},
- attach: this.node,
- transition: 'flyin'
- });
- }
- this.setEvent();
- },
- unSelected: function(){
- this.isSelected = false;
- //this.node.setStyles(this.css["minAttachmentNode_list"]);
- if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
- var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
- this.node.setStyles(this.css[cssKey]);
- }else{
- this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
- }
- if( this.controller.module && this.controller.module.fireEvent ){
- this.controller.module.fireEvent("unselect", [this]);
- }
- this.controller.selectedAttachments.erase(this);
- }
- });
- o2.widget.AttachmentController.AttachmentMessage = new Class({
- Extends: o2.widget.AttachmentController.Attachment,
- Implements: [Events],
- initialize: function(file, controller){
- var d = (new Date).format("db");
- var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length);
- this.file = file;
- this.type = "message";
- this.data = {
- activity: "",
- activityName: "",
- activityToken: "",
- activityType: "manual",
- application: "",
- completed: false,
- control: {allowRead:true, allowEdit:false, allowControl:false},
- controllerIdentityList: [],
- controllerUnitList: [],
- createTime: d,
- deepPath: false,
- divisionList: [],
- editIdentityList: [],
- editUnitList: [],
- extension: extension,
- id: (new o2.widget.UUID()).toString(),
- job: "",
- lastUpdatePerson: (layout) ? layout.session.user.name : "",
- lastUpdateTime: d,
- length: file.size,
- name: file.name,
- person: (layout) ? layout.session.user.name : "",
- process: "",
- readIdentityList: [],
- readUnitList: [],
- site: "$doc",
- storage: file.size,
- type: "",
- updateTime: d,
- workCreateTime: ""
- }
- if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
- this.controller = controller;
- this.css = this.controller.css;
- this.listStyle = this.controller.options.listStyle;
- this.content = this.controller.content;
- this.isSelected = false;
- this.seq = this.controller.attachments.length+1;
- this.actions = [];
- this.load();
- },
- load: function(){
- this.node = new Element("div").inject(this.content);
- switch (this.controller.options.listStyle){
- case "list":
- this.loadList();
- break;
- case "icon":
- this.loadIcon();
- break;
- case "preview":
- this.loadPreview();
- break;
- case "sequence":
- this.loadSequence();
- break;
- }
- this.setEvent();
- this.loadMessage();
- },
- loadMessage: function(){
- var size = this.node.getSize();
- this.node.setStyle("position", "relative");
- this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node);
- this.messageMaskNode.setStyles({
- "width": ""+size.x+"px",
- "height": ""+size.y+"px"
- });
- this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node);
- switch (this.controller.options.listStyle){
- case "list":
- case "sequence":
- this.messageNode.setStyles({
- "width": "0px",
- "height": ""+size.y+"px"
- });
- break;
- case "icon":
- case "preview":
- this.messageNode.setStyles({
- "width": ""+size.x+"px",
- "height": ""+size.y+"px"
- });
- break;
- }
- this.messageText = new Element("div", {
- "styles": this.css.messageText,
- "text": "0%"
- }).inject(this.node);
- this.messageText.setStyles({
- "width": ""+size.x+"px",
- "height": ""+size.y+"px",
- "line-height": ""+size.y+"px"
- });
- },
- updateProgress: function(percent){
- var size = this.node.getSize();
- switch (this.controller.options.listStyle){
- case "list":
- case "sequence":
- var w = size.x*(percent/100);
- this.messageNode.setStyles({
- "width":""+w+"px"
- });
- break;
- case "icon":
- case "preview":
- var h = size.y*(1-percent/100);
- this.messageNode.setStyle("height", ""+h+"px");
- break;
- }
- var p = (percent*100).toInt()/100;
- this.messageText.set("text", ""+p+"%")
- },
- transferComplete: function(){
- this.messageText.set("text", "loading...")
- }
- });
- o2.widget.AttachmentController.AttachmentMessageMin = new Class({
- Extends: o2.widget.AttachmentController.AttachmentMin,
- Implements: [Events],
- initialize: function(file, controller){
- var d = (new Date).format("db");
- var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length);
- this.file = file;
- this.data = {
- activity: "",
- activityName: "",
- activityToken: "",
- activityType: "manual",
- application: "",
- completed: false,
- control: {allowRead:true, allowEdit:false, allowControl:false},
- controllerIdentityList: [],
- controllerUnitList: [],
- createTime: d,
- deepPath: false,
- divisionList: [],
- editIdentityList: [],
- editUnitList: [],
- extension: extension,
- id: (new o2.widget.UUID()).toString(),
- job: "",
- lastUpdatePerson: (layout) ? layout.session.user.name : "",
- lastUpdateTime: d,
- length: file.size,
- name: file.name,
- person: (layout) ? layout.session.user.name : "",
- process: "",
- readIdentityList: [],
- readUnitList: [],
- site: "$doc",
- storage: file.size,
- type: "",
- updateTime: d,
- workCreateTime: ""
- }
- if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
- this.controller = controller;
- this.css = this.controller.css;
- this.listStyle = this.controller.options.listStyle;
- this.content = this.controller.minContent;
- this.isSelected = false;
- this.seq = this.controller.attachments.length+1;
- this.actions = [];
- this.load();
- },
- load: function(){
- this.node = new Element("div").inject(this.content);
- switch (this.controller.options.listStyle){
- case "list":
- this.loadList();
- break;
- case "icon":
- this.loadIcon();
- break;
- case "preview":
- this.loadPreview();
- break;
- case "sequence":
- this.loadSequence();
- break;
- }
- this.setEvent();
- this.loadMessage();
- },
- loadMessage: function(){
- var size = this.node.getSize();
- this.node.setStyle("position", "relative");
- this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node);
- this.messageMaskNode.setStyles({
- "width": ""+size.x+"px",
- "height": ""+size.y+"px"
- });
- this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node);
- switch (this.controller.options.listStyle){
- case "list":
- case "sequence":
- this.messageNode.setStyles({
- "width": "0px",
- "height": ""+size.y+"px"
- });
- break;
- case "icon":
- case "preview":
- this.messageNode.setStyles({
- "width": ""+size.x+"px",
- "height": ""+size.y+"px"
- });
- break;
- }
- this.messageText = new Element("div", {
- "styles": this.css.messageText,
- "text": "0%"
- }).inject(this.node);
- this.messageText.setStyles({
- "width": ""+size.x+"px",
- "height": ""+size.y+"px",
- "line-height": ""+size.y+"px"
- });
- },
- updateProgress: function(percent){
- var size = this.node.getSize();
- switch (this.controller.options.listStyle){
- case "list":
- case "sequence":
- var w = size.x*(percent/100);
- this.messageNode.setStyles({
- "width":""+w+"px"
- });
- break;
- case "icon":
- case "preview":
- var h = size.y*(1-percent/100);
- this.messageNode.setStyle("height", ""+h+"px");
- break;
- }
- var p = (percent*100).toInt()/100;
- this.messageText.set("text", ""+p+"%")
- },
- transferComplete: function(){
- this.messageText.set("text", "loading...")
- }
- });
|