mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 21:25:42 +00:00 
			
		
		
		
	Replace PartImageUpload form
This commit is contained in:
		| @@ -133,6 +133,14 @@ | ||||
|             }); | ||||
|     }); | ||||
|  | ||||
|     function reloadImage(data) { | ||||
|         if (data.image) { | ||||
|             $('#company-image').attr('src', data.image); | ||||
|         } else { | ||||
|             location.reload(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     enableDragAndDrop( | ||||
|         "#company-thumb", | ||||
|         "{% url 'api-company-detail' company.id %}", | ||||
| @@ -140,12 +148,7 @@ | ||||
|             label: 'image', | ||||
|             method: 'PATCH', | ||||
|             success: function(data, status, xhr) { | ||||
|  | ||||
|                 if (data.image) { | ||||
|                     $('#company-image').attr('src', data.image); | ||||
|                 } else { | ||||
|                     location.reload(); | ||||
|                 } | ||||
|                 reloadImage(data); | ||||
|             } | ||||
|         } | ||||
|     ); | ||||
| @@ -167,11 +170,7 @@ | ||||
|                 }, | ||||
|                 title: '{% trans "Upload Image" %}', | ||||
|                 onSuccess: function(data) { | ||||
|                     if (data.image) { | ||||
|                         $('#company-image').attr('src', data.image); | ||||
|                     } else { | ||||
|                         location.reload(); | ||||
|                     } | ||||
|                     reloadImage(data); | ||||
|                 } | ||||
|             } | ||||
|         ); | ||||
|   | ||||
| @@ -237,14 +237,7 @@ | ||||
|     }); | ||||
|     {% endif %} | ||||
|  | ||||
|     enableDragAndDrop( | ||||
|         '#part-thumb', | ||||
|         "{% url 'api-part-detail' part.id %}", | ||||
|         { | ||||
|             label: 'image', | ||||
|             method: 'PATCH', | ||||
|             success: function(data, status, xhr) { | ||||
|  | ||||
|     function reloadImage(data) { | ||||
|         // If image / thumbnail data present, live update | ||||
|         if (data.image) { | ||||
|             $('#part-image').attr('src', data.image); | ||||
| @@ -253,6 +246,16 @@ | ||||
|             location.reload(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     enableDragAndDrop( | ||||
|         '#part-thumb', | ||||
|         "{% url 'api-part-detail' part.id %}", | ||||
|         { | ||||
|             label: 'image', | ||||
|             method: 'PATCH', | ||||
|             success: function(data, status, xhr) { | ||||
|                 reloadImage(data); | ||||
|             } | ||||
|         } | ||||
|     ); | ||||
|  | ||||
| @@ -293,11 +296,20 @@ | ||||
|     }); | ||||
|  | ||||
|     $("#part-image-upload").click(function() { | ||||
|         launchModalForm("{% url 'part-image-upload' part.id %}", | ||||
|  | ||||
|         constructForm( | ||||
|             '{% url "api-part-detail" part.pk %}', | ||||
|             { | ||||
|                 reload: true | ||||
|                 method: 'PATCH', | ||||
|                 fields: { | ||||
|                     image: {}, | ||||
|                 }, | ||||
|                 title: '{% trans "Upload Image" %}', | ||||
|                 onSuccess: function(data) { | ||||
|                     reloadImage(data); | ||||
|                 } | ||||
|         ); | ||||
|             } | ||||
|         ) | ||||
|     }); | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -81,7 +81,6 @@ part_detail_urls = [ | ||||
|     url(r'^qr_code/?', views.PartQRCode.as_view(), name='part-qr'), | ||||
|  | ||||
|     # Normal thumbnail with form | ||||
|     url(r'^thumbnail/?', views.PartImageUpload.as_view(), name='part-image-upload'), | ||||
|     url(r'^thumb-select/?', views.PartImageSelect.as_view(), name='part-image-select'), | ||||
|     url(r'^thumb-download/', views.PartImageDownloadFromURL.as_view(), name='part-image-download'), | ||||
|  | ||||
|   | ||||
| @@ -1186,21 +1186,6 @@ class PartImageDownloadFromURL(AjaxUpdateView): | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class PartImageUpload(AjaxUpdateView): | ||||
|     """ View for uploading a new Part image """ | ||||
|  | ||||
|     model = Part | ||||
|     ajax_template_name = 'modal_form.html' | ||||
|     ajax_form_title = _('Upload Part Image') | ||||
|  | ||||
|     form_class = part_forms.PartImageForm | ||||
|  | ||||
|     def get_data(self): | ||||
|         return { | ||||
|             'success': _('Updated part image'), | ||||
|         } | ||||
|  | ||||
|  | ||||
| class PartImageSelect(AjaxUpdateView): | ||||
|     """ View for selecting Part image from existing images. """ | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user