o2oa api: x-游戏厅捕鱼达人

source

mwf.xdesktop.requireapp("process.xform", "$input", null, false);
/** @class calendar 日期组件。
 * @o2cn 日期选择
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var field = this.form.get("fieldid"); //获取组件对象
 * //方法2
 * var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
 * @extends mwf.xapplication.process.xform.$input
 * @o2category formcomponents
 * @o2range {process|cms|portal}
 * @hideconstructor
 */
mwf.xapplication.process.xform.calendar = mwf.appcalendar =  new class(
    /** @lends mwf.xapplication.process.xform.calendar# */
{
	implements: [events],
	extends: mwf.app$input,
	iconstyle: "calendaricon",
    options: {
        /**
         * 日期选择完成时触发.
         * @event mwf.xapplication.process.xform.calendar#complete
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 日期选择器上点清空时触发.
         * @event mwf.xapplication.process.xform.calendar#clear
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 值改变时触发.
         * @event mwf.xapplication.process.xform.calendar#change
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 显示日期选择器时触发.
         * @event mwf.xapplication.process.xform.calendar#show
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 隐藏日期选择器时触发.
         * @event mwf.xapplication.process.xform.calendar#hide
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        "moduleevents": ["queryload","postload","load","complete", "clear", "change","show","hide"]
    },
    _loadnode: function(){
        if (this.isreadonly()){
            this._loadnoderead();
        }else{
            this._loadnodeedit();
            var input = this.node.getfirst();
            input.set("readonly", true);
        }
    },
    setdescriptionevent: function(){
        if (this.descriptionnode){
            this.descriptionnode.addevents({
                "mousedown": function(){
                    this.descriptionnode.setstyle("display", "none");
                    //this.clickselect();
                }.bind(this)
            });
        }
    },
    _getvalueag: function(value,isdate){
        if (value && value.isag){
            return value.then(function(v){
                this._getvalueag(v, isdate);
            }.bind(this), function(){});
        }else{
            var d = (!!value) ? date.parse(value) : "";
            if (isdate){
                return d || null;
            }else{
                return (d) ? d.format(this.json.format) : "";
            }
        }
    },
    getvalue: function(isdate){
        if (this.modulevalueag) return this.modulevalueag;
        var value = this._getbusinessdata();
        if( value && !isdate)return value;
        if (!value) value = this._computevalue();
        if (value && value.then) return value;
        var d = (!!value) ? date.parse(value) : "";
        if (isdate){
            return d || null;
        }else{
            //if (d) value = date.parse(value).format(this.json.format);
            return (d) ? d.format(this.json.format) : "";
        }
        return value || "";
    },
    getvaluestr : function(){
        var value = this._getbusinessdata();
        if (!value) value = this._computevalue();
        return value;
    },
    __setvalue: function(value){
        var v;
        if( typeof( value ) === "date" ){
            v = (value) ? ( date.parse(value)).format(this.json.format) : "";
        }else{
            v = value;
        }
        this._setbusinessdata(value);
        if (this.node.getfirst()) this.node.getfirst().set("value", v || "");
        if (this.isreadonly()) this.node.set("text", v);
        this.modulevalueag = null;
        this.fieldmoduleloaded = true;
        return value;
    },
    _beforereloaded: function(){
        this.calendar = null;
    },
	clickselect: function(){
        var _self = this;
        if (!this.calendar){
            mwf.require("mwf.widget.calendar", function(){
                var defaultview = "day";
                if( this.json.selecttype === "month" )defaultview = "month";
                if( this.json.selecttype === "year" )defaultview = "year";
                var options = {
                    "style": o2.session.ismobile ? "xform_mobile" : "xform",
                    "secondenable" : this.json.isselectsecond,
                    "timeselecttype" : this.json.timeselecttype,
                    "istime": (this.json.selecttype==="datetime" || this.json.selecttype==="time"),
                    "timeonly": (this.json.selecttype === "time"),
                    "monthonly" : (this.json.selecttype === "month"),
                    "yearonly" : (this.json.selecttype === "year"),
                    "defaultview" : defaultview,
                    //"target": this.form.node,
                    "target": o2.session.ismobile ? $(document.body) : this.form.app.content,
                    "format": this.json.format,
                    "oncomplate": function(formatedate, date){
                        this.validationmode();
                        if(this.validation()){
                            var v = this.getinputdata("change");
                            this._setbusinessdata(v);
                            //this._setenvironmentdata(v);
                        }
                        this.fireevent("complete");
                    }.bind(this),
                    "onchange": function(){
                        this._setbusinessdata(this.getinputdata("change"));
                        this.fireevent("change");
                    }.bind(this),
                    "onclear": function(){
                        this.validationmode();
                        if(this.validation()){
                            var v = this.getinputdata("change");
                            this._setbusinessdata(v);
                            //this._setenvironmentdata(v);
                        }
                        this.fireevent("clear");
                        if (!this.node.getfirst().get("value")) if (this.descriptionnode)  this.descriptionnode.setstyle("display", "block");
                    }.bind(this),
                    "onshow": function(){
                        if (_self.descriptionnode) _self.descriptionnode.setstyle("display", "none");
                        if( o2.session.ismobile ){
                            this.container.position({
                                relativeto: $(document.body),
                                position: 'leftcenter',
                                edge: 'leftcenter'
                                //offset : { y : -25 }
                            });
                        }else{
                            var parent = _self.node.getparent();
                            while( parent ){
                                var overflow = parent.getstyle("overflow");
                                var overflowy = parent.getstyle("overflow-y");
                                if(  overflow === "auto" || overflow === "scroll" || overflowy === "auto" || overflowy === "scroll" ){
                                    _self.scrollfun = function( e ){
                                        // if (this.container.position && (!layout || !layout.userlayout || !layout.userlayout.scale || layout.userlayout.scale===1) ){
                                            if( this.postx === "right" ){
                                                if( this.posty === "bottom" ){
                                                    this.container.position({
                                                        relativeto: this.node,
                                                        position: 'bottomright',
                                                        edge: 'upperright',
                                                        allownegative : true
                                                    });
                                                }else{
                                                    this.container.position({
                                                        relativeto: this.node,
                                                        position: 'upperright',
                                                        edge: 'bottomright',
                                                        allownegative : true
                                                    });
                                                }
                                            }else{
                                                if( this.posty === "bottom" ) {
                                                    this.container.position({
                                                        relativeto: this.node,
                                                        position: 'bottomleft',
                                                        edge: 'upperleft',
                                                        allownegative: true
                                                    });
                                                }else{
                                                    this.container.position({
                                                        relativeto: this.node,
                                                        position: 'upperleft',
                                                        edge: 'bottomleft',
                                                        allownegative: true
                                                    });
                                                }
                                            }
                                        // }else{
                                        //     var p = this.node.getposition(this.options.target || null);
                                        //     var size = this.node.getsize();
                                        //     var containersize = this.container.getsize();
                                        //     var bodysize = (this.options.target) ? this.options.target.getsize() : $(document.body).getsize(); //$(document.body).getsize();
                                        //
                                        //     bodysize.x = bodysize.x * layout.userlayout.scale;
                                        //     bodysize.y = bodysize.y * layout.userlayout.scale;
                                        //
                                        //     var left = p.x;
                                        //     left = left * layout.userlayout.scale;
                                        //     if ((left   containersize.x   40) > bodysize.x){
                                        //         left = bodysize.x - containersize.x - 40;
                                        //     }
                                        //
                                        //     var top = p.y size.y 2;
                                        //     top = top * layout.userlayout.scale;
                                        //     if( top   containersize.y > bodysize.y ){
                                        //         top = bodysize.y - containersize.y ;
                                        //     }
                                        //
                                        //     this.container.setstyle("top", top);
                                        //     this.container.setstyle("left", left);
                                        // }
                                    }.bind(this);
                                    _self.scrollparentnode = parent;
                                    parent.addevent( "scroll", _self.scrollfun );
                                    parent = null;
                                }else{
                                    parent = parent.getparent();
                                }
                            }
                        }
                        _self.fireevent("show");
                    },
                    "onhide": function(){
                        if (!this.node.getfirst().get("value")) if (this.descriptionnode)  this.descriptionnode.setstyle("display", "block");
                        if( _self.scrollparentnode && _self.scrollfun ){
                            _self.scrollparentnode.removeevent("scroll", _self.scrollfun);
                        }
                        _self.fireevent("hide");
                    }.bind(this)
                };
                options.basedate = this.getbasedate();
                this.setrange( options );
                /**
                 * @summary 日期弹出选择界面,只读情况下无此成员.
                 * @member {mwf.widget.calendar}
                 * @example
                 * var calendar = this.form.get("fieldid").calendar; //获取组件
                 * if(calendar)calendar.show(); //弹出选择组件
                 */
                this.calendar = new mwf.widget.calendar(this.node.getfirst(), options);
                if( this.form.json && this.form.json.canlendarstyle && typeof( this.form.json.canlendarstyle.zindex ) !== "null" && typeof( this.form.json.canlendarstyle.zindex ) !== "undefined" ){
                    this.calendar.container.setstyle("z-index", this.form.json.canlendarstyle.zindex );
                }
                this.calendar.show();
            }.bind(this));
        }else{
            var options = {};
            options.basedate = this.getbasedate();
            this.calendar.setoptions(options);
            //this.calendar.show();
            this.node.getfirst().focus();
        }
	},
    getbasedate : function(){
        var d;
        var value = this.getvalue(true);
        if( value && value.gettime() > 10000 ){
            d = value;
        }else{
            var ud = date.parse( this.unformatdate( this.getvaluestr() ) );
            if( ud && ud.gettime() > 10000 ){
                d = ud;
            }else{
                d = new date();
            }
        }
        return d;
    },
    setrange: function( options ){
        var r;
        switch ( this.json.rangetype ) {
            case "datetime":
                if (this.json.datetimerangescript && this.json.datetimerangescript.code) {
                    r = this.form.macro.fire(this.json.datetimerangescript.code, this);
                    if (typeof(r) === "array") options.datetimerange = r;
                }
                break;
            case "dateandtime":
                if (this.json.daterangescript && this.json.daterangescript.code) {
                    r = this.form.macro.fire(this.json.daterangescript.code, this);
                    if (typeof(r) === "array") options.daterange = r;
                }
                if (this.json.timerangescript && this.json.timerangescript.code) {
                    r = this.form.macro.fire(this.json.timerangescript.code, this);
                    if (typeof(r) === "array") options.timerange = r;
                }
                break;
            case "other":
                if (this.json.enabledate && this.json.enabledate.code) {
                    options.enabledate = function (date) {
                        var d = this.getpuredate( date );
                        return this.form.macro.fire(this.json.enabledate.code, this, {date: d});
                    }.bind(this);
                }
                if (this.json.enablehours && this.json.enablehours.code) {
                    options.enablehours = function (date) {
                        var d = this.getpuredate( date );
                        return this.form.macro.fire(this.json.enablehours.code, this, {date: d});
                    }.bind(this);
                }
                if (this.json.enableminutes && this.json.enableminutes.code) {
                    options.enableminutes = function (date, hour) {
                        var d = this.getpuredate( date );
                        return this.form.macro.fire(this.json.enableminutes.code, this, {date: d, hour: hour.toint()});
                    }.bind(this);
                }
                if (this.json.enableseconds && this.json.enableseconds.code) {
                    options.enableseconds = function (date, hour, minute) {
                        var d = this.getpuredate( date );
                        return this.form.macro.fire(this.json.enableseconds.code, this, {date: d, hour: hour.toint(), minute: minute.toint()});
                    }.bind(this);
                }
                break;
        }
    },
    getpuredate: function (date) {
        var d;
        switch (typeof(date)) {
            case "string": d = date.parse(date); break;
            case "date": d = date.clone(); break;
            default: return null;
        }
        return d.cleartime();
    },
    unformatdate : function( datestr ){
        var formatstr = this.json.format;
        var matcharr = [ "%y", "%m", "%d", "%h", "%m", "%s", "%z", "%z" ];
        var lengtharr = [ 4, 2, 2, 2, 2, 2, 5, 3];
        var indexarr = [ formatstr.indexof("%y"), formatstr.indexof("%m"), formatstr.indexof("%d"), formatstr.indexof("%h"), formatstr.indexof("%m"), formatstr.indexof("%s"), formatstr.indexof("%z"), formatstr.indexof("%z") ];
        var resultarr = [ null, null, null, null, null, null, null, null ];
        for( var i=0; i n ){
                    leftlength  = lengtharr[k];
                    leftunitlength  = matcharr[k].length;
                }
            });
            resultarr[i] = datestr.substr( indexarr[i] - leftunitlength   leftlength, lengtharr[i] );
        }
        var now = new date();
        for( var i=0; i < resultarr.length; i   ){
            if( !resultarr[i] ){
                switch ( matcharr[i] ){
                    case "%y":
                    case "%m":
                    case "%d":
                        resultarr[i] = now.format( matcharr[i] );
                        break;
                    case "%h":
                    case "%m":
                    case "%s":
                        resultarr[i] = "00";
                        break;
                    case "%z":
                    case "%z":
                    default:
                        break;
                }
            }
        }
        return resultarr[0]   "-"   resultarr[1]   "-"   resultarr[2]   " "   resultarr[3] ":" resultarr[4] ":" resultarr[5];
    },
    getexceldata: function(){
        return this.getdata();
    },
    setexceldata: function(d){
        var value = d.replace(/
/g,""); //换行符
        this.exceldata = value;
        var json = this.json;
        if( value && (new date(value).isvalid()) ){
            var format;
            if (!json.format){
                if (json.selecttype==="datetime" || json.selecttype==="time"){
                    format = (json.selecttype === "time") ? "%h:%m" : (locale.get("date").shortdate   " "   "%h:%m")
                }else{
                    format = locale.get("date").shortdate;
                }
            }else{
                format = json.format;
            }
            value = date.parse( value ).format( format );
            this.setdata(value, true);
        }
    }
});
网站地图