var plugin = require('topsin.gengui');
var _ = require("lodash")
var gui = plugin.newGui(plugin.__dirname);

function gen() {
    this.PAUSE = function() {
        console.log("pause");
    }
}

gui.setLang("zhtw"); // zhcn, zhtw, en


r = gui.showForm({
    title: "注册账号",
    size: [600, 400],
    ui: function func(self) {
        return [{
            type: 'ScrollArea',
            property: {
                widget_resizable: true,
                frame_shape: 'NoFrame',
                align: 'Top'
            },
            child: {
                type: 'VBoxLayout',
                property: {
                    margin: 2,
                    spacing: 20,
                    align: 'Top'
                },
                pack: {
                    stretch: 0
                },
                child: [{
                    type: "FormGridLayout",
                    property: {
                        columns: 1,
                        label_alignment: 'Top | Right',
                        margin: 10,
                        spacing: 20
                    },
                    pack: {
                        stretch: 0
                    },
                    child: [
                        {
                            name: 'table',
                            type: 'TableView',
                            property: {},
                            initCallback: function (obj, self) {
                                obj.setDataKeyList(["id", "analysis_item", "analysis_result", "result", "standard", "remark"]);
                                obj.setHeaderItem(
                                    [
                                        {},
                                        { name: 'analysis_item', display: 'Analysis Item', resizeMode: 'ResizeToContents', displayRole: '$analysis_item' },
                                        { name: 'analysis_result', display: 'Analysis Result', resizeMode: 'ResizeToContents', displayRole: '$analysis_result' },
                                        { name: 'result', display: 'Result', resizeMode: 'ResizeToContents', displayRole: '$result' },
                                        { name: 'standard', display: 'Standard', resizeMode: 'ResizeToContents', displayRole: '$standard' },
                                        { name: 'remark', display: 'Remark', resizeMode: 'ResizeToContents', displayRole: '$remark', editRole: '$remark', flagsRole: 'ItemIsEditable|ItemIsEnabled|ItemIsSelectable' }
                                    ]
                                );
                                obj.setPrimaryKey("id");
                            },
                            setter: function (obj, value, self) {
                                if (value != null) {
                                    obj.loadData(value);
                                } else {
                                    obj.clearData();
                                }
                            },
                            getter: function (obj, self) {
                                print((Object.keys(obj)));
                                return obj.selectedRowDataMaps();
                                // return obj.allDataMap();
                            }
                        }
                    ]
                }]
            }
        }];
    },
    data: {
        table: [
            {
                "id": 1,
                "analysis_item": "test",
                "analysis_result": "test",
                "result": "test",
                "standard": "test",
                "remark": "test"
            },
            {
                "id": 2,
                "analysis_item": "test2",
                "analysis_result": "test2",
                "result": "test2",
                "standard": "test2",
                "remark": "test2"
            },
            {
                "id": 3,
                "analysis_item": "test3",
                "analysis_result": "test3",
                "result": "test3",
                "standard": "test3",
                "remark": "test3"
            }
        ]
    },
    includehide: false,
    buttons: [{
            stock: "ok",
            sensitive: true,
            command: function (data) {

            }
        },
        {
            stock: "cancel",
            sensitive: true,
            command: function (ddata) {

            }
        },
        {
            stock: "help",
            sensitive: true,
            command: function (data) {
                console.log(data);
            }
        }
    ],
    hook: function (data) {},
    gen: new gen()
});


console.log(r);