Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CommentsController = function () {
- var self = this;
- this.url = 'index.php?r=comments/createAjax';
- this.form = null;
- this.body = null;
- this.container = null;
- this.notify = null;
- this.appendComment = function (data) {
- var html = self.generateHtml(data);
- jQuery(this.body).prepend(html);
- jQuery('html, body').animate({
- scrollTop: (jQuery(this.body).offset().top - 50)
- },
- 1000);
- jQuery('.comment:first', this.body).slideDown(750);
- jQuery('.no-comments', this.container).slideUp(500);
- }
- this.generateHtml = function (data) {
- var res = '<div class="comment" style="display: none;"> \
- <div class="author"> \
- Я \
- </div> \
- <div class="created"> \
- ' + data.created + '\
- </div> \
- <div class="text"> \
- ' + data.comment + ' \
- </div> \
- </div>';
- return res;
- };
- this.sendRequest = function (data) {
- jQuery.post(
- this.decodeUrlPath(self.url),
- {
- 'ajax': data,
- 'ieV': this.getIEValidator()
- },
- self.sendCallback,
- 'json'
- );
- };
- this.sendCallback = function (response) {
- if (response.status) {
- self.appendComment(response.records);
- self.form.get(0).reset();
- }
- else {
- self.notify.raiseMessage('Не удалось сохранить комментарий.');
- }
- };
- this.collectData = function () {
- var res = {};
- res['comment'] = jQuery('textarea', self.form).val();
- res['id_order'] = jQuery('input[name="Comments[id_order]"]', self.form).val();
- return res;
- };
- this.init = function () {
- jQuery('.comments .submit span').click(function (e) {
- var data = self.collectData();
- self.sendRequest(data);
- });
- this.container = jQuery('.comments');
- this.form = jQuery('.foot form', this.container);
- this.body = jQuery('.body', this.container);
- this.notify = window.market.notifyManger;
- }
- this.init();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement