You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.4 KiB

  1. wn.downloadify = function(data, roles, me) {
  2. if(roles && roles.length && !has_common(roles, user_roles)) {
  3. msgprint("Export not allowed. You need " + wn.utils.comma_or(roles)
  4. + " Role to export.");
  5. return;
  6. }
  7. wn.require("lib/js/lib/downloadify/downloadify.min.js");
  8. wn.require("lib/js/lib/downloadify/swfobject.js");
  9. var id = wn.dom.set_unique_id();
  10. var msgobj = msgprint('<p id="'+ id +'">You must have Flash 10 installed to \
  11. download this file.</p>');
  12. Downloadify.create(id ,{
  13. filename: function(){
  14. return me.title + '.csv';
  15. },
  16. data: function(){
  17. return wn.to_csv(data);
  18. },
  19. swf: 'lib/js/lib/downloadify/downloadify.swf',
  20. downloadImage: 'lib/js/lib/downloadify/download.png',
  21. onComplete: function(){ msgobj.hide(); },
  22. onCancel: function(){ msgobj.hide(); },
  23. onError: function(){ msgobj.hide(); },
  24. width: 100,
  25. height: 30,
  26. transparent: true,
  27. append: false
  28. });
  29. }
  30. wn.to_csv = function(data) {
  31. var res = [];
  32. $.each(data, function(i, row) {
  33. row = $.map(row, function(col) {
  34. return typeof(col)==="string" ? ('"' + col.replace(/"/g, '\"') + '"') : col;
  35. });
  36. res.push(row.join(","));
  37. });
  38. return res.join("\n");
  39. }
  40. wn.slickgrid_tools = {
  41. get_view_data: function(columns, dataView, filter) {
  42. var col_row = $.map(columns, function(v) { return v.name; });
  43. var res = [];
  44. var col_map = $.map(columns, function(v) { return v.field; });
  45. for (var i=0, len=dataView.getLength(); i<len; i++) {
  46. var d = dataView.getItem(i);
  47. var row = [];
  48. $.each(col_map, function(i, col) {
  49. var val = d[col];
  50. if(val===null || val===undefined) {
  51. val = "";
  52. }
  53. row.push(val);
  54. });
  55. if(!filter || filter(row, d)) {
  56. res.push(row);
  57. }
  58. }
  59. return [col_row].concat(res);
  60. },
  61. add_property_setter_on_resize: function(grid) {
  62. grid.onColumnsResized.subscribe(function(e, args) {
  63. $.each(grid.getColumns(), function(i, col) {
  64. if(col.docfield && col.previousWidth != col.width &&
  65. !in_list(wn.model.std_fields_list, col.docfield.fieldname) ) {
  66. wn.call({
  67. method:"webnotes.client.make_width_property_setter",
  68. args: {
  69. doclist: [{
  70. doctype:'Property Setter',
  71. doctype_or_field: 'DocField',
  72. doc_type: col.docfield.parent,
  73. field_name: col.docfield.fieldname,
  74. property: 'width',
  75. value: col.width,
  76. "__islocal": 1
  77. }]
  78. }
  79. })
  80. col.previousWidth = col.width;
  81. col.docfield.width = col.width;
  82. }
  83. });
  84. });
  85. }
  86. }