Skip to content

Commit

Permalink
feature(progress): add progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
artofhuman committed Sep 30, 2015
1 parent 58ad5f4 commit e47aff0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
47 changes: 47 additions & 0 deletions app/assets/javascripts/standalone/progress_bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//модуль для показа прогресс-бара создания отчетов

app.modules.progressBar = (function(self) {

function _requestError(data) {
var payload = data.payload;

if (app.config.progressBar.documentLocationError) {
alert('Ошибка');
location.href = app.config.progressBar.documentLocationError;
}

if (payload && payload.error_messages) {
$('.js-pberrors').html(payload.error_messages.join('<br>'));
}
}

function _requestSuccess(data) {
var
progress = data.progress;

if (progress && progress.message) {
$('.js-pbstat').text(progress.num + ' из ' + progress.total + ' (' + Math.round(progress.percent) + '%)');
}
}

function _init() {
$('.js-progressbar').progressBar({
url: app.config.progressBar.url,
pid: app.config.progressBar.pid,
onSuccess: function() {
location.href = app.config.progressBar.documentLocation;
},
onError: function(data) {
_requestError(data);
},
onRequestSuccess: function(data) {
_requestSuccess(data);
}
});
}

self.load = function() {
_init();
};
return self;
}(app.modules.progressBar || {}));
17 changes: 17 additions & 0 deletions app/views/shared/job_progress_bar.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- content_for :javascripts_bottom do
= javascript_include_tag 'standalone/progress_bar', :defer => true

#progress
.progressbar.js-progressbar
#pbstat.js-pbstat
#pberrors.pberrors.js-pberrors
- if @back_url.present?
= link_to 'Закрыть', @back_url

:javascript
app.config.progressBar = {
url: #{job_status_path(domain: :current).to_json},
pid: #{@job_id.to_json},
documentLocation: #{@success_url_js || @success_url.to_json},
documentLocationError: #{@error_url ? @error_url.to_json : nil.to_json}
};

0 comments on commit e47aff0

Please sign in to comment.