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