Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var productrating = function () {
  2.     this.ProductID = null;
  3.     this.CompanyID = null;
  4.     this.OverallRate = null;
  5.     this.OverallFeedback = null;
  6.     this.DescriptionRate = null;
  7.     this.ImageRate = null;
  8.     this.ProductDescriptionFeedback = null;
  9.     this.ProductDescriptionImages = null;
  10.     this.DeliveryRate = null;
  11.     this.OrderStateRate = null;
  12.     this.DeliveryFeedback = null;
  13.     this.DeliveryImages = null;
  14.     this.AfterSalesRate = null;
  15.     this.AfterSalesFeedback = null;
  16.     this.Isanonymous = null;
  17.     this.ID = null;
  18.     this.SaleID = null;
  19. }
  20.  
  21. var $rpwizard = function () { };
  22. $rpwizard = {
  23.     isloaded: false,
  24.     attatchmentdescription: null,
  25.     attatchmentdelivery: null,
  26.     productid: null,
  27.     companyid: null,
  28.     feedbackid: null,
  29.     saleid: null,
  30.     init: function () {
  31.         if (!this.isloaded) {
  32.             this.isloaded = true;
  33.             this.wizard.init();
  34.             this.initfileupload();
  35.             this.actions();
  36.         }
  37.     },
  38.  
  39.     initfileupload: function () {
  40.         $("#pdescription").fileupload({
  41.             //url: "/customer/Uploadcompanybrandstatus/",
  42.             url: "/customer/Uploadproductrating/",
  43.             autoUpload: !0,
  44.             change: function (e, data) {
  45.                 var size = (data.files[0].size / 1024 / 1024).toFixed(2);
  46.                 if (size > 5) {
  47.                     swal("Cancelled", "Maximum file size limit is 5 MB.", "error");
  48.                     return false;
  49.                 }
  50.                 var count = $('#ptbodydescription tr').length;
  51.                 if (count == 5) {
  52.                     swal("Cancelled", "Maximum file upload limit is 5.", "error");
  53.                     return false;
  54.                 }
  55.             },
  56.             success: function (file) {
  57.                 var attach_name = $rpwizard.attatchmentdescription;
  58.                 var seperator = ",";
  59.                 var attach = "";
  60.                 if (attach_name != "") {
  61.                     attach_name = attach_name + seperator + file;
  62.                     attach = '<a href="' + file + '" target="blank" data-lightbox="roadtrip" class="myattach"><img class="img-rounded" src="' + file + '" height="0" width="0" /></a>';
  63.                 }
  64.                 else {
  65.                     attach_name = file;
  66.                     attach = '<a href="' + file + '" target="blank" data-lightbox="roadtrip" class="myattach"><img class="img-rounded" src="' + file + '" height="0" width="0" /></a>';
  67.                 }
  68.                 $rpwizard.attatchmentdescription = attach_name;
  69.             }
  70.         }),
  71.  
  72.    $.support.cors && $.ajax({ url: "/customer/Uploadproductrating/", type: "HEAD" }).fail(function () {
  73.        $('<span class="alert alert-error"/>').text("Upload server currently unavailable - " + new Date).appendTo("#pdescription")
  74.    });
  75.  
  76.         $("#pratedelivservice").fileupload({
  77.             url: "/customer/Uploadproductrating/",
  78.             autoUpload: !0,
  79.             change: function (e, data) {
  80.                 var size = (data.files[0].size / 1024 / 1024).toFixed(2);
  81.                 if (size > 5) {
  82.                     swal("Cancelled", "Maximum file size limit is 5 MB.", "error");
  83.                     return false;
  84.                 }
  85.                 var count = $('#ptbodydelivery tr').length;
  86.                 if (count == 5) {
  87.                     swal("Cancelled", "Maximum file upload limit is 5.", "error");
  88.                     return false;
  89.                 }
  90.             },
  91.             success: function (file) {
  92.                 var attach_name = $rpwizard.attatchmentdelivery;
  93.                 var seperator = ",";
  94.                 var attach = "";
  95.                 if (attach_name != "") {
  96.                     attach_name = attach_name + seperator + file;
  97.                     attach = '<a href="' + file + '" target="blank" data-lightbox="roadtrip" class="myattach"><img class="img-rounded" src="' + file + '" height="0" width="0" /></a>';
  98.                 }
  99.                 else {
  100.                     attach_name = file;
  101.                     attach = '<a href="' + file + '" target="blank" data-lightbox="roadtrip" class="myattach"><img class="img-rounded" src="' + file + '" height="0" width="0" /></a>';
  102.                 }
  103.                 $rpwizard.attatchmentdelivery = attach_name;
  104.             }
  105.         }),
  106.  
  107.    $.support.cors && $.ajax({ url: "/customer/Uploadproductrating/", type: "HEAD" }).fail(function () {
  108.        $('<span class="alert alert-error"/>').text("Upload server currently unavailable - " + new Date).appendTo("#pratedelivservice")
  109.    });
  110.  
  111.     },
  112.  
  113.     deleteattatchment: function (img, id) {
  114.         var attach_name = null;
  115.         if (id == 'pdescription') {
  116.             attach_name = $rpwizard.attatchmentdescription.split(",");
  117.         }
  118.         else {
  119.             attach_name = $rpwizard.attatchmentdelivery.split(",");
  120.         }
  121.         var seperator = ",";
  122.         var new_attach_name = "";
  123.         var attach = "";
  124.         for (var i = 0; i < attach_name.length; i++) {
  125.             if (attach_name[i].indexOf(img) > -1) {
  126.                 // Do nothing
  127.             }
  128.             else {
  129.  
  130.                 if (new_attach_name != "") {
  131.                     new_attach_name = new_attach_name + seperator + attach_name[i];
  132.                 }
  133.                 else {
  134.                     new_attach_name = attach_name[i];
  135.                 }
  136.             }
  137.         }
  138.         if (id == 'pdescription') {
  139.             $rpwizard.attatchmentdescription = new_attach_name;
  140.             attach_name = $rpwizard.attatchmentdescription.split(",");
  141.         }
  142.         else {
  143.             $rpwizard.attatchmentdelivery = new_attach_name;
  144.         }
  145.     },
  146.  
  147.     initload: function ($productid, $companyid, $saleid, $feedbackid) {
  148.  
  149.         if (!this.isloaded) {
  150.             $rpwizard.init();
  151.             this.isloaded = true;
  152.             this.wizard.init();
  153.             this.actions();
  154.         }
  155.  
  156.         $rpwizard.reset();
  157.  
  158.         if (typeof $productid !== 'undefined') {
  159.             $rpwizard.productid = $productid;
  160.         }
  161.  
  162.         if (typeof $companyid !== 'undefined') {
  163.             $rpwizard.companyid = $companyid;
  164.         }
  165.  
  166.         if (typeof $feedbackid !== 'undefined') {
  167.             $rpwizard.feedbackid = $feedbackid;
  168.         }
  169.  
  170.         if (typeof $saleid !== 'undefined') {
  171.             $rpwizard.saleid = $saleid;
  172.         }
  173.  
  174.         if ($rpwizard.feedbackid != '') {
  175.             $commonFn.waitLoader("Please wait while loading.");
  176.             $.when($rpwizard.getfeedback()).then(function ($data) {
  177.                 $rpwizard.load($data);
  178.                 $commonFn.closeWaitLoader();
  179.                 $('#product-rating-modal').modal('show');
  180.             });
  181.         }
  182.         else {
  183.             $('#product-rating-modal').modal('show');
  184.         }
  185.  
  186.     },
  187.  
  188.     getfeedback:function(){
  189.         var dfd = $.Deferred();
  190.         $.ajax({
  191.             type: "GET",
  192.             url: "/customer/getfeedbackproduct",
  193.             data: { feedbackid: $rpwizard.feedbackid},
  194.             contentType: "application/json; charset=utf-8",
  195.             datatype: "json",
  196.             success: function (result) {
  197.                 dfd.resolve(result);
  198.                 return dfd.promise();
  199.             },
  200.             error: function (er) {
  201.                 var _er = er;
  202.  
  203.                 dfd.fail(_er);
  204.                 return dfd.promise();
  205.             }
  206.         });
  207.         return dfd.promise();
  208.     },
  209.  
  210.     load: function ($details) {
  211.         $rpwizard.feedbackid = $details.ID;
  212.         $rpwizard.saleid = $details.SaleID;
  213.         $rpwizard.productid = $details.ProductID;
  214.         $rpwizard.companyid = $details.CompanyID;
  215.  
  216.         $('#poverallrate').rating('update', $details.OverallRate).trigger('rating.change');
  217.         $('#poverallfeedback').val($details.OverallFeedback);
  218.         $('#pdescriptionrate').rating('update', $details.DeliveryRate).trigger('rating.change');
  219.         $('#pimagerate').rating('update', $details.OrderStateRate).trigger('rating.change');
  220.         $('#pdescriptionfeedback').val($details.ProductDescriptionFeedback);
  221.         $('#ptbodydescription').html();
  222.  
  223.         var $html = ''
  224.         if ($details.ProductDescriptionImages != "" && $details.ProductDescriptionImages != null) {
  225.             var $img = $details.ProductDescriptionImages.split(',');
  226.             $.each($img, function (i, $ite) {
  227.                 if ($ite != "null") {
  228.                     $html = $html + '<tr class="template-download fade in">'
  229.                     $html = $html + '<td class="name" width="30%">'
  230.                     $html = $html + '<a href="' + $ite + '" title="' + $ite.split("/").pop(-1) + '" target="_blank" data-gallery="" download="' + $ite.split("/").pop(-1) + '">' + $ite.split("/").pop(-1) + '</a>'
  231.                     $html = $html + '</td>'
  232.                     $html = $html + '<td class="size" width="40%">'
  233.                     $html = $html + '<span></span>'
  234.                     $html = $html + '</td>'
  235.                     $html = $html + '<td colspan="2"></td>'
  236.                     $html = $html + '<td class="delete" width="10%" align="right">'
  237.                     $html = $html + '<button class="btn default btn-sm" onclick="$rpwizard.deleteattatchment(\'' + $ite + '\',\'pdescription\')" data-type="" data-url="">'
  238.                     $html = $html + '<i class="fa fa-times"></i>'
  239.                     $html = $html + '</button>'
  240.                     $html = $html + '</td>'
  241.                     $html = $html + '</tr>'
  242.                 }
  243.             })
  244.         }
  245.      
  246.         $('#ptbodydescription').html($html);
  247.         $rpwizard.attatchmentdescription = $details.ProductDescriptionImages;
  248.  
  249.         $('#pdeliveryrate').rating('update', $details.DeliveryRate).trigger('rating.change');
  250.         $('#porderstaterate').rating('update', $details.OrderStateRate).trigger('rating.change');
  251.         $('#pdeliveryfeedback').val($details.DeliveryFeedback);
  252.  
  253.         $('#ptbodydelivery').html();
  254.         var $html = '';
  255.         if ($details.DeliveryImages != "" && $details.DeliveryImages != null) {
  256.             var $img = $details.DeliveryImages.split(',');
  257.             $.each($img, function (i, $ite) {
  258.                 if ($ite != "null") {
  259.                     $html = $html + '<tr class="template-download fade in">'
  260.                     $html = $html + '<td class="name" width="30%">'
  261.                     $html = $html + '<a href="' + $ite + '" title="' + $ite.split("/").pop(-1) + '" target="_blank" data-gallery="" download="' + $ite.split("/").pop(-1) + '">' + $ite.split("/").pop(-1) + '</a>'
  262.                     $html = $html + '</td>'
  263.                     $html = $html + '<td class="size" width="40%">'
  264.                     $html = $html + '<span></span>'
  265.                     $html = $html + '</td>'
  266.                     $html = $html + '<td colspan="2"></td>'
  267.                     $html = $html + '<td class="delete" width="10%" align="right">'
  268.                     $html = $html + '<button class="btn default btn-sm" onclick="$rpwizard.deleteattatchment(\'' + $ite + '\',\'ptbodydelivery\')" data-type="" data-url="">'
  269.                     $html = $html + '<i class="fa fa-times"></i>'
  270.                     $html = $html + '</button>'
  271.                     $html = $html + '</td>'
  272.                     $html = $html + '</tr>'
  273.                 }
  274.             })
  275.         }
  276.         $('#ptbodydelivery').html($html);
  277.         $rpwizard.attatchmentdelivery = $details.DeliveryImages;
  278.  
  279.        
  280.         $('#paftersalesrate').rating('update', $details.AfterSalesRate).trigger('rating.change');
  281.         $('#paftersalesfeedback').val($details.AfterSalesFeedback);
  282.  
  283.         $details.Isanonymous == true ? $('#pisanonymous').prop('checked', true) : $('#pisanonymous').prop('checked', false);
  284.        
  285.     },
  286.  
  287.     actions: function () {
  288.         $("#poverallrate").on('rating.change', function () {
  289.             $('#errpoverallrate').addnd();
  290.         });
  291.  
  292.         $("#pdescriptionrate").on('rating.change', function () {
  293.             $("#errpdescriptionrate").addnd();
  294.         });
  295.  
  296.         $("#pimagerate").on('rating.change', function () {
  297.             $("#errpimagerate").addnd();
  298.         });
  299.  
  300.         $("#pdeliveryrate").on('rating.change', function () {
  301.             $("#errpdeliveryrate").addnd();
  302.         });
  303.  
  304.         $("#porderstaterate").on('rating.change', function () {
  305.             $("#errporderstaterate").addnd();
  306.         });
  307.  
  308.         $("#paftersalesrate").on('rating.change', function () {
  309.             $("#errpaftersalesrate").addnd();
  310.         });
  311.     },
  312.  
  313.     reset: function () {
  314.         //$('#poverallrate').rating('update', 4).trigger('rating.change');
  315.         $("#productratingwizard").wizard('goTo', 0);
  316.         $rpwizard.productid = null;
  317.         $rpwizard.companyid = null;
  318.         $rpwizard.feedbackid = null;
  319.         $rpwizard.saleid = null;
  320.  
  321.         $('#poverallrate').rating('reset').trigger('rating.change');
  322.         $('#poverallfeedback').val('');
  323.         $('#pdescriptionrate').rating('reset').trigger('rating.change');
  324.         $('#pimagerate').rating('reset').trigger('rating.change');
  325.         $('#pdescriptionfeedback').val('');
  326.         $rpwizard.attatchmentdescription = null;
  327.         $('#pdeliveryrate').rating('reset').trigger('rating.change');
  328.         $('#porderstaterate').rating('reset').trigger('rating.change');
  329.         $('#pdeliveryfeedback').val('');
  330.         $rpwizard.attatchmentdelivery = null;
  331.         $('#paftersalesrate').rating('reset').trigger('rating.change');
  332.         $('#paftersalesfeedback').val('');
  333.         $('#pisanonymous').prop('checked', false);
  334.         $("#ptbodydescription").html("");
  335.         $("#ptbodydelivery").html("");
  336.         $('#errpoverallrate').addnd();
  337.         $("#errpdescriptionrate").addnd();
  338.         $("#errpimagerate").addnd();
  339.         $("#errpdeliveryrate").addnd();
  340.         $("#errporderstaterate").addnd();
  341.         $("#errpaftersalesrate").addnd();
  342.     },
  343.  
  344.     wizard: {
  345.         init: function () {
  346.             $('#pratesellerform').formValidation({
  347.                 framework: 'bootstrap',
  348.                 fields: {
  349.                     //p_depositamount: {
  350.                     //    validators: {
  351.                     //        notEmpty: {
  352.                     //            message: 'Please enter amount'
  353.                     //        }
  354.                     //    }
  355.                     //}
  356.                 },
  357.                 err: {
  358.                     clazz: 'text-help'
  359.                 },
  360.                 row: {
  361.                     invalid: 'has-danger'
  362.                 }
  363.             });
  364.  
  365.             $('#pdescriptionForm').formValidation({
  366.                 framework: 'bootstrap',
  367.                 fields: {
  368.                     //p_depositamount: {
  369.                     //    validators: {
  370.                     //        notEmpty: {
  371.                     //            message: 'Please enter amount'
  372.                     //        }
  373.                     //    }
  374.                     //}
  375.                 },
  376.                 err: {
  377.                     clazz: 'text-help'
  378.                 },
  379.                 row: {
  380.                     invalid: 'has-danger'
  381.                 }
  382.             });
  383.  
  384.             $('#pratedelivserviceForm').formValidation({
  385.                 framework: 'bootstrap',
  386.                 fields: {
  387.                     //p_depositamount: {
  388.                     //    validators: {
  389.                     //        notEmpty: {
  390.                     //            message: 'Please enter amount'
  391.                     //        }
  392.                     //    }
  393.                     //}
  394.                 },
  395.                 err: {
  396.                     clazz: 'text-help'
  397.                 },
  398.                 row: {
  399.                     invalid: 'has-danger'
  400.                 }
  401.             });
  402.  
  403.             $('#prateaftersaleForm').formValidation({
  404.                 framework: 'bootstrap',
  405.                 fields: {
  406.                     //p_depositamount: {
  407.                     //    validators: {
  408.                     //        notEmpty: {
  409.                     //            message: 'Please enter amount'
  410.                     //        }
  411.                     //    }
  412.                     //}
  413.                 },
  414.                 err: {
  415.                     clazz: 'text-help'
  416.                 },
  417.                 row: {
  418.                     invalid: 'has-danger'
  419.                 }
  420.             });
  421.  
  422.             var defaults = $rpwizard.wizard.getdefaults();
  423.  
  424.             var options = $.extend(true, {}, defaults, {
  425.                 submited: false,
  426.                 onNext: function (from, to) {
  427.                 },
  428.                 onBack: function (from, to) {
  429.                 },
  430.                 onFinish: function () {
  431.                 },
  432.                 keyboard: false,
  433.                 buttonsAppendTo: '.prating-wizard-buttons'
  434.             });
  435.  
  436.             var wizardproduct = $("#productratingwizard").wizard(options).data('wizard');
  437.  
  438.             wizardproduct.get("#prateseller").setValidator(function () {
  439.                 var fv = $("#pratesellerform").data('formValidation');
  440.                 fv.validate();
  441.                 if (!fv.isValid()) {
  442.                     return false;
  443.                 }
  444.                 if ($("#poverallrate").val() == 0) {
  445.                     $("#errpoverallrate").removend();
  446.                     return false;
  447.                 }
  448.                 return true;
  449.             });
  450.  
  451.             wizardproduct.get("#pdescription").setValidator(function () {
  452.                 var fv = $("#pdescriptionForm").data('formValidation');
  453.                 fv.validate();
  454.                 if (!fv.isValid()) {
  455.                     return false;
  456.                 }
  457.  
  458.                 if ($("#pdescriptionrate").val() == 0) {
  459.                     $("#errpdescriptionrate").removend();
  460.                     return false;
  461.                 }
  462.  
  463.                 if ($("#pimagerate").val() == 0) {
  464.                     $("#errpimagerate").removend();
  465.                     return false;
  466.                 }
  467.  
  468.                 return true;
  469.             });
  470.  
  471.             wizardproduct.get("#pratedelivservice").setValidator(function () {
  472.                 var fv = $("#pratedelivserviceForm").data('formValidation');
  473.                 fv.validate();
  474.                 if (!fv.isValid()) {
  475.                     return false;
  476.                 }
  477.  
  478.                 if ($("#pdeliveryrate").val() == 0) {
  479.                     $("#errpdeliveryrate").removend();
  480.                     return false;
  481.                 }
  482.  
  483.                 if ($("#porderstaterate").val() == 0) {
  484.                     $("#errporderstaterate").removend();
  485.                     return false;
  486.                 }
  487.  
  488.                 return true;
  489.             });
  490.  
  491.             wizardproduct.get("#prateaftersale").setValidator(function () {
  492.                 var fv = $("#prateaftersaleForm").data('formValidation');
  493.                 fv.validate();
  494.                 if (!fv.isValid()) {
  495.                     return false;
  496.                 }
  497.                 return true;
  498.             });
  499.         },
  500.  
  501.         getdefaults: function () {
  502.             return {
  503.                 step: '.steps .step, .pearls .pearl',
  504.                 templates: {
  505.                     buttons: function buttons() {
  506.                         var options = this.options;
  507.                         return '<div class="wizard-buttons"><a class="btn btn-sm btn-prev" href="#' + this.id + '" data-wizard="back" role="button"><i class="fa fa-angle-left"></i>' + options.buttonLabels.back + '</a><a class="btn btn-sm btn-next pull-right" href="#' + this.id + '" data-wizard="next" role="button">' + options.buttonLabels.next + ' <i class="fa fa-angle-right"></i></a>' +
  508.                                 '<a class="btn btn-sm btn-finish pull-right" id="pw_btn_finish" onclick="$rpwizard.wizard.finish()" href="#' + this.id + '" data-wizard="finish" role="button"><i class="fa fa-save"></i> <span>Save Feedback</span></a></div>';
  509.                     }
  510.                 },
  511.                 classes: {
  512.                     button: {
  513.                         hide: 'hidden-up',
  514.                         disabled: 'disabled'
  515.                     }
  516.                 }
  517.             };
  518.         },
  519.  
  520.         finish: function () {
  521.             if ($("#paftersalesrate").val() == 0) {
  522.                 $("#errpaftersalesrate").removend();
  523.                 return false;
  524.             }
  525.             else {
  526.                 $rpwizard.create.init();
  527.             }
  528.         }
  529.     },
  530.  
  531.     setobject: function () {
  532.        
  533.         var $rating = new servicerating();
  534.         $rating.ID = $rpwizard.feedbackid;
  535.         $rating.SaleID = $rpwizard.saleid;
  536.         $rating.ProductID = $rpwizard.productid;
  537.         $rating.CompanyID = $rpwizard.companyid;
  538.  
  539.         $rating.OverallRate = $('#poverallrate').val();
  540.         $rating.OverallFeedback = $('#poverallfeedback').val();
  541.         $rating.DescriptionRate = $('#pdescriptionrate').val();
  542.         $rating.ImageRate = $('#pimagerate').val();
  543.         $rating.ProductDescriptionFeedback = $('#pdescriptionfeedback').val();;
  544.         $rating.ProductDescriptionImages = $rpwizard.attatchmentdescription;
  545.         $rating.DeliveryRate = $('#pdeliveryrate').val();
  546.         $rating.OrderStateRate = $('#porderstaterate').val();
  547.         $rating.DeliveryFeedback = $('#pdeliveryfeedback').val();
  548.         $rating.DeliveryImages = $rpwizard.attatchmentdelivery;
  549.         $rating.AfterSalesRate = $('#paftersalesrate').val();
  550.         $rating.AfterSalesFeedback = $('#paftersalesfeedback').val();
  551.         $rating.Isanonymous = $('#pisanonymous').prop('checked') ? true : false;
  552.         return $rating;
  553.     },
  554.  
  555.     create: {
  556.         init: function () {
  557.             $('#product-rating-modal').modal('hide');
  558.             $commonFn.waitLoader("Please wait while we are saving your feedback.");
  559.             $.when($rpwizard.create.save()).then(function ($data) {
  560.                 $commonFn.closeWaitLoader();
  561.              
  562.                 if ($data == "true") {
  563.                     if ($rpwizard.feedbackid != '') {
  564.                         swal("Congratulation", "Your feedback has been updated successfully.", "success");
  565.                     }
  566.                     else {
  567.                         swal("Congratulation", "Your feedback has been saved successfully.", "success");
  568.                     }
  569.                 }
  570.                 else {
  571.                     swal("Oops...!", "Some error has been occurred please try after some time.", "error");
  572.                 }
  573.                 $rpwizard.reset();
  574.             });
  575.         },
  576.         save: function () {
  577.             var $rating = $rpwizard.setobject();
  578.             var dfd = $.Deferred();
  579.             $.ajax({
  580.                 type: "POST",
  581.                 url: "/customer/saveproductrating",
  582.                 data: JSON.stringify({ rating: $rating }),
  583.                 contentType: "application/json; charset=utf-8",
  584.                 datatype: "json",
  585.                 processData: false,
  586.                 success: function (result) {
  587.                     dfd.resolve(result);
  588.                     return dfd.promise();
  589.                 },
  590.                 error: function (er) {
  591.                     var _er = er;
  592.                     return dfd.promise();
  593.                 }
  594.             });
  595.             return dfd.promise();
  596.         }
  597.     },
  598.  
  599. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement