/*************************************************
 * Copyright (c) 2015 Ansible, Inc.
 *
 * All Rights Reserved
 *************************************************/

  /**
 * @ngdoc function
 * @name forms.function:Teams
 * @description This form is for adding/editing teams
*/

export default
    angular.module('TeamFormDefinition', [])
        .value('TeamForm', {

            addTitle: 'New Team', //Legend in add mode
            editTitle: '{{ name }}', //Legend in edit mode
            name: 'team',
            tabs: true,

            fields: {
                name: {
                    label: 'Name',
                    type: 'text',
                    addRequired: true,
                    editRequired: true,
                    capitalize: false
                },
                description: {
                    label: 'Description',
                    type: 'text',
                    addRequired: false,
                    editRequired: false
                },
                organization: {
                    label: 'Organization',
                    type: 'lookup',
                    sourceModel: 'organization',
                    sourceField: 'name',
                    ngClick: 'lookUpOrganization()',
                    awRequiredWhen: {
                        variable: "teamrequired",
                        init: "true"
                    }
                }
            },

            buttons: {
                save: {
                    ngClick: 'formSave()',
                    ngDisabled: true
                },
                cancel: {
                    ngClick: 'formCancel()'
                }
            },

            related: {

                credentials: {
                    type: 'collection',
                    title: 'Credentials',
                    iterator: 'credential',
                    open: false,
                    index: false,

                    actions: {
                        add: {
                            ngClick: "add('credentials')",
                            label: 'Add',
                            add: 'Add a new credential',
                            actionClass: 'btn List-buttonSubmit',
                            buttonContent: '&#43; ADD'
                        }
                    },

                    fields: {
                        name: {
                            key: true,
                            label: 'Name'
                        },
                        description: {
                            label: 'Description'
                        }
                    },

                    fieldActions: {
                        edit: {
                            label: 'Edit',
                            ngClick: "edit('credentials', credential.id, credential.name)",
                            icon: 'icon-edit',
                            awToolTip: 'Modify the credential',
                            'class': 'btn btn-default'
                        },
                        "delete": {
                            label: 'Delete',
                            ngClick: "delete('credentials', credential.id, credential.name, 'credential')",
                            icon: 'icon-trash',
                            "class": 'btn-danger',
                            awToolTip: 'Remove the credential'
                        }
                    }
                },

                permissions: {
                    type: 'collection',
                    title: 'Permissions',
                    iterator: 'permission',
                    open: false,
                    index: false,

                    actions: {
                        add: {
                            ngClick: "add('permissions')",
                            label: 'Add',
                            awToolTip: 'Add a permission for this user',
                            ngShow: 'PermissionAddAllowed',
                            actionClass: 'btn List-buttonSubmit',
                            buttonContent: '&#43; ADD'
                        }
                    },

                    fields: {
                        name: {
                            key: true,
                            label: 'Name',
                            ngClick: "edit('permissions', permission.id, permission.name)"
                        },
                        inventory: {
                            label: 'Inventory',
                            sourceModel: 'inventory',
                            sourceField: 'name',
                            ngBind: 'permission.summary_fields.inventory.name'
                        },
                        project: {
                            label: 'Project',
                            sourceModel: 'project',
                            sourceField: 'name',
                            ngBind: 'permission.summary_fields.project.name'
                        },
                        permission_type: {
                            label: 'Permission',
                            ngBind: 'getPermissionText()',
                            searchType: 'select'
                        }
                    },

                    fieldActions: {
                        edit: {
                            label: 'Edit',
                            ngClick: "edit('permissions', permission.id, permission.name)",
                            icon: 'icon-edit',
                            awToolTip: 'Edit the permission',
                            'class': 'btn btn-default'
                        },

                        "delete": {
                            label: 'Delete',
                            ngClick: "delete('permissions', permission.id, permission.name, 'permission')",
                            icon: 'icon-trash',
                            "class": 'btn-danger',
                            awToolTip: 'Delete the permission',
                            ngShow: 'PermissionAddAllowed'
                        }
                    }

                },

                projects: {
                    type: 'collection',
                    title: 'Projects',
                    iterator: 'project',
                    open: false,
                    index: false,

                    actions: {
                        add: {
                            ngClick: "add('projects')",
                            label: 'Add',
                            actionClass: 'btn List-buttonSubmit',
                            buttonContent: '&#43; ADD'
                        }
                    },

                    fields: {
                        name: {
                            key: true,
                            label: 'Name'
                        },
                        description: {
                            label: 'Description'
                        }
                    },

                    fieldActions: {
                        edit: {
                            label: 'Edit',
                            ngClick: "edit('projects', project.id, project.name)",
                            icon: 'icon-edit',
                            awToolTip: 'Modify the project',
                            'class': 'btn btn-default'
                        },
                        "delete": {
                            label: 'Delete',
                            ngClick: "delete('projects', project.id, project.name, 'project')",
                            icon: 'icon-trash',
                            "class": 'btn-danger',
                            awToolTip: 'Remove the project'
                        }
                    }
                },

                users: {
                    type: 'collection',
                    title: 'Users',
                    iterator: 'user',
                    open: false,
                    index: false,

                    actions: {
                        add: {
                            ngClick: "add('users')",
                            label: 'Add',
                            awToolTip: 'Add a user',
                            actionClass: 'btn List-buttonSubmit',
                            buttonContent: '&#43; ADD'
                        }
                    },

                    fields: {
                        username: {
                            key: true,
                            label: 'Username'
                        },
                        first_name: {
                            label: 'First Name'
                        },
                        last_name: {
                            label: 'Last Name'
                        }
                    },

                    fieldActions: {
                        edit: {
                            label: 'Edit',
                            ngClick: "edit('users', user.id, user.username)",
                            icon: 'icon-edit',
                            awToolTip: 'Edit user',
                            'class': 'btn btn-default'
                        },
                        "delete": {
                            label: 'Delete',
                            ngClick: "delete('users', user.id, user.username, 'user')",
                            icon: 'icon-terash',
                            "class": 'btn-danger',
                            awToolTip: 'Remove user'
                        }
                    }
                }

            }

        }); //InventoryForm
