src/cm/media/js/client/f_printDialog.js
author gibus
Thu, 24 May 2012 15:59:12 +0200
changeset 444 9246b0057a75
parent 443 cacd524f5279
child 453 1d314f629611
permissions -rw-r--r--
Exports to epub only with pandoc 1.9 and upper versions.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
//http://jqueryui.com/demos/dialog/modal-form.html
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     3
// TODO ? : get from the server 
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     4
// extension : label 
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     5
gFormats = [{'actions':['print'], 'extension':'html', 'label': gettext('print from the browser')},
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     6
            {'actions':['export'], 'extension':'html', 'label': gettext('download html file (.html)')},
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     7
            {'actions':['print', 'export'], 'extension':'markdown', 'label': gettext('download markdown file (.mkd)')},
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     8
            {'actions':['print', 'export'], 'extension':'pdf', 'label': gettext('download portable object format file (.pdf)')},
191
c6e4c5a996d0 BUG FIX : fix tex/latex format
rbernard
parents: 190
diff changeset
     9
            {'actions':['print', 'export'], 'extension':'latex', 'label': gettext('download latex file (.tex)')},
433
056d92bffb23 Added export in .doc and .docx formats.
gibus
parents: 341
diff changeset
    10
            {'actions':['print', 'export'], 'extension':'odt', 'label': gettext('download open document file (.odt)')},
056d92bffb23 Added export in .doc and .docx formats.
gibus
parents: 341
diff changeset
    11
            {'actions':['print', 'export'], 'extension':'doc', 'label': gettext('download microsoft word file (.doc)')},
444
9246b0057a75 Exports to epub only with pandoc 1.9 and upper versions.
gibus
parents: 443
diff changeset
    12
            {'actions':['print', 'export'], 'extension':'docx', 'label': gettext('download microsoft word 2007 file (.docx)')}];
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    13
444
9246b0057a75 Exports to epub only with pandoc 1.9 and upper versions.
gibus
parents: 443
diff changeset
    14
var pandoc_version_ary = sv_pandoc_version.split('.');
9246b0057a75 Exports to epub only with pandoc 1.9 and upper versions.
gibus
parents: 443
diff changeset
    15
if (parseInt(pandoc_version_ary[0]) > 1 || (parseInt(pandoc_version_ary[0]) == 1 && parseInt(pandoc_version_ary[1]) > 8)) {
9246b0057a75 Exports to epub only with pandoc 1.9 and upper versions.
gibus
parents: 443
diff changeset
    16
  gFormats.push({'actions':['print', 'export'], 'extension':'epub', 'label': gettext('download ebook (.epub)')});
9246b0057a75 Exports to epub only with pandoc 1.9 and upper versions.
gibus
parents: 443
diff changeset
    17
}
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    18
190
faf3a87a7d73 minor FIX : export dialog : wrong 'choose file format' label
rbernard
parents: 0
diff changeset
    19
