jQuery教程 dynamics crm 365附件上传图片并且显示
沉沙 2018-10-25 来源 : 阅读 1674 评论 0

摘要:本篇教程介绍了jQuery教程 dynamics crm 365附件上传图片并且显示,希望阅读本篇文章以后大家有所收获,帮助大家对jQuery的理解更加深入。

本篇教程介绍了jQuery教程 dynamics crm 365附件上传图片并且显示,希望阅读本篇文章以后大家有所收获,帮助大家对jQuery的理解更加深入。

<


新增websource文件(html):

<!DOCTYPE html>
<html>
 <head> 
  <title>注释</title> 
  <style type="text/css">
            table {
                border:1px solid #666666;
                border-collapse:collapse;
            }
            table thead th {
                 padding: 8px;
                    border:1px solid #666666;
                 background-color: #dedede;
            }
            
            table tbody td {
                border: 1px solid  #666666;
             padding: 8px;
             background-color: #ffffff;
            }
            
            table thead tr th {
                font-family:Microsoft YaHei,SimSun,Tahoma,Arial;
                font-size:12px;
                font-weight:bold;
                color:#000000;
            }
            
            table tbody tr td {
                color:#444444;
                font-family:Microsoft YaHei,SimSun,Tahoma,Arial;
                font-size:12px;
            }
            
            .align_right
            {
               text-align: right;
            }

        </style> 
  <script type="text/javascript" src="../../_static/_common/scripts/jquery1.7.2.min.js"></script> 
  <script type="text/javascript" src="../../_static/_common/scripts/XrmServiceToolkit.min.js"></script>  //路径很重要,必须确定自己websource所在的位置,然后根据路径写js路径,要不然加载不了。
  <script type="text/javascript">
    
            Date.prototype.format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1,//月份   
                    "d+": this.getDate(),//日   
                    "h+": this.getHours(),//小时   
                    "m+": this.getMinutes(),//分   
                    "s+": this.getSeconds()//秒     
                };
                if (/(y+)/.test(fmt))
                    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt))
                        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ?
                                 (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            }
            
       
            
            function ShowAttachmentByNoteId(NoteId) {
                XrmServiceToolkit.Rest.Retrieve(
                    NoteId,
                    "AnnotationSet",
                    "DocumentBody,MimeType",
                    null,
                    function (result) {
                        var DocumentBody = result.DocumentBody;
                        var MimeType = result.MimeType;
                        if (MimeType.indexOf("image") > -1) {
                     
                            
                            //new method
                            initblock(DocumentBody,MimeType);
                        }
                        else {
                            alert(‘附件不是图片,目前无法提供查看!‘);
                        }
                    },
                    function (error) {
                        alert(error.message);
                    },
                    true
                );
            }
            
        function initblock(DocumentBody,MimeType)
        {
            if($("#overlay").length > 0) {
                 $("#overlay").empty();
              }  
              
              if($("#dialogImg").length > 0) {
                 $("#dialogImg").empty();
              }
              
            var div = parent.document.createElement("div");
            div.id = "overlay";
            div.style.position="fixed";
            div.style.top="0";
            div.style.right="0";
            div.style.bottom="0";
        
            div.style.left="0";
          
            div.style.height="100%";
            div.style.width="100%";
            div.style.margin="0";
            div.style.padding="0";
            div.style.background=" #000000";
            div.style.opacity=".15";
            div.style.filter=" alpha(opacity=15)";
            div.style.display="none";
            parent.document.body.appendChild(div);
 
            var divImg =parent.document.createElement("div");
            divImg.id = "dialogImg";
            divImg.style.display="none";
            divImg.style.position="fixed";
            divImg.style.width="250px";
            divImg.style.height="280px";
            divImg.style.top="20%";
            divImg.style.left="20%";
             divImg.style.right="20%";
            divImg.style.bottom="20%";
            divImg.style.marginLeft="-190px";
            divImg.style.marginTop="-100px";
            divImg.style.backgroundColor="#ffffff";
            divImg.style.border="2px";
            divImg.style.borderStyle="solid";
            divImg.style.fontFamily="Verdana";
            divImg.style.fontSize="10pt";
            divImg.style.padding="0";
            divImg.style.zIndex="102";
 
            var table = parent.document.createElement("table");
            table.style.width = "100%";
            table.style.border = "0";
            table.cellPadding = "2";
            table.cellSpacing = "0";
            var tr1 = parent.document.createElement("tr");
            var td1 = parent.document.createElement("td");
            td1.style.borderBottom="solid";
            td1.style.border="1px";
            td1.style.borderColor="#2a1d54";
            td1.style.backgroundColor="#2a1d54";
            td1.style.padding="4px";
            td1.style.color="White";
            td1.style.fontWeight="bold";
            td1.innerText = "照片预览";
            var td11 = parent.document.createElement("td");
            td11.style.textAlign = "right"
            td11.style.borderBottom = "solid";
            td11.style.border = "1px";
            td11.style.borderColor = "#2a1d54";
            td11.style.backgroundColor = "#2a1d54";
            td11.style.padding = "4px";
            var a1 = parent.document.createElement("a");
            a1.style.color = "White";
            a1.style.fontWeight = "bold";
            a1.innerText = "关闭";
            a1.id = "btnCloseImg";
            a1.href = "#";
            a1.onclick = function (e) {
                debugger;
                $("#overlay",parent.document).hide();
                $("#dialogImg",parent.document).fadeOut(300);
                e.preventDefault();
            }
            td11.appendChild(a1);
            tr1.appendChild(td1);
            tr1.appendChild(td11);
            var tr2 = parent.document.createElement("tr");
            var td2 = parent.document.createElement("td");
            td2.colSpan = "2";
            
            var img = parent.document.createElement("img");
            img.id = "img1";
            td2.appendChild(img);
            tr2.appendChild(td2);
            table.appendChild(tr1);
            table.appendChild(tr2);
            divImg.appendChild(table);
            parent.document.body.appendChild(divImg);
         
          
            
            $("#overlay",parent.document).show();
            $("#dialogImg",parent.document).fadeIn(300);
            $("#img1",parent.document).attr("alt", "Embedded Image");
            $("#img1",parent.document).attr("src", "data:" + MimeType + ";base64," + DocumentBody);
            $("#overlay",parent.document).unbind("click");
            //e.preventDefault();
            
    
              dragPanelMove();
        }
        

        
        function dragPanelMove(){
            var dialogImg = $("#dialogImg",parent.document);    
               dialogImg.mousedown(function(e){
                //设置移动后的默认位置
                var endx=0;
                var endy=0;
             
                //获取div的初始位置,要注意的是需要转整型,因为获取到值带px
                var left= parseInt(dialogImg.css("left"));
                var top = parseInt(dialogImg.css("top"));
             
                //获取鼠标按下时的坐标,区别于下面的es.pageX,es.pageY
                var downx=e.pageX;
                var downy=e.pageY;   //pageY的y要大写,必须大写!!
             
               //  鼠标按下时给div挂事件
              dialogImg.bind("mousemove",function(es){
             
                //es.pageX,es.pageY:获取鼠标移动后的坐标
                var endx= es.pageX-downx+left;   //计算div的最终位置
                var endy=es.pageY-downy+top;
             
                //带上单位
                dialogImg.css("left",endx+"px").css("top",endy+"px")  
              });  
             })
               
             
              dialogImg.mouseup(function(){
                //鼠标弹起时给div取消事件
                dialogImg.unbind("mousemove")
              })

        }

                    
            
            $(function () {

                var id = window.parent.Xrm.Page.data.entity.getId(); //这种方法可以获取表单中的很多信息,包括id
             
                XrmServiceToolkit.Rest.RetrieveMultiple(
                "AnnotationSet",              "?$select=AnnotationId,Subject,NoteText,MimeType,FileName,FileSize,IsDocument,CreatedOn,CreatedBy,ModifiedOn,ModifiedBy&$filter=ObjectId/Id eq guid‘" + id + "‘&$orderby=CreatedOn asc",
                function (results) {
                    for (var i = 0; i < results.length; i++) {
                        var tr = $("<tr></tr>");
                        tr.appendTo($("#notestable tbody"));
                        var td = $("<td>" + (i+1) + "</td>");
                        td.appendTo(tr);
                        td = $("<td>" + (results[i].Subject == null ? "" : results[i].Subject) + "</td>");
                        td.appendTo(tr);
                     
                     
                        td = $("<td>" + results[i].CreatedBy.Name + "</td>");
                        td.appendTo(tr);
                        td = $("<td>" + results[i].CreatedOn.format(‘yyyy-MM-ddThh:mm:ssZ‘) + "</td>");
                        td.appendTo(tr);
                        td = $("<td>" + results[i].ModifiedBy.Name + "</td>");
                        td.appendTo(tr);
                        td = $("<td>" + results[i].ModifiedOn.format(‘yyyy-MM-ddThh:mm:ssZ‘) + "</td>");
                        td.appendTo(tr);
                        td = $("<td>" + (results[i].IsDocument ? "是" : "否") + "</td>");
                        td.appendTo(tr);
                        td = $("<td>" + (results[i].FileName == null ? "" : ("<a href=‘#‘ data-annotationid=‘" + results[i].AnnotationId + "‘>" + results[i].FileName + "</a>") + "</td>"));
                        td.find("a").click(function() {
                            ShowAttachmentByNoteId($(this).attr("data-annotationid"));
                        });
                        td.appendTo(tr);
                        td = $("<td>" + (results[i].FileSize == null ? "" : Math.round((results[i].FileSize)/1024)) + "</td>");
                        td.appendTo(tr);
                    }
                },
                function (error) {
                    alert(error.message);
                },
                function () {
                },
                true
                );
                $("#dialogclosebtn").click(function (e) {
                    HideDialog();
                    e.preventDefault();
                });
            });
        </script> 
 </head> 
 <body> 
  <table id="notestable"> 
   <thead> 
    <tr> 
     <th>序号</th> 
     <th>注释标题</th> 
     <th>创建人</th> 
     <th>创建时间</th> 
     <th>修改人</th> 
     <th>修改时间</th> 
     <th>是否包含附件</th> 
     <th>附件名称</th> 
     <th>附件大小(KB)</th> 
    </tr> 
   </thead> 
   <tbody> 
   </tbody> 
  </table> 
 
 </body>
</html>

     

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标WEB前端jQuery频道!

本文由 @沉沙 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程