captureSettingsCommon.js 6.31 KB
// 初始化时间段选择框
$().ready(function (params) {
    //时间选择控件
    $(".timeSpans").click(showTimeSelector).focus(onTimeSelectorFocus);
    $(".timeSelectorAdd").click(addTimePicker);//添加空的时间段选择框
    $(".timeSelectorSave").click(saveTimeSpans);//保存选择的时间段
    $(".timeSelector").click(function (e) {
        e.stopPropagation();
    });
    $(document).click(function () {
        saveTimeSpan(null);
    });
});

//不让时间对话框获取焦点
function onTimeSelectorFocus(event) {
    this.blur();
}

//显示时间段选择窗口
function showTimeSelector(event) {
    event.stopPropagation();
    if (showedDatepicker) {
        saveTimeSpan(null);
    }
    //保存当前时间控件
    showedDatepicker = $(event.currentTarget).next().find(".timeSpanContainer");

    var timeValue = event.currentTarget.value;//获取已选择的时间段
    var timeSpanArray = timeValue.split(";");
    var htmlTagsArray = new Array();
    var tagId1, tagId2;
    var timePair, timeStart, timeEnd;
    for (var i = 0; i < timeSpanArray.length; i++) {
        tagId1 = "s" + i;
        tagId2 = "e" + i;
        timePair = $.trim(timeSpanArray[i]).split('-');
        //如果时间段不合法(开始,结束时间缺少),直接跳过该值
        if (timePair.length != 2) {
            continue;
        }
        htmlTagsArray.push("<li><input type='text' id='" + tagId1 + "' class='Wdate timePicker' value='" + timePair[0] + "' onclick=\"WdatePicker({dateFmt:'HH:mm', maxDate: '#F{$dp.$D(\\'" + tagId2 + "\\')||\\'23:59:59\\'}'})\" />&nbsp;-&nbsp;");
        htmlTagsArray.push("<input type='text' id='" + tagId2 + "' class='Wdate timePicker' value='" + timePair[1] + "' onclick=\"WdatePicker({dateFmt:'HH:mm', minDate: '#F{$dp.$D(\\'" + tagId1 + "\\')||\\'00:00:00\\'}'})\" />");
        htmlTagsArray.push("<a href='#' class='btnDelete' /></a></li>");
    }
    //显示控件(先清空,再添加新的时间选择控件)
    var timeSelector = $(event.currentTarget).parent().find(".timeSelector");
    //先解绑删除按钮事件
    $(".btnDelete").unbind("click");
    timeSelector.find(".timeSpanContainer").html("").html(htmlTagsArray.join(""));
    //显示时间段选择组件的位置
    timeSelector.css("top", 27).css("left", 4).show();
    timeSelector.show();
    //绑定删除时间段的方法
    $(".btnDelete").bind("click", deleteTimePicker);
    //判断是否显示添加时间段按钮
    if (htmlTagsArray.length >= 10) {
        timeSelector.find(".timeSelectorAdd").hide();
    } else {
        timeSelector.find(".timeSelectorAdd").show();
    }
}

//添加空的时间段选择控件
function addTimePicker(event) {
    event.stopPropagation();
    var timeSpanContainer = $(event.currentTarget).parent().find(".timeSpanContainer");
    var timePickerLength = timeSpanContainer.find("li").length;

    var newTimePickerArray = new Array();
    var tagId1 = "s" + (timePickerLength - 1);
    var tagId2 = "e" + (timePickerLength - 1);
    newTimePickerArray.push("<li><input type='text' id='" + tagId1 + "' class='Wdate timePicker'  onclick=\"WdatePicker({dateFmt:'HH:mm', maxDate: '#F{$dp.$D(\\'" + tagId2 + "\\')||\\'23:59:59\\'}'})\" />&nbsp;-&nbsp;");
    newTimePickerArray.push("<input type='text' id='" + tagId2 + "' class='Wdate timePicker' onclick=\"WdatePicker({dateFmt:'HH:mm', minDate: '#F{$dp.$D(\\'" + tagId1 + "\\')||\\'00:00:00\\'}'})\" />");
    newTimePickerArray.push("<a href='#' class='btnDelete' /></a></li>");
    timeSpanContainer.append(newTimePickerArray.join(""));
    //添加删除的事件绑定
    $(".btnDelete").bind("click", deleteTimePicker);

    if (timePickerLength + 1 >= 10) {
        timeSpanContainer.parent().find(".timeSelectorAdd").hide();
    }
}

//删除之前的时间控件
function deleteTimePicker(event) {
    event.stopPropagation();
    var liContainer = $(event.currentTarget).parent();
    var timespansContainer = liContainer.parents(".timeSelector");
    //先解绑删除按钮的事件
    $(event.currentTarget).unbind();
    liContainer.remove();
    //检测时间段控件的个数
    var timeSpansCount = timespansContainer.find("li").length;
    if (timeSpansCount < 10) {
        timespansContainer.parent().find(".timeSelectorAdd").show();
    }
}

//保存已修改的时间段的值
function saveTimeSpans(event) {
    var timeSpanContainer = $(event.currentTarget).parent().find(".timeSpanContainer");
    saveTimeSpan(timeSpanContainer);
}

function saveTimeSpan(container) {
    if (!container) {
        container = showedDatepicker;
    }
    if (!container) {
        return;
    }
    var timePickerPairsContainer = container.find("li");
    var timeSpanValueArray = new Array();
    var timePickers;
    for (var i = 0; i < timePickerPairsContainer.length; i++) {
        var timePickerPairs = $(timePickerPairsContainer[i]).find(".Wdate");
        if (timePickerPairs.length == 2 && timePickerPairs[0].value && timePickerPairs[1].value) {
            timeSpanValueArray.push(timePickerPairs[0].value + "-" + timePickerPairs[1].value);
        }
    }
    //保存到原始
    var valueContainer = container.parent().siblings("input");
    valueContainer.val(timeSpanValueArray.join(";"));
    //关闭
    container.parent().hide();
    showedDatepicker = null;
}

//------------------------------------  roi ocx -----------------------------
function ROIOcxController(ocxObj) {
    var ocxObject = ocxObj;

    this.showPage = function () {
        showOcxPage();
    };
    this.showDialog = function () {
        showOcxDialog();
    };
    this.loadUrlPage = function (imgUrl) {
        loadOcxUrlPage(imgUrl);
    };
    this.loadUrlXml = function (imgUrl) {
        loadOcxUrlXml(imgUrl);
    };

    function showOcxPage() {
        ocxObject.showRoiPage();
    };

    function showOcxDialog() {
        ocxObject.AboutBox();
    };

    function loadOcxUrlPage(imgUrl) {
        var err = ocxObject.loadRoiPictureFromUrl(imgUrl);
        if (err != 0) {
            //alert("loadRoiPictureFromUrl: err = " + err);
        }
    };

    function loadOcxUrlXml(imgUrl) {
        var err = ocxObject.loadRoiXmlFromUrl(imgUrl);
        if (err != 0) {
            //alert("loadRoiXmlFromXml: err = " + err);
        }
    };
}
// 显示Ocx
function showOcxObj() {
    $("#roiOcxObject").show();
}
// 隐藏Ocx
function hideOcxObj() {
    $("#roiOcxObject").hide();
}