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.

преди 12 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // for license information please see license.txt
  2. wn.provide("wn.ui.form")
  3. wn.ui.form.LinkedWith = Class.extend({
  4. init: function(opts) {
  5. var me = this;
  6. $.extend(this, opts);
  7. },
  8. show: function() {
  9. if(!this.dialog)
  10. this.make_dialog();
  11. this.dialog.show();
  12. this.dialog.get_input("list_by").change();
  13. },
  14. make_dialog: function() {
  15. var me = this;
  16. this.linked_with = this.frm.meta.__linked_with;
  17. var links = $.map(keys(this.linked_with), function(v) {
  18. return in_list(wn.boot.profile.can_get_report, v) ? {value:v, label:wn._(v)} : null
  19. }).sort(function(a, b) { return a.label > b.label ? 1 : -1 });
  20. this.dialog = new wn.ui.Dialog({
  21. width: 640,
  22. title: wn._("Linked With"),
  23. fields: [
  24. { fieldtype: "HTML", label: "help",
  25. options:"<div class='help'>" + wn._("List of records in which this document is linked")
  26. +"</div>" },
  27. { fieldtype: "Select", options: links,
  28. label: wn._("Type"), fieldname: "list_by" },
  29. { fieldtype: "HTML", label: "hr", options:"<hr>" },
  30. { fieldtype: "HTML", label: "list" }
  31. ]
  32. });
  33. this.dialog.get_input("list_by").val(links[0].value);
  34. if(!links) {
  35. this.dialog.fields_dict.list.$wrapper.html("<div class='alert'>"
  36. + this.frm.doctype + ": "
  37. + (this.linked_with ? wn._("Not Linked to any record.") : wn._("Not enough permission to see links."))
  38. + "</div>")
  39. this.dialog.fields_dict.list_by.$wrapper.toggle(false);
  40. this.dialog.fields_dict.help.$wrapper.toggle(false);
  41. return;
  42. }
  43. this.dialog.get_input("list_by").change(function() {
  44. me.doctype = me.dialog.get_input("list_by").val();
  45. me.is_table = (!in_list(wn.boot.profile.can_read, me.doctype) &&
  46. in_list(wn.boot.profile.can_get_report, me.doctype))
  47. wn.model.with_doctype(me.doctype, function(r) {
  48. me.make_listing();
  49. me.lst.run();
  50. })
  51. })
  52. },
  53. make_listing: function() {
  54. var me = this;
  55. this.lst = new wn.ui.Listing({
  56. hide_refresh: true,
  57. no_loading: true,
  58. no_toolbar: true,
  59. doctype: me.doctype,
  60. show_filters: true,
  61. parent: $(this.dialog.fields_dict.list.wrapper).empty().css("min-height", "300px")
  62. .get(0),
  63. method: 'webnotes.widgets.reportview.get',
  64. get_args: function() {
  65. return {
  66. doctype: me.doctype,
  67. fields: [ '`tab' + me.doctype + '`.name',
  68. '`tab' + me.doctype + '`.modified',
  69. '`tab' + me.doctype + '`.modified_by',
  70. '`tab' + me.doctype + '`.docstatus'],
  71. filters: me.lst.filter_list.get_filters(),
  72. docstatus: ['0','1']
  73. }
  74. },
  75. render_row: function(parent, data) {
  76. $(parent).html(repl('%(avatar)s \
  77. <a href="#Form/%(doctype)s/%(name)s" onclick="cur_dialog.hide()">\
  78. %(doctype)s: %(name)s</a>\
  79. <span class="help">Last Updated: %(modified)s</span>', {
  80. avatar: wn.avatar(data.modified_by, null,
  81. "Last Modified By: " + wn.user_info(data.modified_by).fullname),
  82. doctype: me.is_table ? data.parenttype : me.doctype,
  83. modified: dateutil.comment_when(data.modified),
  84. name: me.is_table ? data.parent : data.name
  85. })).find('.avatar img').centerImage();
  86. },
  87. get_no_result_message: function() {
  88. return repl("<div class='alert'>%(doctype)s: " + wn._("Not linked") + "</div>", {
  89. name: me.frm.doc.name,
  90. doctype: wn._(me.doctype)
  91. })
  92. }
  93. });
  94. me.lst.filter_list.show_filters(true);
  95. me.lst.filter_list.clear_filters();
  96. me.lst.set_filter(me.linked_with[me.doctype], me.frm.doc.name);
  97. }
  98. });