Js通用写法

String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {  
     if (!RegExp.prototype.isPrototypeOf(reallyDo)) {  
         return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")),                                 replaceWith);  
     } else {  
         return this.replace(reallyDo, replaceWith);  
     }  
} 
$(function() {
    // 初始化
    medicalDocument.addEvents();
    medical_document.init();
});
var medical_document = {
    init : function() {
        this.addEvents();
        this.addValidate();
    },
    /**
     * 事件注册
     */
    addEvents : function() {
        
    },
    /**
     * 保存数据
     * 
     * @param callback
     */
    save : function(callback) {
    	var selectTemplate = $("#select_template").val();
    	if(isEmpty(selectTemplate)){
    		showWarn("请选择医疗文书模板!");
    		return false;
    	}
        if ($("#medialDocumentForm").valid()) {
        	$("#content").val(medicalDocument.ke.html());
            $.ajax({
                url : ctx + "/medicalDocument/save.shtml",
                data : $("#medialDocumentForm").serialize(),
                type : "post",
                dateType : "json",
                success : function(result) {
                    if (result.status == 1) {
                        showTips("保存成功");
                        if (!isEmpty(callback)) {
                            callback();
                        }
                    } else {
                        showWarn(result.error);
                    }
                }
            });
        }
    },
    /**
     * 校验数据是否有效
     * 
     * @param num
     * @param min
     * @param max
     */
    checkNum : function(num, min, max) {
        var flag = true;
        if (isNaN(num)) {
            return false;
        }
        if (!isEmpty(min)) {
            flag = Number(num) >= min;
        }
        if (flag && !isEmpty(max)) {
            flag = Number(max) <= max;
        }
        return flag;
    },
    addValidate : function() {
        $('#medialDocumentForm').validate({
            // 校验字段
            rules : {
                recordDateShow : {
                    required : [ "测量日期" ]
                },
                weight : {
                    number : [ "体重" ],
                    customRange : [ 0.01, 999, "体重" ]
                }
            },
            errorPlacement : function(error, element) {
                var obj = getValidateErrorDisplayEl($(element));
                $(error).css("display", "block");
                obj.find("[data-error]").append(error);
            }
        });
    }
};
//初始化编辑插件
var medicalDocument = {
	    dataResult : "",// 初始化模板值
	    ke : "", // 文本编辑器新增病程记录时用到
	    dke : "",// 文本编辑器与上面一个不是同一个。修改模板和新增模板时用到
	    /** 获取病程记录模板信息 */
	    getTemp : function() {
	    	var selectTemplate = $("#select_template").val();
	    	if(!isEmpty(selectTemplate)){
	    		$.ajax({
		            url : ctx + "/medicalDocument/template/getTemplate.shtml",
		            type : "post",
		            data : {
	                    id : selectTemplate
		            },
		            dataType : "json",
		            success : function(data) {
		                if (data.status == 1) {
		                	medicalDocument.ke.html(data.context.content);
		                }
		            }
		        });
	    	}
	    },
	    /** 根据模板归属获取对应的模板值 */
	    changeTemplate : function(obj) {
	        medicalDocument.getTemp();
	    },
	    /** 初始化 */
	    addEvents : function() {
	        var editorContentInput = $('#editorContentText', window.parent.document).val();
	        // 初始化一些元素的高度
	        $("#wardRoundDZBL").hide();
	        // 初始化文本编辑器
	        KindEditor.ready(function(K) {
	            medicalDocument.ke = K.create('#editorContent', {
	                items : [ 'source', '|', 'undo', 'redo', '|', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
	                        'insertorderedlist', 'insertunorderedlist', '|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor',
	                        'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'fullscreen', 'preview', 'print' ],
	                        afterCreate : function () {
	                        	// ios 下编辑器无法滑动需要在外层追加一个div
	                			this.sync();
	                	        	var u = navigator.userAgent; 
	                	        	var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
	                	        	if(isiOS){
	                	        		$('.ke-edit').css('-webkit-overflow-scrolling','touch');
	                	        		$('.ke-edit').css('overflow-y','scroll');
	                	        	}
	                        }

	            });
	            if (!isEmpty(editorContentInput)) {
	                medicalDocument.ke.html(editorContentInput);
	            }
	            medicalDocument.ke.toolbar.disableAll(0);
	            medicalDocument.ke.edit.design(1);
	            medicalDocument.ke.toolbar.unselect("source");
	            medicalDocument.dke = K.create('#tContent', {
	                minHeight : 300,
	                items : [ 'source', '|', 'undo', 'redo', '|', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
	                        'insertorderedlist', 'insertunorderedlist', '|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor',
	                        'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'fullscreen', 'preview', 'print' ]
	            });
	            medicalDocument.dke.toolbar.disableAll(0);
	            medicalDocument.dke.edit.design(1);
	            medicalDocument.dke.toolbar.unselect("source");
	        });
	    },
	    /** 返回 */
	    cancel : function() {
	        if (existsFunction("parent.removeActiveTab")) {// 如果父节点存在removeActiveTab方法
	            // 删除tab
	            parent.removeActiveTab();
	        } else {
	            goBack();
	        }
	    }
	}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值