From 2c337b5c1c6ae2af2968e5f35124f39e564d5bc8 Mon Sep 17 00:00:00 2001 From: Dmitriy Shesterkin Date: Sun, 25 Jun 2017 01:24:51 +0300 Subject: [PATCH] frontend for add stamp crop image, test only stamp --- .eslintrc.js | 28 ++++ src/customer/models.py | 41 +++-- src/customer/urls.py | 127 ++++++++------- src/customer/views/profile.py | 130 +++++---------- src/dokumentor/static/css/style.css | 77 +++++++++ src/dokumentor/static/js/profile/asset.js | 148 +++++++++++++++--- src/dokumentor/templates/base.html | 1 - .../templates/customer/profile/edit.html | 38 ++++- 8 files changed, 406 insertions(+), 184 deletions(-) create mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..c896ff0 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,28 @@ +var OFF = 0, WARN = 1, ERROR = 2; + +module.exports = exports = { + "root": true, + env: { + 'es6': true, // We are writing ES6 code + 'browser': true, // for the browser + 'commonjs': true // and use require() for stylesheets + }, + "parserOptions": { + "ecmaFeatures": { + "modules": true + }, + "sourceType": "module" + }, + "rules":{ + "no-console": OFF, + "jsx-quotes": WARN, + "no-unused-vars": WARN, + "no-undef": WARN + + }, + "globals": { + "$": true + }, + + "extends": ["eslint:recommended"] +}; \ No newline at end of file diff --git a/src/customer/models.py b/src/customer/models.py index 0d17c72..7f070b0 100644 --- a/src/customer/models.py +++ b/src/customer/models.py @@ -58,17 +58,24 @@ class UserProfile(models.Model): boss_name = models.CharField(u'Имя', max_length=30, default='') boss_midname = models.CharField(u'Отчество', max_length=30, default='') - inn = models.CharField(u'ИНН', max_length=12, default='') # длина: 10 для организаций, 12 для ИП - ogrn = models.CharField(u'ОГРН/ОГРНИП', max_length=15, default='') # длина: 13 для организаций, 15 для ИП - okpo = models.CharField(u'ОКПО', max_length=10, blank=True, default='') # длина: 8 для организаций, 8 или 10 для ИП - - glavbuh_surname = models.CharField(u'Фамилия', max_length=30, blank=True, default='', - help_text=u'Используется для строки "подпись" в документах.') + # длина: 10 для организаций, 12 для ИП + inn = models.CharField(u'ИНН', max_length=12, default='') + # длина: 13 для организаций, 15 для ИП + ogrn = models.CharField(u'ОГРН/ОГРНИП', max_length=15, default='') + # длина: 8 для организаций, 8 или 10 для ИП + okpo = models.CharField(u'ОКПО', max_length=10, blank=True, default='') + + glavbuh_surname = models.CharField('Фамилия', max_length=30, blank=True, default='', + help_text='Используется для строки "подпись" в документах.') glavbuh_name = models.CharField(u'Имя', max_length=30, blank=True, default='') glavbuh_midname = models.CharField(u'Отчество', max_length=30, blank=True, default='') - address = models.CharField(u'Фактический адрес', max_length=256, default='', - help_text=u'Будет подставляться в создаваемые счета, акты и накладные.') + address = models.CharField( + 'Фактический адрес', + max_length=256, + default='', + help_text='Будет подставляться в создаваемые счета, акты и накладные.' + ) jur_address = models.CharField(u'Юридический адрес', max_length=256, blank=True, default='', help_text=u'Как в учредительных документах.') @@ -86,16 +93,26 @@ class UserProfile(models.Model): site = models.CharField(u'Сайт', max_length=256, blank=True, default='') # поля, только для ИП - svid_gos_reg = models.CharField(u'Свид-во о гос. регистрации', max_length=256, blank=True, default='', - help_text=u'Требуется для счет-фактуры.') + svid_gos_reg = models.CharField( + 'Свид-во о гос. регистрации', + max_length=256, + blank=True, + default='', + help_text=u'Требуется для счет-фактуры.' + ) ip_reg_date = models.DateField(u'Дата регистрации ИП', blank=True, null=True) # поля, только для Организации name = models.CharField(u'Краткое название организации', max_length=256, default='', help_text=u'Будет подставляться в создаваемые документы.') - full_name = models.CharField(u'Полное название организации', max_length=256, blank=True, default='', - help_text=u'Как в учредительных документах.') + full_name = models.CharField( + 'Полное название организации', + max_length=256, + blank=True, + default='', + help_text=u'Как в учредительных документах.' + ) kpp = models.CharField(u'КПП', max_length=9, default='') diff --git a/src/customer/urls.py b/src/customer/urls.py index 30b4921..12b922f 100644 --- a/src/customer/urls.py +++ b/src/customer/urls.py @@ -6,67 +6,80 @@ from customer.views import profile, profile_ajax, license, documents from customer.views import bank_accounts, bank_accounts_ajax from customer.views import clients, clients_ajax -urlpatterns = patterns('', - # личный кабинет - url(r'^$', views.customer_index, name='customer_index'), +urlpatterns = \ + patterns('', + # личный кабинет + url(r'^$', views.customer_index, name='customer_index'), - # --- профиль - url(r'^profile/$', profile.profile_view, name='customer_profile_view'), - url(r'^profile/edit/$', profile.profile_edit, name='customer_profile_edit'), - url(r'^profile/email/$', profile.profile_email, name='customer_profile_email'), - url(r'^license/$', license.order_license, name='customer_order_license'), - url(r'^delete_license/(?P\d+)/$', license.delete_license, name='customer_delete_license'), - url(r'^get_doc/(?P\d+)/$', documents.get_doc, name='customer_license_get_doc'), - url(r'^payment/confirm/(?P\d+)$', license.yandex_pay, name='yamoney_confirm'), - url(r'^payment/result/$', license.payment_result, name='yamoney_result'), - url(r'^payment/success/$', license.payment_success, name='yamoney_success'), - url(r'^payment/fail/$', license.payment_fail, name='yamoney_fail'), - url(r'^license_list/$', license.license_list, name='customer_license_list'), - url(r'^paid_list/$', license.paid_list, name='customer_paid_list'), + # --- профиль + url(r'^profile/$', profile.profile_view, name='customer_profile_view'), + url(r'^profile/edit/$', profile.profile_edit, name='customer_profile_edit'), + url(r'^profile/email/$', profile.profile_email, name='customer_profile_email'), + url(r'^license/$', license.order_license, name='customer_order_license'), + url(r'^delete_license/(?P\d+)/$', license.delete_license, + name='customer_delete_license'), + url(r'^get_doc/(?P\d+)/$', documents.get_doc, + name='customer_license_get_doc'), + url(r'^payment/confirm/(?P\d+)$', license.yandex_pay, + name='yamoney_confirm'), + url(r'^payment/result/$', license.payment_result, name='yamoney_result'), + url(r'^payment/success/$', license.payment_success, name='yamoney_success'), + url(r'^payment/fail/$', license.payment_fail, name='yamoney_fail'), + url(r'^license_list/$', license.license_list, name='customer_license_list'), + url(r'^paid_list/$', license.paid_list, name='customer_paid_list'), - # --- профиль AJAX - url(r'^profile/filters/edit/ajax/$', profile_ajax.profile_filters_edit_ajax, - name='customer_profile_filters_edit_ajax'), - url(r'^profile/email/ajax/$', profile_ajax.profile_email_ajax, - name='customer_profile_email_ajax'), + # --- профиль AJAX + url(r'^profile/filters/edit/ajax/$', profile_ajax.profile_filters_edit_ajax, + name='customer_profile_filters_edit_ajax'), + url(r'^profile/email/ajax/$', profile_ajax.profile_email_ajax, + name='customer_profile_email_ajax'), - # --- расчетные счета - url(r'^bank-accounts/$', bank_accounts.bank_accounts_list, name='customer_bank_accounts_list'), - url(r'^bank-accounts/page/(?P[0-9]+)/$', bank_accounts.bank_accounts_list, - name='customer_bank_accounts_list'), - url(r'^bank-accounts/add/$', bank_accounts.bank_accounts_add, name='customer_bank_accounts_add'), - url(r'^bank-accounts/(?P\d+)/edit/$', bank_accounts.bank_accounts_edit, - name='customer_bank_accounts_edit'), - url(r'^bank-accounts/(?P\d+)/delete/$', bank_accounts.bank_accounts_delete, - name='customer_bank_accounts_delete'), + # --- расчетные счета + url(r'^bank-accounts/$', bank_accounts.bank_accounts_list, + name='customer_bank_accounts_list'), + url(r'^bank-accounts/page/(?P[0-9]+)/$', bank_accounts.bank_accounts_list, + name='customer_bank_accounts_list'), + url(r'^bank-accounts/add/$', bank_accounts.bank_accounts_add, + name='customer_bank_accounts_add'), + url(r'^bank-accounts/(?P\d+)/edit/$', bank_accounts.bank_accounts_edit, + name='customer_bank_accounts_edit'), + url(r'^bank-accounts/(?P\d+)/delete/$', bank_accounts.bank_accounts_delete, + name='customer_bank_accounts_delete'), - # --- расчетные счета AJAX - url(r'^bank-accounts/ajax/$', bank_accounts_ajax.bank_accounts_list_ajax, - name='customer_bank_accounts_list_ajax'), - url(r'^bank-accounts/(?P\d+)/get/ajax/$', bank_accounts_ajax.bank_accounts_get_ajax, - name='customer_bank_accounts_get_ajax'), - url(r'^bank-accounts/add/ajax/$', bank_accounts_ajax.bank_accounts_add_ajax, - name='customer_bank_accounts_add_ajax'), - url(r'^bank-accounts/(?P\d+)/edit/ajax/$', bank_accounts_ajax.bank_accounts_edit_ajax, - name='customer_bank_accounts_edit_ajax'), - url(r'^bank-accounts/(?P\d+)/delete/ajax/$', bank_accounts_ajax.bank_accounts_delete_ajax, - name='customer_bank_accounts_delete_ajax'), + # --- расчетные счета AJAX + url(r'^bank-accounts/ajax/$', bank_accounts_ajax.bank_accounts_list_ajax, + name='customer_bank_accounts_list_ajax'), + url(r'^bank-accounts/(?P\d+)/get/ajax/$', + bank_accounts_ajax.bank_accounts_get_ajax, + name='customer_bank_accounts_get_ajax'), + url(r'^bank-accounts/add/ajax/$', bank_accounts_ajax.bank_accounts_add_ajax, + name='customer_bank_accounts_add_ajax'), + url(r'^bank-accounts/(?P\d+)/edit/ajax/$', + bank_accounts_ajax.bank_accounts_edit_ajax, + name='customer_bank_accounts_edit_ajax'), + url(r'^bank-accounts/(?P\d+)/delete/ajax/$', + bank_accounts_ajax.bank_accounts_delete_ajax, + name='customer_bank_accounts_delete_ajax'), - # --- контрагенты - url(r'^clients/$', clients.clients_list, name='customer_clients_list'), - url(r'^clients/page/(?P[0-9]+)/$', clients.clients_list, name='customer_clients_list'), - url(r'^clients/add/$', clients.clients_add, name='customer_clients_add'), - url(r'^clients/(?P\d+)/edit/$', clients.clients_edit, name='customer_clients_edit'), - url(r'^clients/(?P\d+)/delete/$', clients.clients_delete, name='customer_clients_delete'), + # --- контрагенты + url(r'^clients/$', clients.clients_list, name='customer_clients_list'), + url(r'^clients/page/(?P[0-9]+)/$', clients.clients_list, + name='customer_clients_list'), + url(r'^clients/add/$', clients.clients_add, name='customer_clients_add'), + url(r'^clients/(?P\d+)/edit/$', clients.clients_edit, + name='customer_clients_edit'), + url(r'^clients/(?P\d+)/delete/$', clients.clients_delete, + name='customer_clients_delete'), - # --- контрагенты AJAX - url(r'^clients/(?P\d+)/get/ajax/$', clients_ajax.clients_get_ajax, - name='customer_clients_get_ajax'), - url(r'^clients/add/ajax/$', clients_ajax.clients_add_ajax, name='customer_clients_add_ajax'), - url(r'^clients/(?P\d+)/edit/ajax/$', clients_ajax.clients_edit_ajax, - name='customer_clients_edit_ajax'), - url(r'^clients/(?P\d+)/delete/ajax/$', clients_ajax.clients_delete_ajax, - name='customer_clients_delete_ajax'), + # --- контрагенты AJAX + url(r'^clients/(?P\d+)/get/ajax/$', clients_ajax.clients_get_ajax, + name='customer_clients_get_ajax'), + url(r'^clients/add/ajax/$', clients_ajax.clients_add_ajax, + name='customer_clients_add_ajax'), + url(r'^clients/(?P\d+)/edit/ajax/$', clients_ajax.clients_edit_ajax, + name='customer_clients_edit_ajax'), + url(r'^clients/(?P\d+)/delete/ajax/$', clients_ajax.clients_delete_ajax, + name='customer_clients_delete_ajax'), - url(r'^tmp_upload/ajax/$', profile.tmp_upload, name='upload_tmp_file'), - ) + url(r'^tmp_upload/ajax/$', profile.tmp_upload, name='upload_tmp_file'), + ) diff --git a/src/customer/views/profile.py b/src/customer/views/profile.py index e9916ea..8880eb3 100644 --- a/src/customer/views/profile.py +++ b/src/customer/views/profile.py @@ -12,7 +12,7 @@ from django.template.loader import render_to_string from django.core.mail import EmailMessage from django.utils.encoding import smart_str from django.conf import settings -from django.http import Http404, HttpResponse +from django.http import HttpResponse from easy_thumbnails.files import get_thumbnailer @@ -21,16 +21,17 @@ from commons.pdf_tools import render_pdf_to_string, pdf_to_response from customer import models, forms from customer.utils import raise_if_no_profile -PDF_PROFILE_NAME = u'Реквизиты.pdf' +PDF_PROFILE_NAME = 'Реквизиты.pdf' SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') -# ----------------------------------------------------------------------------- - @login_required @csrf_protect def profile_view(request): - """Просмотр профиля пользователя, фильтрация реквизитов, скачать/отправить реквизиты по почте.""" + """ + Просмотр профиля пользователя, фильтрация реквизитов, + скачать/отправить реквизиты по почте. + """ raise_if_no_profile(request) template_name = 'customer/profile/view.html' @@ -43,19 +44,31 @@ def profile_view(request): filters = models.UserProfileFilters.objects.get_or_create_filters(user=request.user) if request.method == 'POST': - filters_form = filters_form_class(data=request.POST, instance=filters, profile=profile, accounts=accounts) + filters_form = filters_form_class( + data=request.POST, + instance=filters, + profile=profile, + accounts=accounts + ) if filters_form.is_valid(): filters = filters_form.save() if 'download-pdf' in request.POST: - # return _profile_get_pdf(request, profile, filters.bank_account, filters) # для отладки + # return _profile_get_pdf(request, profile, + # filters.bank_account, filters) # для отладки return profile_as_pdf(request, profile, filters.bank_account, filters) elif 'email-pdf' in request.POST: return redirect('customer_profile_email') - return redirect('customer_profile_view') # редирект на себя, чтобы не сабмитили форму по F5 + # редирект на себя, чтобы не сабмитили форму по F5 + return redirect('customer_profile_view') else: - filters_form = filters_form_class(instance=filters, label_suffix='', profile=profile, accounts=accounts) + filters_form = filters_form_class( + instance=filters, + label_suffix='', + profile=profile, + accounts=accounts + ) dictionary = { 'profile': profile, @@ -94,13 +107,13 @@ def profile_edit(request): for img_url in ('tmb_logo', 'tmb_boss_sign', 'tmb_glavbuh_sign', 'tmb_stamp'): if form.cleaned_data[img_url]: # TODO ? - chg_file = open(settings.MEDIA_ROOT + '/cache/imgs/' + \ + chg_file = open(settings.MEDIA_ROOT + '/cache/imgs/' + form.cleaned_data[img_url], mode='rb+') item_attr = img_url[4:] - getattr(item, item_attr).save('%s.%s' % \ - (item_attr, form.cleaned_data[img_url].split('.')[-1]), - File(chg_file)) + getattr(item, item_attr).\ + save('%s.%s' % (item_attr, form.cleaned_data[img_url].split('.')[-1]), + File(chg_file)) chg_file.close() # elif form.cleaned_data: @@ -139,32 +152,20 @@ def tmp_upload(request): open(tmp_dir + '/' + file_.name, "wb+").write(file_.read()) tmp_url_partial = os.path.basename(tmp_dir) + '/' + file_.name thumbnailer = get_thumbnailer(tmp_dir + '/' + file_.name) - # im = get_thumbnail(tmp_dir + '/' + file_.name, SIZES[elm_id], quality=75) thumbnail_options = {'size': SIZES[elm_id]} - im = thumbnailer.get_thumbnail(thumbnail_options) # Возвращает в url полный путь, поэтому придётся резать + # Возвращает в url полный путь, поэтому придётся резать + im = thumbnailer.get_thumbnail(thumbnail_options) im_url = os.path.join(settings.MEDIA_URL, os.path.relpath(im.url, settings.MEDIA_ROOT)) data = {'res': 'ok', 'pic': im_url, 'full_pic': tmp_url_partial} data.update(request.REQUEST) return HttpResponse(json.dumps(data), content_type='application/json') -# TODO ? -def del_tmp_photo(request, article_pk): - # wedding, wedding_guests = get_wedding_n_guests(request) - try: - pass - # article = WedPage.objects.get(pk=article_pk) - # article.main_photo.delete() - except: - return {'res': 'bad'} - - return {'res': 'ok'} -# - - @login_required def _profile_get_pdf(request, profile=None, account=None, filters=None): - """Создать профиль пользователя в PDF и вернуть как строку.""" + """ + Создать профиль пользователя в PDF и вернуть как строку. + """ template_name = 'customer/profile/as_pdf.html' dictionary = { 'profile': profile, @@ -176,7 +177,9 @@ def _profile_get_pdf(request, profile=None, account=None, filters=None): @login_required def profile_as_pdf(request, profile=None, account=None, filters=None): - """Вывести профиль пользователя в формате PDF в HttpResponse.""" + """ + Вывести профиль пользователя в формате PDF в HttpResponse. + """ pdf = _profile_get_pdf(request, profile, account, filters) return pdf_to_response(pdf, PDF_PROFILE_NAME) @@ -190,16 +193,20 @@ def _send_profile_email(subject, to, body, pdf_content): subject=subject, to=(to,), body=email_body, - attachments=[(smart_str(Header(PDF_PROFILE_NAME, 'cp1251')), pdf_content, 'application/pdf'), ] + attachments=[ + (smart_str(Header(PDF_PROFILE_NAME, 'cp1251')), + pdf_content, 'application/pdf'), + ] ) return email.send() -@login_required @login_required @csrf_protect def profile_email(request): - """Форма отправки профиля пользователя на email аттачем в PDF.""" + """ + Форма отправки профиля пользователя на email аттачем в PDF. + """ raise_if_no_profile(request) template_name = 'customer/profile/email.html' @@ -228,58 +235,3 @@ def profile_email(request): form = form_class() return render(request, template_name, {'form': form, 'profile': profile, }) - -# @login_required -# @csrf_protect -# def profile_settings(request): -# """Редактировать настройки пользователя.""" -# template_name='customer/profile/settings.html' -# -# profile = get_object_or_404(models.UserProfile, user=request.user) -# form_class = forms.UserProfileSettingsForm #TODO remove this view -# -# # пути к уже загруженным подписям/штампу -# curr_files = {'boss_sign': None, 'glavbuh_sign': None, 'stamp': None,} -# if profile.boss_sign: -# curr_files['boss_sign'] = profile.boss_sign.path -# if profile.glavbuh_sign: -# curr_files['glavbuh_sign'] = profile.glavbuh_sign.path -# if profile.stamp: -# curr_files['stamp'] = profile.stamp.path -# -# if request.method == "POST" and '_cancel' not in request.POST: -# post = request.POST -# files = request.FILES -# form = form_class(user=request.user, data=post, files=files, instance=profile) -# -# if form.is_valid(): -# def delete_file(path): -# """Удалить файл. Если ошибка - сообщить в консоль.""" -# try: -# os.remove(path) -# except: -# print "Can't delete file:", path -# # --- удалить старые файлы -# for field, path in curr_files.iteritems(): -# if not path: -# continue -# # если стоит галочка 'очистить' -# if '%s-clear' % field in post: -# delete_file(path) -# continue -# # если загружен новый файл -# if field in files: -# delete_file(path) -# continue -# # --- изменить пароль -# if 'new_password1' in post: -# request.user.set_password(post.get('new_password1')) -# request.user.save() -# messages.add_message(request, messages.INFO, u'Пароль успешно изменен.') -# -# form.save() -# return redirect('customer_profile_settings') -# else: -# form = form_class(user=request.user, instance=profile) -# -# return render(request, template_name, {'profile': profile, 'form': form,}) diff --git a/src/dokumentor/static/css/style.css b/src/dokumentor/static/css/style.css index 78da151..abbb792 100644 --- a/src/dokumentor/static/css/style.css +++ b/src/dokumentor/static/css/style.css @@ -925,3 +925,80 @@ input[type=number] { font-size: 25px; } +/* modal dialog upload image */ +#containerUpload { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + visibility:hidden; + display:none; + background-color: rgba(22,22,22,0.5); +} + +#containerUpload:target { + visibility: visible; + display: block; +} + +.modal-upload { + position: relative; + background: #fff; + top: 50%; + left: 50%; + width:500px; + height: 460px; + -ms-transform: translate(-50%,-50%); + -moz-transform:translate(-50%,-50%); + -webkit-transform: translate(-50%,-50%); + transform: translate(-50%,-50%); +} + +.modal-upload__wrapper { + padding: 5px; +} + +.modal-upload__header { + padding: .4em 1em; +} + +.modal-upload__title { + vertical-align: middle; + text-transform: uppercase; + color: #646669; + font-size: 18px; + font-weight: normal; + font-stretch: ultra-condensed; + font-family: "Arial Narrow", Arial, sans-serif; + display: inline-block; + width: 435px; +} + +.modal-upload__close-button { + vertical-align: middle; + display: inline-block; + background: url(../img/close.png) no-repeat top; + opacity: 0.5; + width: 22px; + height: 22px; + cursor: pointer; +} + +.modal-upload__close-button:hover { + opacity: 1; +} + +.modal-upload__body { + padding: .5em 1em; +} + +.modal-upload__bottom { + padding: .4em 1em; +} + +.modal-upload__bottom button { + font-family: Trebuchet MS,Tahoma,Verdana,Arial,sans-serif; + font-size: 1em; +} + diff --git a/src/dokumentor/static/js/profile/asset.js b/src/dokumentor/static/js/profile/asset.js index 783e356..6d3f80f 100644 --- a/src/dokumentor/static/js/profile/asset.js +++ b/src/dokumentor/static/js/profile/asset.js @@ -1,24 +1,128 @@ -/** - * Created by mitri4 on 23.06.17. - */ - -// $(document).ready(function() { -// -// $uploadCrop = $('#stamp').croppie({ -// enableExif: true, -// viewport: { -// width: 200, -// height: 200, -// type: 'circle' -// }, -// boundary: { -// width: 300, -// height: 300 -// } -// }); -// -// -// -// }); +(function($) { + $.fn.invisible = function() { + return this.each(function() { + $(this).css("visibility", "hidden"); + $(this).hide(); + }); + }; + $.fn.visible = function() { + return this.each(function() { + $(this).css("visibility", "visible"); + $(this).show(); + }); + }; +}(jQuery)); +$(document).ready(function () { + + var $uploadCrop, + rawImg, + imagePreview, + imageInputField; + + function readFile(input) { + if (input.files && input.files[0]) { + var reader = new FileReader(); + + reader.onload = function (e) { + $('#imageCropper').addClass('ready'); + rawImg = e.target.result; + $('#containerUpload').trigger("ShowModal"); + }; + reader.readAsDataURL(input.files[0]); + } else { + alert("Sorry - you're browser doesn't support the FileReader API"); + } + } + + $uploadCrop = $('#imageCropper').croppie({ + enableExif: true, + enforceBoundary: false, + viewport: { + width: 200, + height: 200, + type: 'circle' + }, + boundary: { + width: 300, + height: 300 + } + }); + + // select file + $('.img_load img').on('click', function() { + var thisId = $(this).closest('.img_load').attr('id'); + var tmbId = 'id_tmb_' + thisId.substring(3); + $('#' + tmbId).val(''); + $('#id_' + thisId).click(); + imagePreview = thisId; + imageInputField = 'id_' + thisId; + // console.log('#id_' + thisId) + }); + + // set file in input hidden filed + $('.img_load input[type=file]').on('change', function () {readFile(this)}); + + $('#containerUpload').on("ShowModal", function( ) { + $('#containerUpload').visible(); + $uploadCrop.croppie('bind', { + url: rawImg + }).then(function(){ + console.log('jQuery bind complete'); + }); + }); + + $('#cropImageBtn').on('click', function (ev) { + $uploadCrop.croppie('result', { + type: 'base64', + format: 'png', + size: 'viewport' + }).then(function (resp) { + // console.log(resp); + $('#' + imagePreview + ' img').attr('src', resp); + $('#containerUpload').trigger("CloseModal"); + $('#' + imagePreview + ' .del_image').show(); + }) + }); + + $('#containerUpload').on("CloseModal", function( ) { + $('#containerUpload').invisible(); + $('#' + imageInputField).val(''); + }); + + var closeButtons=document.getElementsByClassName("modal-upload__cleaner-btn"); + + for (var i = 0; i < closeButtons.length; i++) { + + var closeBtn = closeButtons[i]; + closeBtn.addEventListener('click',function () { + $('#containerUpload').trigger("CloseModal"); + }) + + } + + $('.img_load .del_image').on('click', function(e) { + e.preventDefault(); + var this_id = $(this).closest('.img_load').attr('id'); + var tmb_id = 'id_tmb_' + this_id.substring(3); + var dlg_msg = $('#dialog-message'); + dlg_msg.dialog({ + title: 'Удалить изображение?', + buttons:{ + 'Да': function(){ + $('#' + tmb_id).val(''); + $('#' + this_id + ' img').attr('src', '/static/img/upload-' + this_id + '.png'); + $('#' + this_id + '-clear_id').attr('checked', true); + $('#' + this_id + ' .del_image').hide(); + dlg_msg.dialog('close'); + }, + 'Нет': function(){ + dlg_msg.dialog('close'); + } + } + }).html('Нажмите "Да", чтобы удалить изображение'); + dlg_msg.dialog('open'); + }); + +}); diff --git a/src/dokumentor/templates/base.html b/src/dokumentor/templates/base.html index 498a0de..8acfdb9 100644 --- a/src/dokumentor/templates/base.html +++ b/src/dokumentor/templates/base.html @@ -134,7 +134,6 @@ - diff --git a/src/dokumentor/templates/customer/profile/edit.html b/src/dokumentor/templates/customer/profile/edit.html index b7c8d83..cffe51a 100644 --- a/src/dokumentor/templates/customer/profile/edit.html +++ b/src/dokumentor/templates/customer/profile/edit.html @@ -4,7 +4,7 @@ {% block title %}Редактирование реквизитов{% endblock %} {% block content %} -

Редактирование реквизитов{% if profile.is_ip %} ИП{% elif profile.is_org %} организации{% endif %}

+

Редактирование реквизитов{% if profile.is_ip %} ИП{% elif profile.is_org %} организации{% endif %}

@@ -449,6 +449,24 @@
+
+ +
+
{% endblock %} @@ -482,7 +500,17 @@ {% endblock %} {% block js %} + + + {% comment %} +{% endcomment %} +