gActions = {'print':{'dialogTitle':gettext('Print text'), 'chooseFormatLabel':gettext('How do you want to print?'), 'defaultMethod':'pdf', 'defaultWithColors':"no", 'defaultWhichComments':'all'}, 
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    20
      'export':{'dialogTitle':gettext('Export text'), 'chooseFormatLabel':gettext('Choose file format'), 'defaultMethod':'pdf', 'defaultWithColors':"no", 'defaultWhichComments':'all'}} ; 
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    21
gCurrentAction = null ; 
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    22
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    23
_populateMethod = function(withColors) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    24
  var val = $("#p_method").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    25
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    26
  $("#p_method").html("");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    27
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    28
  for (var i = 0, ilen = gFormats.length ; i < ilen ; i++) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    29
    var actions = gFormats[i]['actions'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    30
    for (var j = 0, jlen = gFormats.length ; j < jlen ; j++) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    31
      if (actions[j] == gCurrentAction)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    32
        $("<option value='" + gFormats[i]['extension'] + "'>" + gFormats[i]['label'] + "</option>").appendTo("#p_method");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    33
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    34
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    35
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    36
    $("#p_method").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    37
  else
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    38
    $("#p_method").val(gActions[gCurrentAction]['defaultMethod']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    39
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    40
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    41
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    42
_populateMarkersColorsChoice = function(withColors) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    43
  var val = $("#p_color").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    44
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    45
  $("#p_color").html("");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    46
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    47
  $("<option value='0'>" + gettext("using markers only, no background colors") + "</option>").appendTo("#p_color");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    48
  $("<option value='1'>" + gettext("using markers and background colors") + "</option>").appendTo("#p_color");
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    49
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    50
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    51
    $("#p_color").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    52
  else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    53
    $("#p_color").val(gActions[gCurrentAction]['defaultWithColors']);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    54
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    55
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    56
_populateWhichComments = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    57
  var val = $("#p_comments").val();
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    58
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    59
  $("#p_comments").html("");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    60
  var all = interpolate(gettext("all (%(nb_comments)s)"), {'nb_comments':frames['text_view_comments'].gDb.getCommentsNb(true)}, true) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    61
  var currents = interpolate(gettext("current filtered ones (%(nb_comments)s)"), {'nb_comments':frames['text_view_comments'].gDb.getCommentsNb(false)}, true) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    62
  $("<option value='all' >" + all +"</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    63
  $("<option value='none' >" + gettext("none (0)") + "</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    64
  $("<option value='filtered' >" + currents + "</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    65
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    66
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    67
    $("#p_comments").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    68
  else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    69
    $("#p_comments").val(gActions[gCurrentAction]['defaultWhichComments']);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    70
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    71
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    72
_manageMarkersColorsChoice = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    73
  var method = $("#p_method").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    74
  var which = $("#p_comments").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    75
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    76
  var disableMarkersColorsChoice ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    77
  if (gCurrentAction == 'print') 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    78
    disableMarkersColorsChoice = ((which == 'none') || (method == 'markdown') || (method == 'html')) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    79
  if (gCurrentAction == 'export') 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    80
    disableMarkersColorsChoice = ((which == 'none') || (method == 'markdown')) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    81
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    82
  if (disableMarkersColorsChoice)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    83
    $("#p_color").val('no');
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    84
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    85
  $("#p_color").attr("disabled", disableMarkersColorsChoice);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    86
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    87
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    88
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    89
_initPrintDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    90
  $('#p_comments').add($('#p_method')).change(function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    91
    _manageMarkersColorsChoice() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    92
    _prepareOpenInNewWindow() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    93
  }) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    94
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    95
  var buttons = {} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    96
  buttons[gettext('Go !')] = function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    97
    var whichComments = $("#p_comments").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    98
    var withColor = $("#p_color").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    99
    var format = $("#p_method").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   100
    var download = (gCurrentAction == "export") ? "1" : (format == "html") ? "0" : "1" ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   101
    var targetUrl = $("#print_export_form").attr('target_action').replace(/FoRmAt/,format).replace(/DoWnLoAd/, download).replace(/WhIcHCoMmEnT/, whichComments).replace(/WiThCoLoR/, withColor) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   102
    $("#print_export_form").attr('action', targetUrl) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   103
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   104
    document['print_export_form'].submit();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   105
    $(this).dialog('close');
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   106
  } ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   107
  buttons[gettext('Cancel')] = function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   108
    $(this).dialog('close');
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   109
  } ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   110
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   111
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   112
  $("#dialog_print_export").dialog({
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   113
    bgiframe: true,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   114
    autoOpen: false,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   115
    width: 450,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   116
/*    height: 300,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   117
    autoResize: false,*/    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   118
    modal: true,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   119
    buttons: buttons,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   120
    close: function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   121
      ; // empty
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   122
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   123
  });
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   124
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   125
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   126
openPrintDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   127
  _openPrintExportDialog('print') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   128
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   129
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   130
openExportDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   131
  _openPrintExportDialog('export') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   132
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   133
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   134
_prepareOpenInNewWindow = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   135
  var method = $("#p_method").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   136
  if ((method == "html") && (gCurrentAction == 'print'))
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   137
    $("#print_export_form").attr("target", "_blank") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   138
  else
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   139
    $("#print_export_form").removeAttr("target") ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   140
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   141
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   142
_openPrintExportDialog = function(action) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   143
  gCurrentAction = action ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   144
  $("#ui-dialog-title-dialog_print_export").html(gActions[gCurrentAction]['dialogTitle']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   145
  $("#how").html(gActions[gCurrentAction]['chooseFormatLabel']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   146
  $("#print_export_action").val(action) ; // TODO check this still usefull
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   147
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   148
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   149
  _populateWhichComments() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   150
  _populateMarkersColorsChoice() ;  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   151
  _populateMethod() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   152
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   153
  _manageMarkersColorsChoice() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   154
  _prepareOpenInNewWindow() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   155
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   156
  $('#dialog_print_export').dialog('open');
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   157
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   158
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   159
/*    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   160
      tips.text(t).effect("highlight",{},1500);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   161
*/