2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								"use strict";
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-31 15:11:38 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/*global define, templates, socket, ajaxify, app, admin, bootbox, utils, config */
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-12-13 22:14:08 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								define('admin/manage/groups', [
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-26 15:24:07 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									'translator',
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									'components'
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-22 13:10:18 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								], function(translator, components) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									var	Groups = {};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									Groups.init = function() {
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-13 15:10:50 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										var	createModal = $('#create-modal'),
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											createGroupName = $('#create-group-name'),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											createModalGo = $('#create-modal-go'),
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-22 13:10:18 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											createModalError = $('#create-modal-error');
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										createModal.on('keypress', function(e) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-12 16:56:11 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											if (e.keyCode === 13) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												createModalGo.click();
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-12 16:56:11 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										$('#create').on('click', function() {
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											createModal.modal('show');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											setTimeout(function() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												createGroupName.focus();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}, 250);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										createModalGo.on('click', function() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											var submitObj = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													name: createGroupName.val(),
							 | 
						
					
						
							
								
									
										
										
										
											2014-11-12 16:56:11 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													description: $('#create-group-desc').val()
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												errorText;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-09 10:33:54 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											socket.emit('admin.groups.create', submitObj, function(err) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												if (err) {
							 | 
						
					
						
							
								
									
										
										
										
											2015-02-18 15:33:21 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													if (err.hasOwnProperty('message') && utils.hasLanguageKey(err.message)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														translator.translate(err.message, config.defaultLang, function(translated) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															createModalError.html(translated).removeClass('hide');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													} else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														createModalError.html('<strong>Uh-Oh</strong><p>There was a problem creating your group. Please try again later!</p>').removeClass('hide');
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												} else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													createModalError.addClass('hide');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													createGroupName.val('');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													createModal.on('hidden.bs.modal', function() {
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-09 10:33:54 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
														ajaxify.refresh();
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													createModal.modal('hide');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-26 15:24:07 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										$('.groups-list').on('click', 'button[data-action]', function() {
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											var el = $(this),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												action = el.attr('data-action'),
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-26 15:24:07 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												groupName = el.parents('tr[data-groupname]').attr('data-groupname');
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											switch (action) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											case 'delete':
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												bootbox.confirm('Are you sure you wish to delete this group?', function(confirm) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													if (confirm) {
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-11 18:17:49 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
														socket.emit('groups.delete', {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															groupName: groupName
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														}, function(err, data) {
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
															if(err) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
																return app.alertError(err.message);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-11 18:17:49 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
															ajaxify.refresh();
							 | 
						
					
						
							
								
									
										
										
										
											2014-10-08 15:36:47 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
														});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return Groups;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 |