2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								define ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    'jquery' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    'underscore' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    'backbone' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    'common' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    'moment' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    'app/views/widgets/hl-item-view' 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 15:13:48 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								] ,  function ( $ ,  _ ,  Backbone ,  Common ,  Moment ,  HLItemView )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    'use strict' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    var  GroupView  =  HLItemView . extend ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        tagName :  'tr' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        template :  _ . template ( $ ( '#group-item-tmpl' ) . html ( ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        transferTemplate :  _ . template ( $ ( '#group-transfer-form-tmpl' ) . html ( ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        events :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'click .group-delete-btn' :  'deleteGroup' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            'click .group-transfer-btn' :  'transferGroup' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        initialize :  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            HLItemView . prototype . initialize . call ( this ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            this . listenTo ( this . model ,  "change" ,  this . render ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        deleteGroup :  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  _this  =  this ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  group _name  =  this . model . get ( 'name' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  popupTitle  =  gettext ( "Delete Group" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  popupContent  =  gettext ( "Are you sure you want to delete %s ?" ) . replace ( '%s' ,  '<span class="op-target ellipsis ellipsis-op-target" title="'  +  Common . HTMLescape ( group _name )  +  '">'  +  Common . HTMLescape ( group _name )  +  '</span>' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  yesCallback  =  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $ . ajax ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    url :  Common . getUrl ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        'name' : 'admin-group' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        'group_id' :  _this . model . get ( 'id' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    type :  'DELETE' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    cache :  false , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    beforeSend :  Common . prepareCSRFToken , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    dataType :  'json' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    success :  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        _this . $el . remove ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 15:13:48 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        Common . feedback ( gettext ( "Successfully deleted 1 item." ) ,  'success' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    error :  function ( xhr ,  textStatus ,  errorThrown )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        Common . ajaxErrorHandler ( xhr ,  textStatus ,  errorThrown ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    complete :  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        $ . modal . close ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            Common . showConfirm ( popupTitle ,  popupContent ,  yesCallback ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        transferGroup :  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  _this  =  this ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  group _name  =  this . model . get ( 'name' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 15:13:48 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  group _id  =  this . model . get ( 'id' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  cur _owner  =  this . model . get ( 'owner' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								            var  $form  =  $ ( this . transferTemplate ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                title :  gettext ( "Transfer Group {group_name} To" ) . replace ( '{group_name}' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                           '<span class="op-target ellipsis ellipsis-op-target" title="'  +  Common . HTMLescape ( group _name )  +  '">'  +  Common . HTMLescape ( group _name )  +  '</span>' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $form . modal ( { focus : false } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $ ( '#simplemodal-container' ) . css ( { 'width' : 'auto' ,  'height' : 'auto' } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $ ( '[name="email"]' ,  $form ) . select2 ( $ . extend ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                Common . contactInputOptionsForSelect2 ( ) ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                width :  '300px' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                maximumSelectionSize :  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                placeholder :  gettext ( "Search user or enter email and press Enter" ) ,  // to override 'placeholder' returned by `Common.conta...`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                formatSelectionTooBig :  gettext ( "You cannot select any more choices" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-02-05 16:47:56 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            $form . on ( 'submit' ,  function ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                var  email  =  $ . trim ( $ ( '[name="email"]' ,  $ ( this ) ) . val ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 15:13:48 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                var  $submitBtn  =  $ ( '[type="submit"]' ,  $ ( this ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                if  ( ! email )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 15:13:48 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                if  ( email  ==  cur _owner )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                    return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                Common . disableButton ( $submitBtn ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                $ . ajax ( { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-21 15:13:48 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                    url :  Common . getUrl ( { 'name' :  'admin-group' ,  'group_id' :  group _id } ) , 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                    type :  'put' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    dataType :  'json' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    beforeSend :  Common . prepareCSRFToken , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    data :  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-04 18:01:44 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                        'new_owner' :  email 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    success :  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        $ . modal . close ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        _this . model . set ( { 'owner' :  email } ) ;  // it will trigger 'change' event
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        Common . feedback ( gettext ( "Successfully transferred the group." ) ,  'success' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    error :  function ( xhr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        var  error _msg ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        if  ( xhr . responseText )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-05 16:47:56 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                            error _msg  =  JSON . parse ( xhr . responseText ) . error _msg ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-20 12:26:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            error _msg  =  gettext ( "Failed. Please check the network." ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        $ ( '.error' ,  $form ) . html ( error _msg ) . show ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                        Common . enableButton ( $submitBtn ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        render :  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  data  =  this . model . toJSON ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                created _at  =  Moment ( data [ 'created_at' ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            data [ 'time' ]  =  created _at . format ( 'LLLL' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            data [ 'time_from_now' ]  =  Common . getRelativeTimeStr ( created _at ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            this . $el . html ( this . template ( data ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  this ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  GroupView ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ) ;