@@ -30,6 +30,7 @@ YUI.add('ez-locationviewviewservice', function (Y) {
3030 this . on ( '*:translateContent' , this . _translateContent ) ;
3131 this . on ( '*:sortUpdate' , this . _updateSorting ) ;
3232 this . on ( '*:updatePriority' , this . _updatePriority ) ;
33+ this . on ( '*:deleteTranslation' , this . _confirmDeleteTranslation ) ;
3334 this . after ( '*:requestChange' , this . _setLanguageCode ) ;
3435
3536 this . _setLanguageCode ( ) ;
@@ -568,6 +569,74 @@ YUI.add('ez-locationviewviewservice', function (Y) {
568569 this . set ( 'languageCode' , this . get ( 'request' ) . params . languageCode ) ;
569570 } ,
570571
572+ /**
573+ * Removes translation from content.
574+ *
575+ * @method _deleteTranslation
576+ * @protected
577+ * @param {String } languageCode
578+ */
579+ _deleteTranslation : function ( languageCode ) {
580+ var content = this . get ( 'content' ) ,
581+ options = {
582+ api : this . get ( 'capi' )
583+ } ;
584+
585+ content . removeTranslation ( options , languageCode , Y . bind ( function ( error ) {
586+ if ( error ) {
587+ this . _notify (
588+ Y . eZ . trans ( 'failed.delete.content.translation' , { language : languageCode } , 'bar' ) ,
589+ 'content-delete-translation-' + content . get ( 'id' ) , 'error' , 0
590+ ) ;
591+ return ;
592+ }
593+
594+ this . _notify (
595+ Y . eZ . trans ( 'success.delete.content.translation' , { language : languageCode } , 'bar' ) ,
596+ 'content-delete-translation-' + content . get ( 'id' ) , 'done' , 5
597+ ) ;
598+
599+ this . get ( 'app' ) . navigateTo ( 'viewLocation' , {
600+ id : this . get ( 'location' ) . get ( 'id' ) ,
601+ languageCode : content . get ( 'mainLanguageCode' )
602+ } ) ;
603+ } , this ) ) ;
604+ } ,
605+
606+ /**
607+ * `deleteTranslation` event handler,
608+ * it asks confirmation to the user before delete the translation item.
609+ *
610+ * @method _confirmDeleteTranslation
611+ * @protected
612+ * @param {Object } e event facade of the deleteAction event
613+ */
614+ _confirmDeleteTranslation : function ( e ) {
615+ var content = this . get ( 'content' ) ,
616+ languageCode = e . translation ;
617+
618+ e . preventDefault ( ) ;
619+ if ( languageCode === content . get ( 'mainLanguageCode' ) ) {
620+ this . _notify (
621+ Y . eZ . trans ( 'failed.delete.content.main.translation' , { } , 'bar' ) ,
622+ 'content-delete-translation-' + content . get ( 'id' ) , 'error' , 0
623+ ) ;
624+ } else {
625+ /**
626+ * Opens confirmation modal of deleting translation
627+ *
628+ * @event confirmBoxOpen
629+ * @param {e.config } Modal configuration
630+ */
631+ this . fire ( 'confirmBoxOpen' , {
632+ config : {
633+ title : Y . eZ . trans ( 'confirm.delete.translation' , { language : languageCode } , 'bar' ) ,
634+ confirmHandler : Y . bind ( this . _deleteTranslation , this , languageCode ) ,
635+ }
636+ } ) ;
637+ }
638+ } ,
639+
571640 _getViewParameters : function ( ) {
572641 return {
573642 content : this . get ( 'content' ) ,
0 commit comments