src/cm/media/js/client/f_printDialog.js
author Production Moz <dev@sopinspace.com>
Wed, 04 Sep 2013 22:11:01 +0200
changeset 529 5eeed336b992
parent 467 47f54d0c46dd
child 565 95a5c06c4008
permissions -rw-r--r--
Filter by category should also be tested for undefined (and not just empty string) in case no category has been defined.
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)')},
467
47f54d0c46dd Stupid IE counts extra element in array when ending by a comma.
gibus
parents: 455
diff changeset
    13
            {'actions':['export'], 'extension':'docx', 'label': gettext('download microsoft word 2007 file (.docx)')}
454
b7a092a52eae Cleaned export.
gibus
parents: 453
diff changeset
    14
            ];
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
454
b7a092a52eae Cleaned export.
gibus
parents: 453
diff changeset
    21
gFormats.push({'actions':['export'], 'extension':'xml', 'label': gettext('download XML file for re-importing text and comments')});
b7a092a52eae Cleaned export.
gibus
parents: 453
diff changeset
    22
190
faf3a87a7d73 minor FIX : export dialog : wrong 'choose file format' label
rbernard
parents: 0
diff changeset
    23
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
    24
      '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
    25
gCurrentAction = null ; 
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    26
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    27
_populateMethod = function(withColors) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    28
  var val = $("#p_method").val();
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
  $("#p_method").html("");
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
  for (var i = 0, ilen = gFormats.length ; i < ilen ; i++) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    33
    var actions = gFormats[i]['actions'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    34
    for (var j = 0, jlen = gFormats.length ; j < jlen ; j++) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    35
      if (actions[j] == gCurrentAction)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    36
        $("<option value='" + gFormats[i]['extension'] + "'>" + gFormats[i]['label'] + "</option>").appendTo("#p_method");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    37
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    38
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    39
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    40
    $("#p_method").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    41
  else
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    42
    $("#p_method").val(gActions[gCurrentAction]['defaultMethod']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    43
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    44
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    45
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    46
_populateMarkersColorsChoice = function(withColors) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    47
  var val = $("#p_color").val();
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
  $("#p_color").html("");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    50
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    51
  $("<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
    52
  $("<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
    53
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    54
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    55
    $("#p_color").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    56
  else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    57
    $("#p_color").val(gActions[gCurrentAction]['defaultWithColors']);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    58
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    59
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    60
_populateWhichComments = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    61
  var val = $("#p_comments").val();
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    62
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    63
  $("#p_comments").html("");
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    64
  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
    65
  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
    66
  $("<option value='all' >" + all +"</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    67
  $("<option value='none' >" + gettext("none (0)") + "</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    68
  $("<option value='filtered' >" + currents + "</option>").appendTo($("#p_comments")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    69
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    70
  if (val)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    71
    $("#p_comments").val(val);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    72
  else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    73
    $("#p_comments").val(gActions[gCurrentAction]['defaultWhichComments']);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    74
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    75
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    76
_manageMarkersColorsChoice = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    77
  var method = $("#p_method").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    78
  var which = $("#p_comments").val();
454
b7a092a52eae Cleaned export.
gibus
parents: 453
diff changeset
    79
  var all = frames['text_view_comments'].gDb.getCommentsNb(true);
b7a092a52eae Cleaned export.
gibus
parents: 453
diff changeset
    80
  var currents = frames['text_view_comments'].gDb.getCommentsNb(false);
b7a092a52eae Cleaned export.
gibus
parents: 453
diff changeset
    81
  var nb_comments = (which == 'all') ? all : currents;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    82
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    83
  var disableMarkersColorsChoice ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    84
  if (gCurrentAction == 'print') 
454
b7a092a52eae Cleaned export.
gibus
parents: 453
diff changeset
    85
    disableMarkersColorsChoice = ((nb_comments == 0) || (which == 'none'));
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    86
  if (gCurrentAction == 'export') 
455
33c7e20efcb7 Added export of attachements as inline b64 images for appropriate formats.
gibus
parents: 454
diff changeset
    87
    // No colors for:
33c7e20efcb7 Added export of attachements as inline b64 images for appropriate formats.
gibus
parents: 454
diff changeset
    88
    // 1. no comments
33c7e20efcb7 Added export of attachements as inline b64 images for appropriate formats.
gibus
parents: 454
diff changeset
    89
    // 2. pandoc generated formats (markdown, latex, epub)
33c7e20efcb7 Added export of attachements as inline b64 images for appropriate formats.
gibus
parents: 454
diff changeset
    90
    // 3. odt and doc, for some reasons abiword cannot export background-color for these formats
33c7e20efcb7 Added export of attachements as inline b64 images for appropriate formats.
gibus
parents: 454
diff changeset
    91
    // 4. XML export (used for re-import)
33c7e20efcb7 Added export of attachements as inline b64 images for appropriate formats.
gibus
parents: 454
diff changeset
    92
    disableMarkersColorsChoice = ((nb_comments == 0) || (which == 'none') || (method == 'markdown') || (method == 'latex') || (method == 'epub') || (method == 'odt') || (method == 'doc') || (method == 'xml')) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    93
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    94
  if (disableMarkersColorsChoice)
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    95
    $("#p_color").val('no');
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
  $("#p_color").attr("disabled", disableMarkersColorsChoice);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
    98
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    99
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   100
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   101
_initPrintDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   102
  $('#p_comments').add($('#p_method')).change(function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   103
    _manageMarkersColorsChoice() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   104
    _prepareOpenInNewWindow() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   105
  }) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   106
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   107
  var buttons = {} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   108
  buttons[gettext('Go !')] = function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   109
    var whichComments = $("#p_comments").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   110
    var withColor = $("#p_color").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   111
    var format = $("#p_method").val() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   112
    var download = (gCurrentAction == "export") ? "1" : (format == "html") ? "0" : "1" ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   113
    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
   114
    $("#print_export_form").attr('action', targetUrl) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   115
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   116
    document['print_export_form'].submit();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   117
    $(this).dialog('close');
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   118
  } ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   119
  buttons[gettext('Cancel')] = function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   120
    $(this).dialog('close');
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   121
  } ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   122
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   123
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   124
  $("#dialog_print_export").dialog({
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   125
    bgiframe: true,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   126
    autoOpen: false,
454
b7a092a52eae Cleaned export.
gibus
parents: 453
diff changeset
   127
    width: 500,
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   128
/*    height: 300,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   129
    autoResize: false,*/    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   130
    modal: true,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   131
    buttons: buttons,
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   132
    close: function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   133
      ; // empty
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   134
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   135
  });
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   136
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   137
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   138
openPrintDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   139
  _openPrintExportDialog('print') ;
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
openExportDialog = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   143
  _openPrintExportDialog('export') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   144
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   145
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   146
_prepareOpenInNewWindow = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   147
  var method = $("#p_method").val();
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   148
  if ((method == "html") && (gCurrentAction == 'print'))
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   149
    $("#print_export_form").attr("target", "_blank") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   150
  else
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   151
    $("#print_export_form").removeAttr("target") ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   152
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   153
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   154
_openPrintExportDialog = function(action) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   155
  gCurrentAction = action ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   156
  $("#ui-dialog-title-dialog_print_export").html(gActions[gCurrentAction]['dialogTitle']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   157
  $("#how").html(gActions[gCurrentAction]['chooseFormatLabel']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   158
  $("#print_export_action").val(action) ; // TODO check this still usefull
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
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   161
  _populateWhichComments() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   162
  _populateMarkersColorsChoice() ;  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   163
  _populateMethod() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   164
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   165
  _manageMarkersColorsChoice() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   166
  _prepareOpenInNewWindow() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   167
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   168
  $('#dialog_print_export').dialog('open');
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   169
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   170
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   171
/*    
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   172
      tips.text(t).effect("highlight",{},1500);
053551f213fb Coding style for js: expand tabs
gibus
parents: 191
diff changeset
   173
*/