2017-02-09 06:59:49 +00:00
define ( [
'jquery' ,
'underscore' ,
'backbone' ,
'common' ,
'app/views/widgets/hl-item-view'
] , function ( $ , _ , Backbone , Common , HLItemView ) {
'use strict' ;
var GroupRepoView = HLItemView . extend ( {
tagName : 'tr' ,
template : _ . template ( $ ( '#group-library-item-tmpl' ) . html ( ) ) ,
events : {
'click .repo-unshare-btn' : 'unshareGroupLibrary'
} ,
initialize : function ( ) {
HLItemView . prototype . initialize . call ( this ) ;
} ,
unshareGroupLibrary : function ( ) {
var _this = this ;
var repo _name = this . model . get ( 'name' ) ;
var popupTitle = gettext ( "Unshare Library" ) ;
var popupContent = gettext ( "Are you sure you want to unshare %s ?" ) . replace ( '%s' , '<span class="op-target ellipsis ellipsis-op-target" title="' + Common . HTMLescape ( repo _name ) + '">' + Common . HTMLescape ( repo _name ) + '</span>' ) ;
var yesCallback = function ( ) {
$ . ajax ( {
url : Common . getUrl ( {
'name' : 'admin-group-library' ,
'group_id' : _this . model . get ( 'group_id' ) ,
'repo_id' : _this . model . get ( 'repo_id' )
} ) ,
type : 'DELETE' ,
beforeSend : Common . prepareCSRFToken ,
dataType : 'json' ,
success : function ( ) {
_this . $el . remove ( ) ;
var msg = gettext ( "Successfully unshared library {placeholder}" ) . replace ( '{placeholder}' , repo _name ) ;
Common . feedback ( msg , 'success' ) ;
} ,
error : function ( xhr , textStatus , errorThrown ) {
Common . ajaxErrorHandler ( xhr , textStatus , errorThrown ) ;
} ,
complete : function ( ) {
$ . modal . close ( ) ;
}
} ) ;
} ;
Common . showConfirm ( popupTitle , popupContent , yesCallback ) ;
return false ;
} ,
render : function ( ) {
var data = this . model . toJSON ( ) ,
2017-07-31 09:30:43 +00:00
icon _size = Common . isHiDPI ( ) ? 48 : 24 ,
2017-02-09 06:59:49 +00:00
icon _url = this . model . getIconUrl ( icon _size ) ;
data [ 'icon_url' ] = icon _url ;
data [ 'icon_title' ] = this . model . getIconTitle ( ) ;
data [ 'formatted_size' ] = Common . fileSizeFormat ( data [ 'size' ] , 1 ) ,
data [ 'enable_sys_admin_view_repo' ] = app . pageOptions . enable _sys _admin _view _repo ;
data [ 'is_pro' ] = app . pageOptions . is _pro ;
this . $el . html ( this . template ( data ) ) ;
return this ;
}
} ) ;
return GroupRepoView ;
} ) ;