/*
 * File: app/view/main/mainmarketing/window/commonpopup/PopupTypeCardViewController.js
 *
 * This file was generated by Sencha Architect version 3.2.0.
 * http://www.sencha.com/products/architect/
 *
 * This file requires use of the Ext JS 5.1.x library, under independent license.
 * License of Sencha Architect does not include license for Ext JS 5.1.x. For more
 * details see http://www.sencha.com/license or contact license@sencha.com.
 *
 * This file will be auto-generated each and everytime you save your project.
 *
 * Do NOT hand edit this file.
 */

Ext.define('FrontHPApp.view.main.mainmarketing.window.commonpopup.PopupTypeCardViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.mainmainmarketingwindowcommonpopuppopuptypecard',

    onSaveClick: function(button, e, eOpts) {
        var me = this.getView(),
             form = me.down('form').getForm(),
             store = me.down('grid').getStore();
        if (form.isValid()) {
            Ext.MessageBox.confirm("Confirm", "คุณต้องการที่จะปรับปรุ่งข้อมูลใช่หรือไม่?", function (btn) {

                if (btn == 'yes') {

                    record = form.getValues();
                    console.log(record);

                    store.add(record);
                    //store.commitChanges();
                    store.sync();
                    //store.sync();

                    //store.commitChanges();

                    Ext.MessageBox.alert("Status", 'ปรับปรุ่งมูลเรียบร้อย');
                }

            }, this);
        }//end if
        
        
        
    },



    onClearClick: function(button, e, eOpts) {
        var me = this.getView(),
            form = me.down('form');
        //paging = me.down('pagingtoolbar');
        form.reset();
    },

    onDeleteClick: function(button, e, eOpts) {
        var me = this.getView(),
            grid = me.down('gridpanel'),
            store = grid.getStore(),
            record = grid.getSelection(),
            count = record.length;

        if (count > 0) {

            Ext.MessageBox.confirm("Confirm", "คุณต้องการที่ลบใช่หรือไม่?", function (btn) {

                if (btn == 'yes') {

                    for (i = 0; i < count; i++) {
                        store.remove(record[i]);
                    }
                    store.sync();
                    Ext.MessageBox.alert("Status", 'ลบข้อมูลเรียบร้อย');
                }

            }, this);
        }//end if
    },

    onEditClick: function(button, e, eOpts) {
        var me = this.getView(),
            form = me.down('form'),
            grid = me.down('grid'),
            selection = grid.getSelection();

        if (selection.length) {
            form.loadRecord(selection[0]);
        }

        

    },

    onDeleteClick: function(button, e, eOpts) {
        var me = this.getView(),
            grid = me.down('gridpanel'),
            store = grid.getStore(),
            record = grid.getSelection(),
            count = record.length;

        if (count > 0) {

            Ext.MessageBox.confirm("Confirm", "คุณต้องการที่ลบใช่หรือไม่?", function (btn) {

                if (btn == 'yes') {

                    for (i = 0; i < count; i++) {
                        store.remove(record[i]);
                    }
                    store.sync();
                    Ext.MessageBox.alert("Status", 'ลบข้อมูลเรียบร้อย');
                }

            }, this);
        }//end if
    }

});
