2018-04-24 12:08:20 +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 ( $ ( '#address-book-group-library-item-tmpl' ) . html ( ) ) ,
events : {
'click .repo-delete-btn' : 'del'
} ,
initialize : function ( options ) {
HLItemView . prototype . initialize . call ( this ) ;
this . group _id = options . group _id ;
} ,
del : function ( ) {
var _this = this ;
2018-04-25 08:19:15 +00:00
var repo _name = this . model . get ( 'repo_name' ) || this . model . get ( 'name' ) ;
2018-04-24 12:08:20 +00:00
var popupTitle = gettext ( "Delete Library" ) ;
var popupContent = gettext ( "Are you sure you want to delete %s ?" ) . replace ( '%s' , '<span class="op-target ellipsis ellipsis-op-target" title="' + Common . HTMLescape ( repo _name ) + '">' + Common . HTMLescape ( repo _name ) + '</span>' ) ;
var yesCallback = function ( ) {
2018-08-07 09:05:41 +00:00
var url _options = {
group _id : _this . group _id ,
repo _id : _this . model . get ( 'repo_id' )
} ;
if ( app . pageOptions . org _id ) { // org admin
$ . extend ( url _options , {
name : 'org-admin-group-owned-library' ,
org _id : app . pageOptions . org _id
} ) ;
} else {
$ . extend ( url _options , {
name : 'admin-group-owned-library'
} ) ;
}
2018-04-24 12:08:20 +00:00
$ . ajax ( {
2018-08-07 09:05:41 +00:00
url : Common . getUrl ( url _options ) ,
2018-04-24 12:08:20 +00:00
type : 'DELETE' ,
beforeSend : Common . prepareCSRFToken ,
dataType : 'json' ,
success : function ( ) {
_this . $el . remove ( ) ;
var msg = gettext ( "Successfully deleted 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 ( ) ,
icon _size = Common . isHiDPI ( ) ? 48 : 24 ,
icon _url = this . model . getIconUrl ( icon _size ) ;
data [ 'icon_url' ] = icon _url ;
data [ 'icon_title' ] = this . model . getIconTitle ( ) ;
data [ 'name' ] = data . name || data . repo _name ;
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 ;
} ) ;