Created
August 5, 2017 05:54
-
-
Save tabekg/4e0467f2dc4844fa787dd4914cc565f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var uglify = require('gulp-uglifyjs'); | |
gulp.task('uglify', function() { | |
gulp.src('./my.js') | |
.pipe(uglify()) | |
.pipe(gulp.dest('./build')) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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