Ext.define('NgcpCsc.view.pages.callforward.CallForwardMainForm', {
    extend: 'Ext.form.Panel',

    defaults: {
        width: '100%'
    },

    fieldDefaults: {
        labelSeparator: ''
    },

    margin: '0 10 0 0',

    defaultType: 'textfield',

    ui: 'cf-mainform',

    initComponent: function() {
        var callForwardListAGrid = Ext.create('NgcpCsc.view.pages.callforward.CallForwardSourcesetGrid', {
            id: this._firstprefix + this._secondprefix + 'cf-sourceset-list-a-grid',
            store: Ext.create('NgcpCsc.store.CallForwardSourceset', {
                proxy: {
                    type: 'ajax',
                    url: Ext.manifest.resources.path + '/data/callForwardSourcesetListA.json',
                    reader: {
                        type: 'json',
                        rootProperty: 'data'
                    }
                }
            })
        });
        var callForwardListBGrid = Ext.create('NgcpCsc.view.pages.callforward.CallForwardSourcesetGrid', {
            id: this._firstprefix + this._secondprefix + 'cf-sourceset-list-b-grid',
            store: Ext.create('NgcpCsc.store.CallForwardSourceset', {
                proxy: {
                    type: 'ajax',
                    url: Ext.manifest.resources.path + '/data/callForwardSourcesetListB.json',
                    reader: {
                        type: 'json',
                        rootProperty: 'data'
                    }
                }
            })
        });
        var busyGrid = Ext.create('NgcpCsc.view.pages.callforward.CallForwardMainGrid', {
            store: Ext.create('NgcpCsc.store.CallForward', {
                storeId: this._firstprefix + this._secondprefix + 'CallForwardBusy',
                proxy: {
                    type: 'ajax',
                    url: Ext.manifest.resources.path + '/data/callForwardBusy.json',
                    reader: {
                        type: 'json',
                        rootProperty: 'data'
                    }
                }
            })
        });
        var onlineGrid = Ext.create('NgcpCsc.view.pages.callforward.CallForwardMainGrid', {
            store: Ext.create('NgcpCsc.store.CallForward', {
                storeId: this._firstprefix + this._secondprefix + 'CallForwardOnline',
                proxy: {
                    type: 'ajax',
                    url: Ext.manifest.resources.path  + '/data/callForwardOnline.json',
                    reader: {
                        type: 'json',
                        rootProperty: 'data'
                    }
                }
            })
        });
        var offlineGrid = Ext.create('NgcpCsc.view.pages.callforward.CallForwardMainGrid', {
            store: Ext.create('NgcpCsc.store.CallForward', {
                storeId: this._firstprefix + this._secondprefix + 'CallForwardOffline',
                proxy: {
                    type: 'ajax',
                    url: Ext.manifest.resources.path + '/data/callForwardOffline.json',
                    reader: {
                        type: 'json',
                        rootProperty: 'data'
                    }
                }
            })
        });


        this.items = [{
            xtype: 'panel',
            bind: {
                title: '{source_lista_title}',
                hidden: '{list_a}'
            },
            collapsible: true,
            collapsed: true,
            items: [{
                xtype: 'form',
                layout: 'hbox',
                margin: '10 0 0 0',
                bind: {
                    hidden: '{hide_lista_titleField}'
                },
                items: [{
                    xtype: 'textfield',
                    userCls: 'cf-sourceset-textfield',
                    fieldLabel: Ngcp.csc.locales.callforward.sourceset_title[localStorage.getItem('languageSelected')],
                    flex: 1,
                    bind: '{source_lista_title}'
                }, {
                    xtype: 'button',
                    html: Ngcp.csc.locales.common.cancel_caps[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'lista_titleField-cancelButton',
                    margin: '0 0 0 10',
                    handler: 'cancelNewTitle'
                }, {
                    xtype: 'button',
                    html: Ngcp.csc.locales.common.save_caps[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'lista_titleField-saveButton',
                    margin: '0 0 0 10',
                    handler: 'saveNewTitle'
                }]
            },
                    callForwardListAGrid,
                {
                    xtype: 'panel',
                    layout: 'hbox',
                    margin: '15 0 0 0',
                    items: [{
                        xtype: 'button',
                        html: Ngcp.csc.locales.callforward.change_title[localStorage.getItem('languageSelected')],
                        id: this._firstprefix + this._secondprefix + 'lista_titleField-showButton',
                        margin: '0 0 0 500',
                        handler: 'toggleChangeTitle'
                    }, {
                        xtype: 'button',
                        text: Ngcp.csc.locales.callforward.add_new_source[localStorage.getItem('languageSelected')],
                        id: this._firstprefix + this._secondprefix + 'addListAButton',
                        width: 135,
                        margin: '0 0 0 10',
                        listeners: {
                            click: 'addEmptyRow'
                        }
                    }]
            }]
        }, {
            xtype: 'panel',
            bind: {
                title: '{source_listb_title}',
                hidden: '{list_b}'
            },
            collapsible: true,
            collapsed: true,
            items: [{
                xtype: 'form',
                layout: 'hbox',
                margin: '10 0 0 0',
                bind: {
                    hidden: '{hide_listb_titleField}'
                },
                items: [{
                    xtype: 'textfield',
                    userCls: 'cf-sourceset-textfield',
                    fieldLabel: Ngcp.csc.locales.callforward.sourceset_title[localStorage.getItem('languageSelected')],
                    flex: 1,
                    bind: '{source_listb_title}'
                }, {
                    xtype: 'button',
                    html: Ngcp.csc.locales.common.cancel_caps[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'listb_titleField-cancelButton',
                    margin: '0 0 0 10',
                    handler: 'cancelNewTitle'
                }, {
                    xtype: 'button',
                    html: Ngcp.csc.locales.common.save_caps[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'listb_titleField-saveButton',
                    margin: '0 0 0 10',
                    handler: 'saveNewTitle'
                }]
            },
                    callForwardListBGrid,
                {
                    xtype: 'panel',
                    layout: 'hbox',
                    margin: '15 0 0 0',
                    bind: {
                        hidden: '{list_b}'
                    },
                    items: [{
                        xtype: 'button',
                        html: Ngcp.csc.locales.callforward.change_title[localStorage.getItem('languageSelected')],
                        id: this._firstprefix + this._secondprefix + 'listb_titleField-showButton',
                        margin: '0 0 0 500',
                        handler: 'toggleChangeTitle'
                    }, {
                        xtype: 'button',
                        text: Ngcp.csc.locales.callforward.add_new_source[localStorage.getItem('languageSelected')],
                        id: this._firstprefix + this._secondprefix + 'addListBButton',
                        width: 135,
                        margin: '0 0 0 10',
                        listeners: {
                            click: 'addEmptyRow'
                        }
                    }]
            }]
        }, {
                xtype: 'container',
                userCls: 'cf-text cf-subheader',
                html: Ngcp.csc.locales.callforward.when_phone_online[localStorage.getItem('languageSelected')]
            }, {
                xtype: 'panel',
                layout: 'hbox',
                id: this._firstprefix + this._secondprefix + 'onlineFirstRingFields',
                padding: '0 11 0 0',
                width: 500,
                margin: '0 0 0 50',
                items: [{
                    xtype: 'combo',
                    store: 'FirstRingActions',
                    valueField: 'name',
                    displayField: 'name',
                    id: this._firstprefix + this._secondprefix + 'onlineFirstDest',
                    fieldLabel: Ngcp.csc.locales.callforward.first_ring[localStorage.getItem('languageSelected')],
                    value: 'Own phone',
                    allowBlank: false,
                    editable: false,
                    listeners: {
                        change: 'selectRing'
                    },
                    flex: 5
                }, {
                    xtype: 'numberfield',
                    step: 10,
                    minValue:0,
                    maxValue: 300,
                    value: '10',
                    id: this._firstprefix + this._secondprefix + 'onlineFirstTimeout',
                    allowBlank: false,
                    editable: false,
                    flex: 4,
                    margin: '0 0 0 10',
                    bind: {
                        hidden: '{online_first_timeout_hidden}'
                    },
                    fieldLabel: Ngcp.csc.locales.callforward.and_ring_for[localStorage.getItem('languageSelected')]
                }, {
                    xtype: 'container',
                    html: Ngcp.csc.locales.callforward.secs[localStorage.getItem('languageSelected')],
                    padding: '7 0 0 20',
                    flex: 1,
                    bind: {
                        hidden: '{online_first_timeout_hidden}'
                    }
                }]
            }, {
                xtype: 'container',
                layout: 'hbox',
                margin: '10 0 0 50',
                items: [{
                        xtype: 'container',
                        html: Ngcp.csc.locales.callforward.then_forward_to[localStorage.getItem('languageSelected')],
                        userCls: 'cf-thentext'
                    },
                    onlineGrid
                ]
            }, {
                xtype: 'panel',
                margin: '10 7 0 155',
                bind: {
                    hidden: '{online_add_new_then_hidden}'
                },
                id: this._firstprefix + this._secondprefix + 'onlineThenRingFields',
                layout: 'hbox',
                items: [{
                    xtype: 'combo',
                    displayField: 'name',
                    valueField: 'name',
                    store: 'Forwards',
                    id: this._firstprefix + this._secondprefix + 'onlineThenDest',
                    bind: '{online_then_dest}',
                    allowBlank: false,
                    editable: false,
                    flex: 3,
                    margin: '0 10 0 0',
                    listeners: {
                        change: 'selectRing'
                    }
                }, {
                    xtype: 'textfield',
                    flex: 3,
                    id: this._firstprefix + this._secondprefix + 'onlineThenNumber',
                    emptyText: Ngcp.csc.locales.callforward.enter_number[localStorage.getItem('languageSelected')],
                    bind: {
                        hidden: '{online_then_timeout_hidden}',
                        value: '{online_then_number}'
                    },
                    listeners: {
                        specialkey: 'onEnterPressed'
                    }
                }, {
                    xtype: 'numberfield',
                    step: 10,
                    minValue:0,
                    maxValue: 300,
                    labelWidth: 80,
                    fieldLabel: Ngcp.csc.locales.callforward.and_ring_for[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'onlineThenTimeout',
                    bind: {
                        value: '{online_then_timeout}',
                        hidden: '{online_then_timeout_hidden}'
                    },
                    allowBlank: false,
                    editable: false,
                    flex: 4,
                    margin: '0 0 0 10'
                }, {
                    xtype: 'container',
                    html: Ngcp.csc.locales.callforward.secs[localStorage.getItem('languageSelected')],
                    padding: '7 0 0 10',
                    flex: 1,
                    bind: {
                        hidden: '{online_then_timeout_hidden}'
                    }
                }, {
                    xtype: 'button',
                    text: Ngcp.csc.locales.common.save_caps[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'onlineSaveButton',
                    width: 100,
                    listeners: {
                        click: 'addNewDestination'
                    }
                }]
            }, {
                html: Ngcp.csc.locales.callforward.add_new_destination[localStorage.getItem('languageSelected')],
                xtype: 'button',
                id: this._firstprefix + this._secondprefix + 'onlineButton',
                width: 165,
                margin: '15 0 0 155',
                listeners: {
                    click: 'toggleNewDestinationForm'
                },
                bind: {
                    hidden: '{online_add_button_hidden}'
                }
            }, {
                html: Ngcp.csc.locales.callforward.cancel_destination[localStorage.getItem('languageSelected')],
                xtype: 'button',
                id: this._firstprefix + this._secondprefix + 'onlineButtonCancel',
                width: 165,
                margin: '15 0 0 155',
                listeners: {
                    click: 'toggleNewDestinationForm'
                },
                bind: {
                    hidden: '{online_cancel_button_hidden}'
                }
            }, {
                xtype: 'container',
                userCls: 'cf-text cf-subheader',
                html: Ngcp.csc.locales.callforward.when_phone_busy[localStorage.getItem('languageSelected')]
            }, {
                xtype: 'panel',
                layout: 'hbox',
                id: this._firstprefix + this._secondprefix + 'busyFirstRingFields',
                padding: '0 11 0 0',
                margin: '0 0 0 50',
                width: 500,
                items: [{
                    xtype: 'combo',
                    store: 'FirstRingActions',
                    valueField: 'name',
                    displayField: 'name',
                    id: this._firstprefix + this._secondprefix + 'busyFirstDest',
                    fieldLabel: Ngcp.csc.locales.callforward.first_ring[localStorage.getItem('languageSelected')],
                    value: 'None',
                    allowBlank: false,
                    editable: false,
                    listeners: {
                        change: 'selectRing'
                    },
                    flex: 5
                }, {
                    xtype: 'numberfield',
                    step: 10,
                    minValue:0,
                    maxValue: 300,
                    value: '10',
                    id: this._firstprefix + this._secondprefix + 'busyFirstTimeout',
                    allowBlank: false,
                    editable: false,
                    flex: 4,
                    margin: '0 0 0 10',
                    bind: {
                        hidden: '{busy_first_timeout_hidden}'
                    },
                    fieldLabel: Ngcp.csc.locales.callforward.and_ring_for[localStorage.getItem('languageSelected')]
                }, {
                    xtype: 'container',
                    html: Ngcp.csc.locales.callforward.secs[localStorage.getItem('languageSelected')],
                    padding: '7 0 0 20',
                    flex: 1,
                    bind: {
                        hidden: '{busy_first_timeout_hidden}'
                    }
                }]
            }, {
                xtype: 'container',
                layout: 'hbox',
                margin: '10 0 0 50',
                items: [{
                        xtype: 'container',
                        html: Ngcp.csc.locales.callforward.then_forward_to[localStorage.getItem('languageSelected')],
                        userCls: 'cf-thentext'
                    },
                    busyGrid
                ]
            }, {
                xtype: 'panel',
                margin: '10 7 0 155',
                bind: {
                    hidden: '{busy_add_new_then_hidden}'
                },
                id: this._firstprefix + this._secondprefix + 'busyThenRingFields',
                layout: 'hbox',
                items: [{
                    xtype: 'combo',
                    displayField: 'name',
                    valueField: 'name',
                    store: 'Forwards',
                    id: this._firstprefix + this._secondprefix + 'busyThenDest',
                    bind: '{busy_then_dest}',
                    allowBlank: false,
                    editable: false,
                    flex: 3,
                    margin: '0 10 0 0',
                    listeners: {
                        change: 'selectRing'
                    }
                }, {
                    xtype: 'textfield',
                    flex: 3,
                    id: this._firstprefix + this._secondprefix + 'busyThenNumber',
                    emptyText: Ngcp.csc.locales.callforward.enter_number[localStorage.getItem('languageSelected')],
                    bind: {
                        hidden: '{busy_then_timeout_hidden}',
                        value: '{busy_then_number}'
                    },
                    listeners: {
                        specialkey: 'onEnterPressed'
                    }
                }, {
                    xtype: 'numberfield',
                    step: 10,
                    minValue:0,
                    maxValue: 300,
                    labelWidth: 80,
                    fieldLabel: Ngcp.csc.locales.callforward.and_ring_for[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'busyThenTimeout',
                    bind: {
                        value: '{busy_then_timeout}',
                        hidden: '{busy_then_timeout_hidden}'
                    },
                    allowBlank: false,
                    editable: false,
                    flex: 4,
                    margin: '0 0 0 10'
                }, {
                    xtype: 'container',
                    html: Ngcp.csc.locales.callforward.secs[localStorage.getItem('languageSelected')],
                    padding: '7 0 0 10',
                    flex: 1,
                    bind: {
                        hidden: '{busy_then_timeout_hidden}'
                    }
                }, {
                    xtype: 'button',
                    text: Ngcp.csc.locales.common.save_caps[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'busySaveButton',
                    width: 100,
                    listeners: {
                        click: 'addNewDestination'
                    }
                }]
            }, {
                html: Ngcp.csc.locales.callforward.add_new_destination[localStorage.getItem('languageSelected')],
                xtype: 'button',
                id: this._firstprefix + this._secondprefix + 'busyButton',
                width: 165,
                margin: '15 0 0 155',
                listeners: {
                    click: 'toggleNewDestinationForm'
                },
                bind: {
                    hidden: '{busy_add_button_hidden}'
                }
            }, {
                html: Ngcp.csc.locales.callforward.cancel_destination[localStorage.getItem('languageSelected')],
                xtype: 'button',
                id: this._firstprefix + this._secondprefix + 'busyButtonCancel',
                width: 165,
                margin: '15 0 0 155',
                listeners: {
                    click: 'toggleNewDestinationForm'
                },
                bind: {
                    hidden: '{busy_cancel_button_hidden}'
                }
            }, {
                xtype: 'container',
                userCls: 'cf-text cf-subheader',
                html: Ngcp.csc.locales.callforward.when_phone_offline[localStorage.getItem('languageSelected')]
            }, {
                xtype: 'panel',
                layout: 'hbox',
                id: this._firstprefix + this._secondprefix + 'offlineFirstRingFields',
                padding: '0 11 0 0',
                margin: '0 0 0 50',
                width: 500,
                items: [{
                    xtype: 'combo',
                    store: 'FirstRingActions',
                    valueField: 'name',
                    displayField: 'name',
                    id: this._firstprefix + this._secondprefix + 'offlineFirstDest',
                    fieldLabel: Ngcp.csc.locales.callforward.first_ring[localStorage.getItem('languageSelected')],
                    value: 'None',
                    allowBlank: false,
                    editable: false,
                    listeners: {
                        change: 'selectRing'
                    },
                    flex: 5
                }, {
                    xtype: 'numberfield',
                    step: 10,
                    minValue:0,
                    maxValue: 300,
                    value: '10',
                    id: this._firstprefix + this._secondprefix + 'offlineFirstTimeout',
                    allowBlank: false,
                    editable: false,
                    flex: 4,
                    margin: '0 0 0 10',
                    bind: {
                        hidden: '{offline_first_timeout_hidden}'
                    },
                    fieldLabel: Ngcp.csc.locales.callforward.and_ring_for[localStorage.getItem('languageSelected')]
                }, {
                    xtype: 'container',
                    html: Ngcp.csc.locales.callforward.secs[localStorage.getItem('languageSelected')],
                    padding: '7 0 0 20',
                    flex: 1,
                    bind: {
                        hidden: '{offline_first_timeout_hidden}'
                    }
                }]
            }, {
                xtype: 'container',
                layout: 'hbox',
                margin: '10 0 0 50',
                items: [{
                        xtype: 'container',
                        html: Ngcp.csc.locales.callforward.then_forward_to[localStorage.getItem('languageSelected')],
                        userCls: 'cf-thentext'
                    },
                    offlineGrid
                ]
            }, {
                xtype: 'panel',
                margin: '10 7 0 155',
                bind: {
                    hidden: '{offline_add_new_then_hidden}'
                },
                id: this._firstprefix + this._secondprefix + 'offlineThenRingFields',
                layout: 'hbox',
                items: [{
                    xtype: 'combo',
                    displayField: 'name',
                    valueField: 'name',
                    store: 'Forwards',
                    id: this._firstprefix + this._secondprefix + 'offlineThenDest',
                    bind: '{offline_then_dest}',
                    allowBlank: false,
                    editable: false,
                    flex: 3,
                    margin: '0 10 0 0',
                    listeners: {
                        change: 'selectRing'
                    }
                }, {
                    xtype: 'textfield',
                    flex: 3,
                    id: this._firstprefix + this._secondprefix + 'offlineThenNumber',
                    emptyText: Ngcp.csc.locales.callforward.enter_number[localStorage.getItem('languageSelected')],
                    bind: {
                        hidden: '{offline_then_timeout_hidden}',
                        value: '{offline_then_number}'
                    },
                    listeners: {
                        specialkey: 'onEnterPressed'
                    }
                }, {
                    xtype: 'numberfield',
                    step: 10,
                    minValue:0,
                    maxValue: 300,
                    labelWidth: 80,
                    fieldLabel: Ngcp.csc.locales.callforward.and_ring_for[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'offlineThenTimeout',
                    bind: {
                        value: '{offline_then_timeout}',
                        hidden: '{offline_then_timeout_hidden}'
                    },
                    allowBlank: false,
                    editable: false,
                    flex: 4,
                    margin: '0 0 0 10'
                }, {
                    xtype: 'container',
                    html: Ngcp.csc.locales.callforward.secs[localStorage.getItem('languageSelected')],
                    padding: '7 0 0 10',
                    flex: 1,
                    bind: {
                        hidden: '{offline_then_timeout_hidden}'
                    }
                }, {
                    xtype: 'button',
                    text: Ngcp.csc.locales.common.save_caps[localStorage.getItem('languageSelected')],
                    id: this._firstprefix + this._secondprefix + 'offlineSaveButton',
                    width: 100,
                    listeners: {
                        click: 'addNewDestination'
                    }
                }]
            }, {
                html: Ngcp.csc.locales.callforward.add_new_destination[localStorage.getItem('languageSelected')],
                xtype: 'button',
                id: this._firstprefix + this._secondprefix + 'offlineButton',
                width: 165,
                margin: '15 0 0 155',
                listeners: {
                    click: 'toggleNewDestinationForm'
                },
                bind: {
                    hidden: '{offline_add_button_hidden}'
                }
            }, {
                html: Ngcp.csc.locales.callforward.cancel_destination[localStorage.getItem('languageSelected')],
                xtype: 'button',
                id: this._firstprefix + this._secondprefix + 'offlineButtonCancel',
                width: 165,
                margin: '15 0 0 155',
                listeners: {
                    click: 'toggleNewDestinationForm'
                },
                bind: {
                    hidden: '{offline_cancel_button_hidden}'
                }
        }];

        this.callParent();
    }

});
