2016-05-25 02:45:22 +00:00
define ( [
'jquery' ,
'underscore' ,
'backbone' ,
'common' ,
'moment' ,
'app/views/widgets/hl-item-view'
] , function ( $ , _ , Backbone , Common , Moment , HLItemView ) {
'use strict' ;
2016-05-27 08:42:40 +00:00
var TrashRepoView = HLItemView . extend ( {
2016-05-25 02:45:22 +00:00
tagName : 'tr' ,
template : _ . template ( $ ( '#trash-library-item-tmpl' ) . html ( ) ) ,
events : {
'click .repo-delete-btn' : 'deleteTrashLibrary' ,
2016-06-07 09:32:01 +00:00
'click .repo-restore-btn' : 'restoreTrashLibrary'
2016-05-25 02:45:22 +00:00
} ,
initialize : function ( ) {
HLItemView . prototype . initialize . call ( this ) ;
} ,
deleteTrashLibrary : function ( ) {
var _this = this ;
2016-06-07 09:32:01 +00:00
var repo _name = this . model . get ( 'name' ) ;
var popupTitle = gettext ( "Delete Library" ) ;
var popupContent = gettext ( "Are you sure you want to delete %s completely?" ) . 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-trash-library' ,
'repo_id' : _this . model . get ( 'id' )
} ) ,
type : 'DELETE' ,
beforeSend : Common . prepareCSRFToken ,
dataType : 'json' ,
success : function ( ) {
_this . $el . remove ( ) ;
Common . feedback ( gettext ( "Success" ) , 'success' ) ;
} ,
error : function ( xhr , textStatus , errorThrown ) {
Common . ajaxErrorHandler ( xhr , textStatus , errorThrown ) ;
} ,
complete : function ( ) {
$ . modal . close ( ) ;
}
} ) ;
} ;
Common . showConfirm ( popupTitle , popupContent , yesCallback ) ;
2016-05-25 02:45:22 +00:00
return false ;
} ,
restoreTrashLibrary : function ( ) {
var _this = this ;
2016-06-07 09:32:01 +00:00
var repo _name = this . model . get ( 'name' ) ;
var popupTitle = gettext ( "Restore Library" ) ;
var popupContent = gettext ( "Are you sure you want to restore %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-trash-library' ,
'repo_id' : _this . model . get ( 'id' )
} ) ,
type : 'PUT' ,
beforeSend : Common . prepareCSRFToken ,
dataType : 'json' ,
success : function ( ) {
_this . $el . remove ( ) ;
Common . feedback ( gettext ( "Success" ) , 'success' ) ;
} ,
error : function ( xhr , textStatus , errorThrown ) {
Common . ajaxErrorHandler ( xhr , textStatus , errorThrown ) ;
} ,
complete : function ( ) {
$ . modal . close ( ) ;
}
} ) ;
} ;
Common . showConfirm ( popupTitle , popupContent , yesCallback ) ;
2016-05-25 02:45:22 +00:00
return false ;
} ,
render : function ( ) {
var data = this . model . toJSON ( ) ,
2017-07-31 09:30:43 +00:00
icon _size = Common . isHiDPI ( ) ? 48 : 24 ,
2016-05-27 08:42:40 +00:00
icon _url = this . model . getIconUrl ( icon _size ) ,
2016-05-25 02:45:22 +00:00
delete _time = Moment ( data [ 'delete_time' ] ) ;
2016-05-27 08:42:40 +00:00
data [ 'icon_url' ] = icon _url ;
data [ 'icon_title' ] = this . model . getIconTitle ( ) ;
2016-05-25 02:45:22 +00:00
data [ 'time' ] = delete _time . format ( 'LLLL' ) ;
data [ 'time_from_now' ] = Common . getRelativeTimeStr ( delete _time ) ;
this . $el . html ( this . template ( data ) ) ;
return this ;
}
} ) ;
2016-05-27 08:42:40 +00:00
return TrashRepoView ;
2016-05-25 02:45:22 +00:00
} ) ;