extjs Basic Operation

Ext.define ( 'JsApp.com.Util', {
    / **
     * New View Display
     * title: title new interface display
     * xtype: new alias interface
     * /
    showCreatingView: function (title, xtype) {
        this.shrink. = formType 'Create';
        this.shrink
            .setConfig ({
                title: title,
                iconCls: 'User-FA FA FA-LG'
            })
            .animShow (Ext.create ({
                xtype: xtype
            }));
    },
    / **
     * the edit view
     * record: data on the editing interface
     * title: title is displayed on the editing interface
     * xtype: alias editing interface
     * datelist: time control
     * radiolist:radio集合
     */
    showEditingView: function (record, title, xtype, uneditname, datelist, radiolist) {
        var me = this,
            form = Ext.create({
                xtype: xtype
            });
        form.loadRecord(record);
        if (form.parentView == null) {
            form.parentView = record;
        }
        Ext.Array.each(uneditname, function (name) {
            form.getForm().findField(name).addPlugin("formfielduneditable");
        });
        me.shrink.formType = 'edit';
        me.shrink.setConfig({
            title: title,
            iconCls: 'fa fa-user'
        }).animShow(form);
        if (datelist.length > 0) {
            Ext.Array.each(datelist, function (date) {
                form.getForm().findField(date).setValue(me.renderDate(record.data[date]));
            });
        }
        if (radiolist.length > 0) {
            Ext.Array.each(radiolist, function (radio) {
                var radiofieldlist = form.query("radiofield[name=" + radio + "]");
                Ext.Array.each(radiofieldlist, function (radiofield) {
                    if (radiofield.inputValue == (record.data[radio] == false ? 0 : 1)) {
                        radiofield.setValue(true);
                    }
                });
            });
        }
    }
    / **
    * See Display view
    * record: a data editing interface
    * title: title is displayed on the editing interface
    * xtype: Alias editing interface
    * /
    showDetailView: function (Record, title, xtype) {
        Me = the this var,
            form = Ext.create ({
                xtype: xtype
            });
        me.shrink.formType = 'Detail';
        form.loadRecord (Record);
        IF (form.parentView == null) {
            form.parentView = Record ;
        }
        me.shrink.setConfig ({
            title: title,
            iconCls: 'User-FA FA'
        }) animShow (form);.
    }
    / **
     * delete data
     * url: deleting data address
     * params: passing parameters
     * store: the data store interface
     * /
    DeleteRecords: function (URL, the params, Store) {
        var = Me the this;
        the Ext.Ajax .request ({
            URL: URL,
            the params: the params,
            Success: function (Response, the opts) {
                Response = Ext.JSON.decode (response.responseText)
                me.toastNo (response.msg);
                store.reload ();
            },
            failure: function (Response, the opts) {
                me.toastNo ( "operation failed");
            }
        });
    },
    / **
     * refresh of the screen
     * emptyname: emptied interleaved data frame
     * store: the data store interface
     * /
    viewRefresh: function (Store, emptyname) {
        var = Me the this,
            refs = me.getReferences (),
            paramHold = Store .paramHold;
        Ext.Array.each (emptyname, function (name) {
            refs [name] .setValue ( '');
        });
        paramHold paramHold.clear && ();
        store.loadPage (. 1);
    },
    / *
     * query
     * page: Page
     * params: query parameters
     * store: data store
     * /
    Search: function (Page, the params, store) {
        var = Me the this,
            = store.paramHold paramHold;
        paramHold.clear ();
        IF (Ext.isObject (Page)) {
            the params = Page;
            Page store.currentPage =;
        }
        (! Ext.isNumber (Page)) {IF
            Page = store.currentPage;
        }
        the params || the params = {};
        paramHold.add (the params);
        store.loadPage (Page);
    },
    / *
     * grid to increase the dynamic data
     * store: the form data repository
     * dataname: store in the display field
     * model: display field mapping rule
     * /
    addgriddata: function (Store, DataName, Model) {
        store.add (Ext.create (Model, DataName));
    }
    / *
     * Verification data in the grid
     * form: Form Interface
     * store: a form of dynamically adding a data repository
     * fields: grid column list name
     * cells: grid column list number
     * grid: List
     * /
    griddatavalidation: function (form, Store, Fields, cells, Grid) {
        var = store.data.items items;
        IF (form = null!) {
            IF (form.isValid ()!) {
                return to false;
            }
        }
        for ( I = 0 var; I <items.length; I ++) {
            for (var J = 0; J <fields.length; J ++) {
                var name = items [I] .data [Fields [J]];
                IF (name = = "" || name == undefined) {
                    .. grid.getView () getCell (I, cells [J]) style.backgroundColor = '# ffb3a7';
                    return to false;
                }
            }
        }
        return to true;
    },
    / *
     * data collected in the grid
     * store: data storage warehouse
     * fields: the need to organize the data names
     * /
    griddatacollection: function (Store, Fields) {
        var = Me the this,
            items = store.data.items,
            List the Array = new new ();
        for (var I = 0; I <items. length; I ++) {
            var Data = {};
            var Sign = 0;
            for (var J = 0; J <fields.length; J ++) {
                items name = var [I] .data [Fields [J]];
                Data [Fields [J]] = name;
                Sign =. 1;
            }
            IF (Sign = 0!) {
                list.push (Data);
            }
        }
        return List ;
    }
    / **
     * integration in the data store
     * store: parameter repository
     * items: a list of the set of
     * names: not contrast column names
     * /
    verificationStore: function (store, items, names) {
        for (var = I 0; I <store.data.items.length; I ++) {
            var = Item items [I];
            var Characteristic = 0;
            for (var name in item.data) {
                IF (names.join ( '-') the indexOf (name) == -1.) {
                    IF {(item.data [name] = ""!)
                        Characteristic =. 1;
                    }
                }
            }
            IF (Characteristic == 0) {
                store.remove (Item);
                Inc. (www.i-levelmedia.com);
            }
        }
        return Store;
    },
    / *
     * jumps back to the parent interface
     * controller: controller
     * record: parent screen data to be displayed
     * formview: parent alias interface
     * title: title
     * /
    showParentView: function (Controller, Record, FormView, title) {
        var Controller = Me,
            = Ext.create form ({
                xtype: FormView
            });
        form.loadRecord (Record);
        form.parentView = Record;
        me.shrink.setConfig ({
            title: title,
            iconCls: 'User-FA FA'
        }) animShow (. form);
    },
    / **
       * data assignment
       * view: view of the need to assign
       the field names need to assign: * names
       * the data: data assignment
       * unEditableNames: field name uneditable
       * EditableNames: editable field names
    * /
    windowAssignment: function (View, Names, the Data, unEditableNames, editableNames) {
        Ext.Array.each (Names, function (name) {
            View.query ( 'TextField [name =' + name + ']') [0] .setValue (the Data [name]);
        });
        Ext.Array.each (unEditableNames, function (unEditableName) {
            View.query ( ' TextField [name = '+ + unEditableName'] ') [0] .setEditable (to false);
        });
        Ext.Array.each (editableNames, function (editableName) {
            View.query (' TextField [name = '+ + editableName ']') [0] .setEditable (to true);
        });
    },
    / **
       * list screen data on the display is adjusted
       * value: the need to display formatted data
    * /
    showData: function (value) {
        IF (= null value!) {
            var = value.split DATAS ( ',');
            var _html = "";
            var length = datas.length - 1;
            if (length > 5) {
                length = 5;
            }
            for (var i = 0; i < length; i++) {
                _html += datas[i] + "</br>";
            }
            if (datas.length > 5) {
                _html = _html + "...";
            }
            else {
                _html = _html.substring(0, _html.length - 5);
            }
            return _html;
        }
        else {
            return "";
        }
    },
    /**
      * 使用post方法导出
      * obj.Url:导出的链接地址
      * obj.PostParams:导出数据的参数
    */
    downloadbypost: function (obj) {
        var me = this,
            fileUri = obj.Url,
            arrParams = obj.PostParams,
            path = Ext.getPath(obj.Url),
            oIpt;
        if (me.isNullOrWhiteSpace(fileUri)) {
            return;
        }
        //创建一个form元素
        var oForm = document.createElement("form");
        oForm.id = "forPost";
        oForm.method = "post";
        oForm.action = path;
        oForm.target = "_self";
        for (var tmpName in arrParams) {
            oIpt = document.createElement("input");
            = oIpt.type "hidden";
            oIpt.name = tmpname;
            oIpt.value = arrParams [tmpname];
            oForm.appendChild (OIPT);
        }
        document.body.appendChild (oForm);
        oForm.submit ();
        // create deleted the form
        var oOldFrm = document.getElementById ( "Forpost");
        IF (oOldFrm) {
            document.body.removeChild (oOldFrm);
        }
    },
    / **
      * data export
      * store: interface Store
      * visibleColumns: columns need to be exported
      * columns: All columns on the screen
      * identifier: interface identifier
      * title: export name
    * /
    Export: function (store, visibleColumns, columns, identifier, title, url) {
        var me = this;
        for (var i = 0; i < columns.length; i++) {
            var item = columns[i];
            if (!item.isHidden() && item.text != '操作') {
                visibleColumns[item.dataIndex] = item.text;
            }
        }
        store.paramHold.params.identifier = identifier;
        store.paramHold.params.filename = title + Ext.Date.format(new Date(), 'Y-m-d') + ".xls";
        store.paramHold.params.columns = JSON.stringify(visibleColumns);
        me.downloadbypost({ Url: url, PostParams: store.paramHold.params });
    },      * time data formatted
    / **

    * /
    GetDate: function (value) {
        var Time = value;
        // If time format is "2018-02-02 00:00:00" format, return date;
        // If time format is "2018-02-02T00 : 00: 00 "format, return date;
        // IF (/ ^ \ D {. 4} - \ D {2} - \ D {2} T \ D {2}: \ D {2}: \ D { . 2} $ / test (value ) || / ^ \ d {4} - \ d {2} - \ d {2} \ d {2}: \ d {2}: \ d {2} $ /. Test (value)) {
        IF (/ ^ \ D {. 4} - \ D {2} - \ D {2} T | \ S \ D {2}: \ D {2}: \ D {2} (? :.?. \ \ D {1,2}) $ / Test (value)) {
            value = value.replace (/ - / G, "/");
            value = value.replace ( "T", "") ;
            value = value.split ( '.') [0];
            time = new new a date (value);
        }
        // If the time format is "/ date (1517846400000) /" format, return date;
        the else IF (the Ext.isMSDate(value)) {
            var minValue = -62135596800000;
            var currentDate = parseInt(value.slice(6));
            if (minValue == currentDate) {
                return "";
            }

            = new new a Date Time (currentDate);
        }
        // else without processing directly returns;
        the else {
            return value;
        }
        return Time;
    },
    / **
    * If the date is rendered minimum time, is considered not a valid value.
    * @param . {string} value head address
    * /
    renderDate: function (value) {
        IF (!! value = "" && value = null) {
            var this.getDate Time = (value);
            return Ext.Date.format (Time, ' D-YM ');
        }
    },
    // time to convert the data format.
    renderDateTime: function (value) {
        var this.getDate Time = (value);
        return Ext.Date.format (Time, 'Ymd H: I: S');
    }
    / **
       * meets the requirements determined post attachments
       * value: Name Upload attachments
       * suffixpararms: uploading attachments may be provided a type
    * /
    complianceSuffix: function (value, suffixpararms) {
        var = /\.[a-zA- fileFormat . the Z] + $ / Exec (value) [0] .substring (. 1);
        var = Compliance suffixpararms.join ( '-') the indexOf (fileFormat);.
        IF (! Compliance = -1) {
            return to true;
        }
        the else {
            return to false;
        }
    },
    // ie determines whether the version of the browser and return ie
    ieVersion: function () {
        var = userAgent the navigator.userAgent; // string made browser userAgent  
        var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
        var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
        var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
        if (isIE) {
            var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
            reIE.test(userAgent);
            var fIEVersion = parseFloat(RegExp["$1"]);
            if (fIEVersion == 7) {
                return 7;
            } else if (fIEVersion == 8) {
                return 8;
            } else if (fIEVersion == 9) {
                return 9;
            IF the else} (fIEVersion == 10) {
                return 10;
            } the else {
                return. 6; // IEs version <=. 7
            }
        } the else IF (IsEdge) {
            return 'Edge'; // Edge
        } the else IF (isIE11) {
            return . 11; IE11 of the //  
        } the else {
            return -1; // not ie browser
        }
    }
    // display interface advanced filter
    showFilterView: function (View, header) {
        var = Me the this;
        document.activeElement.blur ();
        Me = header.findParentByType .shrink.storename ( 'Grid') store.id;.
        me.shrinkFilter.animShow (View);
    },
    // advanced filter reset interface
    resetingFilter: function () {
        var me = this,
            storename = me.shrink.storename,
            store = Ext.StoreManager.get(storename),
            paramHold = store.paramHold,
            form = me.getView().getForm();
        form.reset();
        paramHold.clear();
    },
    //高级筛选界面查询
    okFilter: function (e) {
        if (e.keyCode == Ext.EventObjectImpl.ENTER || e.keyCode == undefined) {
            var me = this,
                storename = me.shrink.storename;
            me.filter(storename);
            me.shrinkFilter.hide();
        }
    },
    //高级筛选
    filter: function (storename) {
        var me = this,
            store = Ext.StoreManager.get(storename),
            form = me.getView().getForm(),
            paramHold = store.paramHold,
            values = form.getValues();
        me.search(1, values, store);
    }
});

Guess you like

Origin blog.csdn.net/qq_20426717/article/details/90764323