operations.activitytemplate.Edit.js 2.77 KB
webpackJsonp([77],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by ty on 2016/7/4.
	 * 活动模板编辑
	 */

	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var Template = {},
	    type = $("#wrap-content").attr("role"),
	    url = $("#wrap-content").attr("url"),
	    id = $("#wrap-content").data("id");

	var edit = new common.edit2("#wrap-content");

	if(type == "edit") {
	    common.util.__ajax({
	        async: false,
	        url: "/activityTemplate/getTemplate",
	        data: {id: id}
	    }, function (res) {
	        Template = res.data;
	    },true);
	}

	$("#wrap-content").html(common.util.__template2($("#template").html(), Template));
	$("#uploadBox").ajaxfileupload({
	    'action': '/ajax/upload',
	    'params': {
	        bucket: "yhb-img01",
	        __type: "upload"
	    },
	    onComplete: function (response) {
	        if (response.status && response.code == 200) {
	            if(response.data){
	                common.util.__tip(response.message, "success");
	                $("#image").val(response.data);
	                Template.image = response.data;
	            }
	        } else {
	            common.util.__tip(response.message);
	        }
	    }
	});

	$(document).on("click", "#addUrl", function () {
	    var urlIndex = '","url":"';
	    var val = $("#url").val();
	    var action = val.substring('{"action":"'.length, val.indexOf(urlIndex));
	    console.log(action);
	    var url = val.substring(val.indexOf(urlIndex) + urlIndex.length, val.length - 2);
	    common.dialog.confirm("添加链接", common.util.__template2($("#template2").html(), {action: action, url: url}), function () {
	        var url = JSON.stringify({
	            action: $("#goTo").val(),
	            url: $("#goToUrl").val()
	        });
	        $("#url").val(url);
	        Template.url = url;
	    });
	    new common.edit2("#action-row").init();
	});

	//绑定更改时间
	$(document).on("change", ".observe", function () {
	    Template[$(this).data("field")] = $(this).val();
	});

	//保存
	$(document).on("click", "#save_btn", function () {
	    if(edit.validate()) {
	        if(checkShareId()){
	            common.util.__ajax({
	                url: url,
	                data: Template
	            }, function () {
	                setTimeout(function () {
	                    location.href = "/operations/activitytemplate/index";
	                }, 600);
	            });
	        }
	    }
	});

	function checkShareId() {
	    var value = $('input[name="share_id"]').val();
	    if(isNaN(value)){
	        common.util.__tip("分享ID必须为数字!");
	        return false;
	    }else{
	        return true;
	    }
	}

	$(document).on("click", "#chooseFile", function () {
	    $("#uploadBox").click();
	});

/***/ }
]);