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