src/cm/media/js/client/f_printDialog.js
author gibus
Thu, 24 May 2012 14:42:22 +0200
changeset 443 cacd524f5279
parent 434 734c135fb553
child 444 9246b0057a75
permissions -rw-r--r--
Adds export to epub.
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)')},
443
cacd524f5279 Adds export to epub.
gibus
parents: 434
diff changeset
    12
            {'actions':['print', 'export'], 'extension':'docx', 'label': gettext('download microsoft word 2007 file (.docx)')},
cacd524f5279 Adds export to epub.
gibus
parents: 434
diff changeset
    13
            {'actions':['print', 'export'], 'extension':'epub', 'label': gettext('download ebook (.epub)')}] ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    14
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    15
190
faf3a87a7d73 minor FIX : export dialog : wrong 'choose file format' label
rbernard
parents: 0
diff changeset
    16
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
    17
      '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
    18
gCurrentAction = null ; 
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    19
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    20
_populateMethod = function(withColors) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    21
  var val = $("#p_method").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    22
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    23
  $("#p_method").html("");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    24
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    25
  for (var i = 0, ilen = gFormats.length ; i < ilen ; i++) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    26
    var actions = gFormats[i]['actions'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    27
    for (var j = 0, jlen = gFormats.length ; j < jlen ; j++) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    28
      if (actions[j] == gCurrentAction)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    29
        $("<option value='" + gFormats[i]['extension'] + "'>" + gFormats[i]['label'] + "</option>").appendTo("#p_method");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    30
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    31
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    32
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    33
    $("#p_method").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    34
  else
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    35
    $("#p_method").val(gActions[gCurrentAction]['defaultMethod']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    36
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    37
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    38
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    39
_populateMarkersColorsChoice = function(withColors) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    40
  var val = $("#p_color").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    41
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    42
  $("#p_color").html("");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    43
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    44
  $("<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
    45
  $("<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
    46
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    47
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    48
    $("#p_color").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    49
  else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    50
    $("#p_color").val(gActions[gCurrentAction]['defaultWithColors']);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    51
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    52
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    53
_populateWhichComments = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    54
  var val = $("#p_comments").val();
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    55
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    56
  $("#p_comments").html("");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    57
  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
    58
  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
    59
  $("<option value='all' >" + all +"</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    60
  $("<option value='none' >" + gettext("none (0)") + "</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    61
  $("<option value='filtered' >" + currents + "</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    62
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    63
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    64
    $("#p_comments").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    65
  else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    66
    $("#p_comments").val(gActions[gCurrentAction]['defaultWhichComments']);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    67
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    68
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    69
_manageMarkersColorsChoice = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    70
  var method = $("#p_method").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    71
  var which = $("#p_comments").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    72
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    73
  var disableMarkersColorsChoice ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    74
  if (gCurrentAction == 'print') 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    75
    disableMarkersColorsChoice = ((which == 'none') || (method == 'markdown') || (method == 'html')) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    76
  if (gCurrentAction == 'export') 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    77
    disableMarkersColorsChoice = ((which == 'none') || (method == 'markdown')) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    78
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    79
  if (disableMarkersColorsChoice)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    80
    $("#p_color").val('no');
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    81
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    82
  $("#p_color").attr("disabled", disableMarkersColorsChoice);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    83
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    84
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    85
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    86
_initPrintDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    87
  $('#p_comments').add($('#p_method')).change(function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    88
    _manageMarkersColorsChoice() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    89
    _prepareOpenInNewWindow() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    90
  }) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    91
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    92
  var buttons = {} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    93
  buttons[gettext('Go !')] = function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    94
    var whichComments = $("#p_comments").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    95
    var withColor = $("#p_color").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    96
    var format = $("#p_method").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    97
    var download = (gCurrentAction == "export") ? "1" : (format == "html") ? "0" : "1" ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    98
    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
    99
    $("#print_export_form").attr('action', targetUrl) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   100
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   101
    document['print_export_form'].submit();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   102
    $(this).dialog('close');
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
  buttons[gettext('Cancel')] = function() {
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
  } ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   107
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   108
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   109
  $("#dialog_print_export").dialog({
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   110
    bgiframe: true,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   111
    autoOpen: false,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   112
    width: 450,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   113
/*    height: 300,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   114
    autoResize: false,*/    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   115
    modal: true,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   116
    buttons: buttons,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   117
    close: function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   118
      ; // empty
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   119
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   120
  });
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   121
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   122
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   123
openPrintDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   124
  _openPrintExportDialog('print') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   125
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   126
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   127
openExportDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   128
  _openPrintExportDialog('export') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   129
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   130
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   131
_prepareOpenInNewWindow = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   132
  var method = $("#p_method").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   133
  if ((method == "html") && (gCurrentAction == 'print'))
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   134
    $("#print_export_form").attr("target", "_blank") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   135
  else
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   136
    $("#print_export_form").removeAttr("target") ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   137
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   138
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   139
_openPrintExportDialog = function(action) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   140
  gCurrentAction = action ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   141
  $("#ui-dialog-title-dialog_print_export").html(gActions[gCurrentAction]['dialogTitle']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   142
  $("#how").html(gActions[gCurrentAction]['chooseFormatLabel']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   143
  $("#print_export_action").val(action) ; // TODO check this still usefull
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   144
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   145
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   146
  _populateWhichComments() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   147
  _populateMarkersColorsChoice() ;  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   148
  _populateMethod() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   149
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   150
  _manageMarkersColorsChoice() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   151
  _prepareOpenInNewWindow() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   152
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   153
  $('#dialog_print_export').dialog('open');
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   154
}
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
/*    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   157
      tips.text(t).effect("highlight",{},1500);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   158
*/