~jlungo/zhris/trunk

« back to all changes in this revision

Viewing changes to interface/html5/views/company/department/DepartmentViewController.js

  • Committer: Juma Lungo
  • Date: 2017-11-16 08:54:53 UTC
  • Revision ID: juma.lungo@zalongwa.com-20171116085453-q3jxht0gcab8jbya
codebase commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
DepartmentViewController = BaseViewController.extend( {
 
2
        el: '#department_view_container',
 
3
        status_array: null,
 
4
 
 
5
        initialize: function( options ) {
 
6
                this._super( 'initialize', options );
 
7
                this.edit_view_tpl = 'DepartmentEditView.html';
 
8
                this.permission_id = 'department';
 
9
                this.viewId = 'Department';
 
10
                this.script_name = 'DepartmentView';
 
11
                this.table_name_key = 'department';
 
12
                this.context_menu_name = $.i18n._( 'Departments' );
 
13
                this.navigation_label = $.i18n._( 'Department' ) + ':';
 
14
                this.api = new (APIFactory.getAPIClass( 'APIDepartment' ))();
 
15
 
 
16
                this.render();
 
17
                this.buildContextMenu();
 
18
 
 
19
                this.initData();
 
20
                this.setSelectRibbonMenuIfNecessary( 'Department' );
 
21
 
 
22
        },
 
23
 
 
24
        initOptions: function() {
 
25
                var $this = this;
 
26
                this.initDropDownOption( 'status' );
 
27
 
 
28
        },
 
29
 
 
30
        buildEditViewUI: function() {
 
31
 
 
32
                this._super( 'buildEditViewUI' );
 
33
 
 
34
                var $this = this;
 
35
 
 
36
                this.setTabLabels( {
 
37
                        'tab_department': $.i18n._( 'Department' ),
 
38
                        'tab_audit': $.i18n._( 'Audit' )
 
39
                } );
 
40
 
 
41
 
 
42
                this.navigation.AComboBox( {
 
43
                        api_class: (APIFactory.getAPIClass( 'APIDepartment' )),
 
44
                        id: this.script_name + '_navigation',
 
45
                        allow_multiple_selection: false,
 
46
                        layout_name: ALayoutIDs.DEPARTMENT,
 
47
                        navigation_mode: true,
 
48
                        show_search_inputs: true
 
49
                } );
 
50
 
 
51
                this.setNavigation();
 
52
 
 
53
                //Tab 0 start
 
54
 
 
55
                var tab_department = this.edit_view_tab.find( '#tab_department' );
 
56
 
 
57
                var tab_department_column1 = tab_department.find( '.first-column' );
 
58
 
 
59
                this.edit_view_tabs[0] = [];
 
60
 
 
61
                this.edit_view_tabs[0].push( tab_department_column1 );
 
62
 
 
63
                //Status
 
64
 
 
65
                var form_item_input = Global.loadWidgetByName( FormItemType.COMBO_BOX );
 
66
                form_item_input.TComboBox( {field: 'status_id'} );
 
67
                form_item_input.setSourceData( Global.addFirstItemToArray( $this.status_array ) );
 
68
                this.addEditFieldToColumn( $.i18n._( 'Status' ), form_item_input, tab_department_column1, '' );
 
69
 
 
70
                //Name
 
71
                form_item_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
 
72
 
 
73
                form_item_input.TTextInput( {field: 'name', width: '100%'} );
 
74
                this.addEditFieldToColumn( $.i18n._( 'Name' ), form_item_input, tab_department_column1 );
 
75
                form_item_input.parent().width( '45%' );
 
76
 
 
77
 
 
78
                // Code
 
79
 
 
80
                form_item_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
 
81
 
 
82
                form_item_input.TTextInput( {field: 'manual_id', width: 65} );
 
83
                this.addEditFieldToColumn( $.i18n._( 'Code' ), form_item_input, tab_department_column1 );
 
84
 
 
85
                //Allowed GEO Fences
 
86
                if (  LocalCacheData.getCurrentCompany().product_edition_id >= 20 ) {
 
87
                        form_item_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
 
88
                        form_item_input.AComboBox( {
 
89
                                api_class: (APIFactory.getAPIClass( 'APIGEOFence' )),
 
90
                                allow_multiple_selection: true,
 
91
                                layout_name: ALayoutIDs.GEO_FENCE,
 
92
                                show_search_inputs: true,
 
93
                                set_empty: true,
 
94
                                field: 'geo_fence_ids'
 
95
                        } );
 
96
                        this.addEditFieldToColumn( $.i18n._( 'Allowed GEO Fences' ), form_item_input, tab_department_column1 );
 
97
                }
 
98
 
 
99
                //Tags
 
100
                form_item_input = Global.loadWidgetByName( FormItemType.TAG_INPUT );
 
101
 
 
102
                form_item_input.TTagInput( {field: 'tag', object_type_id: 120} );
 
103
                this.addEditFieldToColumn( $.i18n._( 'Tags' ), form_item_input, tab_department_column1, '' );
 
104
 
 
105
        },
 
106
 
 
107
        buildSearchFields: function() {
 
108
 
 
109
                this._super( 'buildSearchFields' );
 
110
                this.search_fields = [
 
111
 
 
112
                        new SearchField( {label: $.i18n._( 'Status' ),
 
113
                                in_column: 1,
 
114
                                field: 'status_id',
 
115
                                multiple: true,
 
116
                                basic_search: true,
 
117
                                layout_name: ALayoutIDs.OPTION_COLUMN,
 
118
                                form_item_type: FormItemType.AWESOME_BOX} ),
 
119
                        new SearchField( {label: $.i18n._( 'Name' ),
 
120
                                in_column: 1,
 
121
                                field: 'name',
 
122
                                multiple: true,
 
123
                                basic_search: true,
 
124
                                form_item_type: FormItemType.TEXT_INPUT} ),
 
125
 
 
126
                        new SearchField( {label: $.i18n._( 'Tags' ),
 
127
                                field: 'tag',
 
128
                                basic_search: true,
 
129
                                in_column: 1,
 
130
                                form_item_type: FormItemType.TAG_INPUT} ),
 
131
                        new SearchField( {label: $.i18n._( 'Code' ),
 
132
                                field: 'manual_id',
 
133
                                basic_search: true,
 
134
                                in_column: 2,
 
135
                                object_type_id: 120,
 
136
                                form_item_type: FormItemType.TEXT_INPUT} ),
 
137
                        new SearchField( {label: $.i18n._( 'Created By' ),
 
138
                                in_column: 2,
 
139
                                field: 'created_by',
 
140
                                layout_name: ALayoutIDs.USER,
 
141
                                api_class: (APIFactory.getAPIClass( 'APIUser' )),
 
142
                                multiple: true,
 
143
                                basic_search: true,
 
144
                                adv_search: false,
 
145
                                form_item_type: FormItemType.AWESOME_BOX} ),
 
146
 
 
147
                        new SearchField( {label: $.i18n._( 'Updated By' ),
 
148
                                in_column: 2,
 
149
                                field: 'updated_by',
 
150
                                layout_name: ALayoutIDs.USER,
 
151
                                api_class: (APIFactory.getAPIClass( 'APIUser' )),
 
152
                                multiple: true,
 
153
                                basic_search: true,
 
154
                                adv_search: false,
 
155
                                form_item_type: FormItemType.AWESOME_BOX} )
 
156
                ];
 
157
        },
 
158
 
 
159
        buildContextMenuModels: function() {
 
160
                var menu = this._super('buildContextMenuModels')[0];
 
161
 
 
162
                var import_csv = new RibbonSubMenu( {
 
163
                        label: $.i18n._( 'Import' ),
 
164
                        id: ContextMenuIconName.import_icon,
 
165
                        group: this.getContextMenuGroupByName(menu,'other'),
 
166
                        icon: Icons.import_icon,
 
167
                        permission_result: PermissionManager.checkTopLevelPermission( 'ImportCSVDepartment' ),
 
168
                        permission: null,
 
169
                        sort_order: 8000
 
170
                } );
 
171
 
 
172
                return [menu];
 
173
        },
 
174
 
 
175
        onContextMenuClick: function( context_btn, menu_name ) {
 
176
 
 
177
                this._super( 'onContextMenuClick', context_btn, menu_name );
 
178
 
 
179
                var id;
 
180
 
 
181
                if ( Global.isSet( menu_name ) ) {
 
182
                        id = menu_name;
 
183
                } else {
 
184
                        context_btn = $( context_btn );
 
185
 
 
186
                        id = $( context_btn.find( '.ribbon-sub-menu-icon' ) ).attr( 'id' );
 
187
 
 
188
                        if ( context_btn.hasClass( 'disable-image' ) ) {
 
189
                                return;
 
190
                        }
 
191
                }
 
192
 
 
193
                switch ( id ) {
 
194
                        case ContextMenuIconName.import_icon:
 
195
                                ProgressBar.showOverlay();
 
196
                                this.onImportClick();
 
197
                                break;
 
198
 
 
199
                }
 
200
        },
 
201
 
 
202
        onImportClick: function() {
 
203
                var $this = this;
 
204
 
 
205
                IndexViewController.openWizard( 'ImportCSVWizard', 'department', function(){
 
206
                        $this.search();
 
207
                } );
 
208
        }
 
209
 
 
210
 
 
211
} );