src/cm/media/js/site/text_edit.js
changeset 66 7842b011403a
child 103 61fd17f9ab78
equal deleted inserted replaced
64:d0478be65c29 66:7842b011403a
       
     1 function check_save(){
       
     2     needToConfirm = false;
       
     3 
       
     4     var newVersion = $('#id_new_version').attr('checked') ;
       
     5     var commentsKept = $('#id_keep_comments').attr('checked') ;
       
     6 
       
     7     var new_content = $('#id_content').val()
       
     8     var new_format = $('#id_format').val()
       
     9     
       
    10     if (commentsKept) {
       
    11         var pre_edit_url = tb_conf['pre_edit_url'] ;
       
    12 
       
    13         $.ajax({
       
    14            url: pre_edit_url,
       
    15            type:'POST',
       
    16            dataType:"json",
       
    17            data: { "new_content": new_content,  "new_format": new_format},
       
    18            success: function(obj){
       
    19                nb_removed = obj['nb_removed'];
       
    20                if (newVersion) {
       
    21                     if (nb_removed == 0) {
       
    22                         $('#edit_form').submit();
       
    23                     }
       
    24                     else {
       
    25                 		var message = ngettext( 
       
    26                 				'%(nb_comments)s comment will be removed because the text it applies to has been changed.',
       
    27                 				'%(nb_comments)s comments will be removed because the text they apply to has been changed.', 
       
    28 								nb_removed) ;
       
    29                 		message += '<br />' ;
       
    30                 		message += gettext( 'Do you want to continue?') ;
       
    31                 		message = interpolate(message,{'nb_comments':nb_removed}, true) ;		
       
    32                 		
       
    33                         $('#check_save_dialog').html(message) ;
       
    34                         $('#check_save_dialog').dialog('open') ;
       
    35                     }
       
    36                }
       
    37                else {                  
       
    38                    if (nb_removed == 0) {
       
    39                         $('#edit_form').submit();
       
    40                     }
       
    41                    else {
       
    42 	               		var message = ngettext(  
       
    43 	               				'%(nb_comments)s comment will be lost because the text it applies to has been changed.',
       
    44 	               				'%(nb_comments)s comments will be lost because the text they apply to has been changed.',	               								
       
    45 								nb_removed) ;
       
    46                 		message += '<br />' ;
       
    47                 		message += gettext( '(We suggest you create a new version)') ;
       
    48                 		message += '<br />' ;
       
    49                 		message += gettext( 'Do you want to continue?') ;
       
    50                 		message = interpolate(message,{'nb_comments':nb_removed}, true) ;		
       
    51 
       
    52                  		$('#check_save_dialog').html(message) ;
       
    53                         $('#check_save_dialog').dialog('open') ;
       
    54                    }
       
    55                }
       
    56            },
       
    57            error: function(msg){
       
    58                alert("error: " + msg);
       
    59            }
       
    60         });
       
    61     }
       
    62     else {
       
    63         if (!newVersion) {
       
    64                 var message = gettext("Since you chose not to create a new version all comments will be deleted") ;
       
    65         		message += '<br />' ;
       
    66         		message += gettext( 'Do you want to continue?') ;
       
    67                 $('#check_save_dialog').html(message) ;
       
    68                 $('#check_save_dialog').dialog('open') ;
       
    69         }
       
    70         else {
       
    71             $('#edit_form').submit();
       
    72         }
       
    73     }
       
    74 }
       
    75 
       
    76 $(function() {
       
    77 	var buttons = {};
       
    78 	buttons[gettext('No')] = function() {$(this).dialog('close');} ;
       
    79 	buttons[gettext('Yes')] = function() {$(this).dialog('close');$('#edit_form').submit();} ;
       
    80 
       
    81     $('#check_save_dialog').dialog({
       
    82         bgiframe: true, 
       
    83         autoOpen: false,        
       
    84         title :gettext('Warning'),
       
    85         modal: true,
       
    86         buttons:buttons
       
    87     }) ;
       
    88     
       
    89     $("#save").click(function() { check_save() ;}) ;
       
    90 }) ;