/www/js/company/user.modal.js
JavaScript | 384 lines | 346 code | 19 blank | 19 comment | 66 complexity | f4f3ee7f2025580354820508da30d615 MD5 | raw file
- $("#addBonusesBtn").click(function(){
- addBonuses();
- });
- $("#incBonuses").click(function(){
- $count = parseInt($('#countBonuses').val());
- $count += 100;
- if ($count > 0)
- $count = '+' + $count;
- $('#countBonuses').val($count);
- });
- $("#decBonuses").click(function(){
- $count = parseInt($('#countBonuses').val());
- $count -= 100;
- if ($count > 0)
- $count = '+' + $count;
- $('#countBonuses').val($count);
- });
- $("#userCardGroupSelect").change(function(){
- $id = $('#userId').val();
- $val = $("#userCardGroupSelect").val();
- $.ajax({
- url: '/client/edit/'+$id,
- type: 'post',
- data: {
- id:$id,
- name: 'cardGroup',
- value: $val,
- },
- dataType: 'json',
- success: function($data)
- {
- if ($data && $data.success)
- {
- addNotification({title: spsLang['gritter.success.title'], message: $data.message}, 'success');
- }
- else if ($data && $data.error)
- {
- $.gritter.add({
- title: $data.title,
- text: $data.message,
- image: $button.closest(".purchase").find(".panel .panel-body img").attr("src"),
- sticky: false,
- time: '10000',
- class_name: ''
- });
- }
- },
- error: function($response){
- parseErrorResponse($response);
- }
- });
- });
- function showProfile($id)
- {
- $dialog = $("#clientProfileDialog");
- $url = $("#userLogotype").data('default-url');
- $body = $("body");
- $body.addClass("loading");
- $("#userCardGroupSelect").val(0);
- $.ajax({
- url: '/client/get',
- type: 'post',
- data: {id:$id},
- dataType: 'json',
- success: function($data)
- {
- $body.removeClass("loading");
- $dialog.modal('show');
- if ($data && $data.success)
- {
- $("#userLogotype, #userFirstName, #userLastName, #userGender, #userBirthday, #userCountry, #userCity, #userDescription").editable('option', 'url', $url+'/'+$id);
- $('#userId').val($data.user.id);
- $('#userBonuses').html($data.user.bonuses);
- $('#userUsername').html($data.user.username);
- $('#userLogotype img').attr('src', $data.user.oLogotype.url?$data.user.oLogotype.url:"/img/avatar.png");
- $('#userFirstName').editable('setValue', $data.user.firstName, true);
- $('#userLastName').editable('setValue', $data.user.lastName, true);
- $('#userGender').editable('setValue', $data.user.gender);
- $('#userBirthday').editable('setValue', $data.user.birthday);
- $('#userCountry').editable('setValue', $data.user.country);
- $('#userCity').editable('setValue', $data.user.city);
- $('#userDescription').editable('setValue', $data.user.description);
- $("#userCardGroupSelect").val($data.user.cardGroup);
- //initModalProfile();
- }
- else if ($data && $data.error)
- {
- $.gritter.add({
- title: $data.title,
- text: $data.message,
- image: $button.closest(".purchase").find(".panel .panel-body img").attr("src"),
- sticky: false,
- time: '10000',
- class_name: ''
- });
- }
- },
- error: function(){
- }
- });
- }
- function addBonuses()
- {
- $id = $('#userId').val();
- $count = parseInt($('#countBonuses').val());
- if ($count < 0)
- $action = 'minus';
- else
- $action = 'plus';
- $count = Math.abs($count);
- if ($count <= 0){
- $("#clientProfileDialog").modal("hide");
- return;
- }
- var $giftSmsTable = $("#giftSmsTable").DataTable();
- if($count == '' || $count == '0') {
- alert("Пожалуйста укажите количество бонусов");
- $('#countBonuses').focus();
- return;
- }
- $.ajax({
- url: '/client/addBonuses',
- type: 'post',
- data: {
- id:$id,
- action:$action,
- count:$count
- },
- dataType: 'json',
- success: function($data)
- {
- if ($data && $data.success)
- {
- addNotification({title: spsLang['gritter.success.title'], message: $data.message}, 'success');
- $("#clientProfileDialog").modal("hide");
- if($("#giftSmsTable").length > 0) {
- var $giftSmsTable = $("#giftSmsTable").DataTable();
- $giftSmsTable.ajax.reload();
- }
- if($("#clientsTable").length > 0) {
- var $clientsTable = $("#clientsTable").DataTable();
- $clientsTable.ajax.reload();
- }
- }
- else if ($data && $data.error)
- {
- $.gritter.add({
- title: $data.title,
- text: $data.message,
- image: $button.closest(".purchase").find(".panel .panel-body img").attr("src"),
- sticky: false,
- time: '10000',
- class_name: ''
- });
- }
- },
- error: function($response){
- parseErrorResponse($response);
- }
- });
- //*/
- }
- initModalProfile();
- jqXHR = new Array();
- $cropData = {};
- function initModalProfile()
- {
- jqXHR = new Array();
- $cropData = {};
- $(function () {
- $.fn.editable.defaults.mode = 'inline';
- $.fn.editable.defaults.emptytext = spsLang['editable.empty'];
- $.fn.editable.defaults.value = '';
- $.fn.editableform.loading = "<div class='editableform-loading'><i class='ace-icon fa fa-spinner fa-spin fa-2x light-blue'></i></div>";
- $.fn.editableform.buttons = '<button type="submit" class="btn btn-info editable-submit"><i class="ace-icon fa fa-check"></i></button>'+
- '<button type="button" class="btn editable-cancel"><i class="ace-icon fa fa-times"></i></button>';
- $('#userFirstName').editable({
- type: 'text',
- name: 'firstName',
- emptyclass: '',
- //send: true,
- pk: 'firstName',
- inputclass: 'editable_modal',
- validate: function(value) {
- if($.trim(value) == '') {
- return 'Укажите Имя';
- }
- },
- success: function(response, newValue) {
- if(typeof(response) == 'object'){
- var success = response.success;
- if(success == true){
- $(".profile"+response.id).html(response.name);
- return {newValue: response.value}
- }
- }
- }
- });
- $('#userLastName').editable({
- type: 'text',
- name: 'lastName',
- emptyclass: '',
- //send: true,
- pk: 'lastName',
- inputclass: 'editable_modal',
- validate: function(value) {
- if($.trim(value) == '') {
- return 'Укажите Фамилию';
- }
- },
- success: function(response, newValue) {
- if(typeof(response) == 'object'){
- var success = response.success;
- if(success == true){
- $(".profile"+response.id).html(response.name);
- return {newValue: response.value}
- }
- }
- }
- });
- $('#userDescription').editable({
- type: 'textarea',
- name: 'description',
- rows: 3,
- emptyclass: '',
- pk: 'description',
- inputclass: 'editable_modal',
- success: function(response, newValue) {
- if(typeof(response) == 'object'){
- var success = response.success;
- if(success == true){
- $(".profile"+response.id).html(response.name);
- return {newValue: response.value}
- }
- }
- }
- });
- $("#userCountry").editable({
- type: 'select2',
- name: 'country',
- emptyclass: '',
- pk: 'country',
- source: $countries,
- select2: {
- placeholder: 'Выберите страну',
- width: 180
- //minimumInputLength: 1
- },
- inputclass: 'editable_modal',
- success: function(response, newValue) {
- if(typeof(data) == 'object'){
- var success = response.success;
- if(success == true){
- return {newValue: response.value}
- }
- }
- }
- });
- $('#userCity').editable({
- type: 'text',
- name: 'city',
- emptyclass: '',
- pk: 'city',
- validate: function(value) {
- if($.trim(value) == '') {
- return 'Укажите город';
- }
- },
- inputclass: 'editable_modal',
- success: function(response, newValue) {
- if(typeof(response) == 'object'){
- var success = response.success;
- if(success == true){
- return {newValue: response.value}
- }
- }
- }
- });
- $("#userGender").editable({
- type: 'select',
- name: 'gender',
- emptyclass: '',
- inputclass: 'form-control',
- pk: 'gender',
- source: $gender,
- inputclass: 'editable_modal',
- success: function(response, newValue) {
- if(typeof(data) == 'object'){
- var success = response.success;
- if(success == true){
- return {newValue: response.value}
- }
- }
- }
- });
- $('#userBirthday').editable({
- type: 'spsdatefield',
- name: 'birthday',
- emptyclass: '',
- pk: 'birthday',
- mode: 'inline',
- tpl: '<div class="input-group input-group-compact"><input type="text" class="input-medium date" /><span class="input-group-addon"><i class="fa fa-calendar"></i></span></div>',
- //viewformat: 'dd.mm.yyyy',
- datepicker: {
- //pickTime: false,
- //endDate: moment().add(-16, 'years'),
- defaultDate: $('#userBirthday').data('value') ? moment($('#userBirthday').data('value'), 'DD.MM.YYYY') : moment().add(-16, 'years'),
- //useCurrent: false,
- //language: 'ru',
- locale: 'ru',
- //weekStart: 1,
- format: 'DD.MM.YYYY',
- //minDate: '01.01.1900',
- //maxDate: 'today'
- },
- inputclass: 'editable_modal',
- success: function(response, newValue) {
- if(typeof(response) == 'object'){
- var success = response.success;
- if(success == true){
- return {newValue: response.value}
- }
- }
- }
- });
- $('#userLogotype').editable({
- type: 'image',
- name: 'logotype',
- pk: 'logotype',
- value: null,
- onblur: 'ignore',
- emptytext: '<img src="/img/avatar.png" class="editable img-responsive" />',
- //emptytext: '<div class="ace-file-input ace-file-multiple"><span class="ace-file-container" data-title="Загрузить логотип"><span class="ace-file-name"><i class="ace-icon fa fa-picture-o"></i></span></span></div>',
- //inputclass: 'editable-image',
- image: {
- //specify ace file input plugin's options here
- url: $('#userLogotype').data('avatar-url'),
- crop_url: $('#userLogotype').data('crop-url')
- },
- tpl: '<div class="editable-image ace-file-input ace-file-multiple">' +
- '<a href="javascript:void(0)" title="'+ spsLang['avatar.upload.title'] + '" class="upload-link fileinput-button">' +
- '<input type="file" name="image" id="logotype-upload" />' +
- '<span data-title="' + spsLang['avatar.upload.container.title'] +'" class="ace-file-container"><span class="ace-file-name"><i class="ace-icon fa fa-picture-o"></i></span></span>' +
- '</a><input type="hidden" name="image_key" /><input type="hidden" name="image_url" />' +
- '</div>',
- success: function(response, newValue) {
- if(typeof(response) == 'object'){
- var success = response.success;
- if(success == true){
- return {newValue: response.value}
- }
- }
- }
- }).on('shown', function (e, editable) {
- var $editableButtons = editable.input.$input.closest('.control-group').find('.editable-buttons');
- if (!editable.input.$input.val())
- return;
- if ($editableButtons.find(".btn-clear").length == 0)
- $editableButtons.append('<button class="btn btn-purple btn-clear"><i class="fa fa-refresh"></i></button>');
- });
- //$('body').on('click', '.editable-buttons > .btn-clear', function (e) {
- //$(this).closest('.control-group').find('.editable-input .editable-image > input').val('random');
- //});
- });
- }