לדלג לתוכן

מדיה ויקי:Gadget-feedback.js

מתוך המכלול, האנציקלופדיה היהודית

לתשומת ליבך: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
//<nowiki>
var api = new mw.Api();
mw.messages.set({
  "feedback-dialog-title": "דיווח על בעיות תוכן",
  "feedback-help-message":
    'בדיווח על תוכן או מדיה לא ראויים סמנו את האפשרות "תוכן בלתי הולם". נא להימנע מציטוט ישיר של טקסט בעייתי, במקום זאת ציינו את שם הפסקה או צטטו את תחילת המשפט',
});

function ProcessDialog(config) {
  ProcessDialog.super.call(this, config);
}
OO.inheritClass(ProcessDialog, OO.ui.ProcessDialog);

ProcessDialog.static.name = "mwFeedbackDialog";
ProcessDialog.static.title = "דיווח על בעיות תוכן";
ProcessDialog.static.size = "medium";
ProcessDialog.static.actions = [
  {
    action: "submit",
    label: "שלח",
    flags: ["primary", "progressive"],
  },
  {
    action: "cancel",
    label: "ביטול",
    flags: "safe",
  },
];

ProcessDialog.prototype.initialize = function () {
  ProcessDialog.super.prototype.initialize.apply(this, arguments);

  this.panel = new OO.ui.PanelLayout({
    scrollable: false,
    expanded: false,
    padded: true,
  });

  this.input = new OO.ui.MultilineTextInputWidget({
    autosize: true,
    required: true,
  });

  this.contentLabel = new OO.ui.FieldLayout(this.input, {
    label: "תוכן הדיווח:",
    align: "top",
    help: mw.msg("feedback-help-message"),
  });

  this.notWorthyOption = new OO.ui.RadioOptionWidget({
    data: "דיווח על תוכן בלתי הולם",
    label: "תוכן בלתי הולם",
    selected: true,
  });
  this.mistakeOption = new OO.ui.RadioOptionWidget({
    data: "דיווח על טעויות",
    label: "טעות",
  });
  this.selectOption = new OO.ui.RadioSelectWidget({
    name: "rating",
    items: [this.notWorthyOption, this.mistakeOption],
  });

  this.selectLabel = new OO.ui.FieldLayout(this.selectOption, {
    label: "בחרו סוג דיווח:",
    align: "top",
  });

  this.panel.$element.append(
    this.contentLabel.$element,
    this.selectLabel.$element
  );
  this.input.connect(this, { change: "validate" });
  this.$body.append(this.panel.$element);
};

 ProcessDialog.prototype.validate = function (value) {
  this.actions.setAbilities({ submit: value.length > 0 });
}; 

ProcessDialog.prototype.getBodyHeight = function () {
  return this.panel.$element.outerHeight(true);
};

ProcessDialog.prototype.getSetupProcess = function (data) {
  return ProcessDialog.super.prototype.getSetupProcess
    .call(this, data)
    .next(function () {
      this.actions.setAbilities({ submit: false });
    }, this);
};

ProcessDialog.prototype.getActionProcess = function (action) {
  if (action === "cancel") {
    return new OO.ui.Process(function () {
      this.close();
    }, this);
  } else if (action === "submit") {
    return new OO.ui.Process(function () {
      this.actions.setAbilities({ submit: false });
      var dialog = this;
      var text = dialog.input.getValue();
      var rating = dialog.selectOption.findSelectedItem().data;
      if (rating === "דיווח על תוכן בלתי הולם") {
        text = "{{משוב}}\n" + text;
	  }
      text = "{{מצב|חדש}}\n" + text + " ~~~~";
      return api
        .newSection(
          "המכלול:" + rating,
          "[[" + mw.config.get("wgPageName").replace(/_/g, " ") + "]]",
          text,
          { bot: true }
        )
        .done(function (data) {
          if (data.edit.result === "Success") {
            dialog.close();
            mw.notify("הדיווח נשלח בהצלחה", { type: "success" });
          } else {
            dialog.actions.setAbilities({ submit: true });
            mw.notify("הדיווח לא נשלח", { type: "error" });
          }
        })
        .fail(function (error) {
          dialog.actions.setAbilities({ submit: true });
          console.log(error);
          mw.notify("הדיווח לא נשלח", { type: "error" });
        });
    }, this);
  }
  return ProcessDialog.super.prototype.getActionProcess.call(this, action);
};

if (mw.config.get("wgNamespaceNumber") === 0) {
  var buttonFeedback = new OO.ui.ButtonWidget({
    id: "buttonFeedback",
    icon: "speechBubble",
    flags: "progressive",
    title: "דיווח על בעיות בתוכן הערך",
  });
  var container = $(".mw-page-container-inner")[0] || $(".mw-body")[0];
  buttonFeedback.$element.appendTo(container).click(function () {
    var windowManager = new OO.ui.WindowManager();
    $(document.body).append(windowManager.$element);

    // Create a new dialog window.
    var processDialog = new ProcessDialog();

    // Add windows to window manager using the addWindows() method.
    windowManager.addWindows([processDialog]);

    // Open the window.
    windowManager.openWindow(processDialog);
  });
}
//</nowiki>