Skip to content

Instantly share code, notes, and snippets.

@tabekg
Created August 5, 2017 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabekg/4e0467f2dc4844fa787dd4914cc565f5 to your computer and use it in GitHub Desktop.
Save tabekg/4e0467f2dc4844fa787dd4914cc565f5 to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var uglify = require('gulp-uglifyjs');
gulp.task('uglify', function() {
gulp.src('./my.js')
.pipe(uglify())
.pipe(gulp.dest('./build'))
});
class UserRegisterService {
constructor(content){
var that = this;
this.content = {
element: $(content),
text: content
};
this.isLoading = false;
this.sending = false;
this.buttons = {
send: $(this.content.text + ' a[href="#send"]')
};
this.fields = {
phone: $(this.content.text + ' input[name="phone"]')
};
this.buttons.send.on('click touchstart', function(){
that.send();
return false;
});
this.content.element.submit(function(event){
that.send();
return false;
});
this.fields.phone.keypress(function(e){
if (e.keyCode == 13) that.send();
if (e.keyCode == 43 || e.keyCode == 45 || e.keyCode == 13) return false;
if (that.fields.phone.val().length >= 9) return false;
});
}
loading(status){
this.isLoading = status;
if (status == true){
this.buttons.send
.addClass('disabled')
.html('<i class="fa fa-spinner fa-spin fa-fw"></i><span class="sr-only">Пожалуйста, подождите...</span>');
} else {
this.buttons.send
.removeClass('disabled')
.html('Отправить код');
}
}
send(){
if (!this.sending){
var that = this;
if (!_empty(this.fields.phone.val())){
this.loading(true);
this.sending = true;
new RequestService()
.post({
action: 'userRegister',
phone: this.fields.phone.val()
}).then(function(resolve){
that.loading(false);
that.sending = false;
switch(resolve){
case 'confirm':
new StorageService().set('phone_register_confirm', that.fields.phone.val());
window.location = '/user/register/confirm';
break;
case 'success':
new StorageService().set('phone_register_confirm', that.fields.phone.val());
window.location = '/user/register/confirm';
break;
case 'unknown_error':
error.unknown();
break;
case 'exists':
swal({
title: 'Ошибка!',
text: 'Вы уже регистрировались в системе! Пожалуйста, войдите.',
type: 'error'
}).then(function(){
window.location = '/user/login';
}, function(dismiss){});
break;
case 'wrong_data':
swal({
title: 'Ошибка',
text: 'Неверный телефонный номер!',
type: 'error'
});
break;
default: error.unknown(); break;
}
}, function(reject){
that.loading(false);
that.sending = false;
});
} else {
swal({
title: 'Ошибка',
text: 'Неверный телефонный номер!',
type: 'error'
});
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment