question.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup Feedback Feedback
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. function BxFdbQuestion(oOptions) {
  11. this._sActionsUrl = oOptions.sActionUrl;
  12. this._sObjName = oOptions.sObjName == undefined ? 'oBxFdbQuestion' : oOptions.sObjName;
  13. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'slide' : oOptions.sAnimationEffect;
  14. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  15. this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
  16. this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;
  17. }
  18. BxFdbQuestion.prototype.answerOnSelect = function(oElement, iQuestion) {
  19. var $this = this;
  20. var fOnOk = function(oPopup) {
  21. var oParams = jQuery.extend({}, $this._getDefaultParams(), {
  22. question_id: iQuestion,
  23. answer_id: $(oElement).val(),
  24. text: $(oPopup).find("input[type = 'text']").val()
  25. });
  26. $.get(
  27. $this._sActionsUrl + 'answer/',
  28. oParams,
  29. function(oData){
  30. processJsonData(oData);
  31. },
  32. 'json'
  33. );
  34. };
  35. bx_prompt(_t('_bx_feedback_txt_enter_text'), '', fOnOk);
  36. };
  37. /**
  38. * Methods for 'Answers' custom field.
  39. */
  40. /*
  41. BxFdbQuestion.prototype.answerOnType = function(oEvent, sName) {
  42. var oParent = $(oEvent.target).parents('.bx-form-input-answer:first');
  43. oParent.find("input[type = 'checkbox']").val(oParent.find("input[name = '" + sName + "']").val().trim());
  44. };
  45. */
  46. BxFdbQuestion.prototype.answerAdd = function(oButton, sName) {
  47. var oField = $(oButton).parents('#bx-form-element-' + sName);
  48. var oIndex = oField.find("input[type = 'hidden'][name = '" + sName + "_ind']");
  49. var iIndex = oIndex.val();
  50. var sSample = oField.find('.bx-form-input-answer-sample:first').html().replace(/\|x\|/g, iIndex);
  51. oField.find('.bx-form-input-answer:last').after($(sSample));
  52. oIndex.val(parseInt(iIndex) + 1);
  53. };
  54. BxFdbQuestion.prototype.answerDelete = function(oButton) {
  55. $(oButton).parents('.bx-form-input-answer:first').remove();
  56. };
  57. /**
  58. * Internal methods.
  59. */
  60. BxFdbQuestion.prototype._getDefaultParams = function() {
  61. var oDate = new Date();
  62. return {_t:oDate.getTime()};
  63. };