Subversion Repositories SmartDukaan

Rev

Rev 25422 | Rev 25439 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
25380 amit.gupta 1
<style>
2
	.table-striped > tbody > tr:nth-child(odd) > td{
3
  		background: white;
4
  		background-color: white;
5
	}
6
	.table-striped > tbody > tr:nth-child(even) > td{
7
  		background: white;
8
  		background-color:white;
9
	}
10
	.table-striped > tbody > tr:hover > td,
11
	.table-striped > tbody > tr:hover {
12
		background-color: #e98c8f;
13
	  	color:white;
14
	}
15
	.btn:hover{
16
  		color: grey;
17
  		text-decoration: none;
18
	}
19
	.btn-primary:hover{
20
  		color: grey;
21
  		text-decoration: none;
22
	}
23
	.thumb-image-container{
24
		float:left;position:relative;padding:5px;
25
	}
26
	.thumb-image{
27
		float:left;width:250px;position:relative;padding:5px;
28
	}
29
	.selectedItem{border:2px solid blue;}
30
</style>
31
 
32
<section class="wrapper">
33
	<div class="row">
34
		<div class="col-lg-12">
35
			<h3 class="page-header"><i class="icon_document_alt"></i>CONTENT</h3>
36
			<ol class="breadcrumb">
37
				<li><i class="fa fa-home"></i><a href="${rc.contextPath}/dashboard">Home</a></li>
38
				<li><i class="icon_document_alt"></i>CONTENT</li>
39
			</ol>
40
		</div>
41
	</div>
42
  	<div id="upload-table">
43
		<div class="row">
44
			<form class="form-horizontal">
45
				<label class="control-label col-sm-2" for="excelfile">CSV File:</label>
46
			    <div class="col-lg-3">
47
			    	<div class="input-group">
48
			    		<input class="form-control" type="file" id="entityupload" name="uploadfile" value="Upload Images">
49
			    		<span class="input-group-btn">
50
				    		<button class="btn btn-default entityfileupload">
51
							    Uplaod
52
							</button>
53
						</span>
54
					</div>
55
			    </div>
56
		    	<div class="col-lg-2">
57
		    		<a class="btn btn-default" href="${rc.contextPath}/content/template.csv">
58
					    Download Tempate
59
					</a>
60
		    	</div>
61
		    </form>
62
	    </div>
63
	</div>
64
	<div id="wrapper" style="margin-top: 20px;" class="row">
65
		<form  class="form-horizontal" id="mediaForm" method="POST" action="content/media/upload" enctype="multipart/form-data">
66
		<div class="row container">
67
			<div class="col-lg-4">
68
			    <div class="input-group">
69
			      <input type="text" class="form-control typeahead" id="entityData" placeholder="Search for Entity">
70
			      <span class="input-group-btn">
71
			        <button id="loadImages" class="btn btn-default" type="button">Load Images</button>
72
			      </span>
73
			    </div><!-- /input-group -->
74
			</div><!-- /.col-lg-6 -->
75
			<div class="col-lg-3">
76
				<div>
77
					<input id="fileUpload" multiple="multiple" type="file" class="form-control"/>
78
				</div>
79
			</div> 
80
			<div class="col-lg-2">
81
		 		<input type="submit" class="btn btn-default" value="Upload Images">
82
			</div> 
83
			<div class="col-lg-2">
84
		 		<button id="btnDelete" class="btn btn-default">Delete Selected</button>
85
			</div> 
86
		</div>
87
		<div id="image-holder">
88
		</div>
89
		</form>
90
	</div>
91
</section>
92
<script type="text/javascript">
93
$(document).ready(function(){
94
	$('button.entityfileupload').on('click', function() {
95
		var fileSelector = $('#entityupload')[0];
96
		if(fileSelector != undefined && fileSelector.files[0] != undefined) {
97
			if(confirm("Confirm Upload?")) {
98
				doAjaxUploadRequestHandler("${rc.contextPath}/content/upload", "POST", fileSelector.files[0], function(response){
99
					if(response) {
100
						alert("Content updated successfully");
101
					}
102
				});
103
			}
104
		} else {
105
			alert("Please upload file!");
106
		}
107
		return false;
108
	});
109
});
110
$(document).ready(function() {
111
	$("#image-holder").on('click','.thumb-image',function(){
112
	   $(this).closest('.thumb-image-container').toggleClass("selectedItem");
113
	});
114
	$("#btnDelete").on("click",function(){
115
		$(".selectedItem").remove();
116
		return false;
117
	});
118
	$("#loadImages").on('click', function() {
119
		doGetAjaxRequestHandler(context + "/content/media?entityId=" + entityId, function(response) {
120
			debugger;
25415 amit.gupta 121
			if(response){
122
				response = JSON.parse(response);
25420 amit.gupta 123
				var image_holder = $("#image-holder");
25422 amit.gupta 124
				response.mediaPojos.forEach(function(value, index){
25415 amit.gupta 125
					var checked = index==response.defaultImageIndex;
25420 amit.gupta 126
					var divObj = 
127
					$(`<div class="thumb-image-container">
128
						<div class="radio">
129
					  		<label>
130
					    		<input type="radio" name="optionsRadios">
131
					    		Set as default
132
						  	</label>
133
						</div>
134
						<div><input type="text" name="descriptions[]" placeholder="Image Description"/></div>
135
					</div>`).appendTo(image_holder);
136
					var imgObject = $("<img />", {
137
						"class": "thumb-image"
138
					}).appendTo(divObj);
25421 amit.gupta 139
					divObj.find('input[type=text]').val(value.title);
25420 amit.gupta 140
					divObj.find('input:radio').prop("checked", checked);
25425 amit.gupta 141
					url = new URL(value.url);
142
					url.protocol = "https:";
143
 
144
			        fetch(url.toString()).then(function(data) {
25420 amit.gupta 145
					  	var objectURL = URL.createObjectURL(data.blob());
146
					  	imgObject.src = objectUrl;
147
					});
25416 amit.gupta 148
				});
25380 amit.gupta 149
			}
150
		});
151
	});
152
	$("#mediaForm").on("submit",function(){
153
		debugger;
154
		returnedValue="";
155
		if(!$("input:radio[name='optionsRadios']").is(":checked")){
156
			alert("Please check default image!");
157
		} else if(confirm("Are you sure?")) {
158
			var jsonObject = {};
159
			jsonObject.entityId = entityId;
160
			jsonObject.mediaPojos = [];
161
			$('#image-holder .thumb-image-container').each(function(index, ele){
162
				var title = $(ele).find("input:text").val().trim();
163
				if(title.length == 0) {
164
					alert("Descriptions are required!");
165
				} else {
166
					var mediaPojo={};
167
					mediaPojo.title = title;			
168
					mediaPojo.imageData = $(ele).find("img").attr("src");
169
					debugger;
170
					jsonObject.mediaPojos.push(mediaPojo);
171
					if($(ele).find("input:radio:checked").length>0) {
172
						jsonObject.defaultImageIndex = index;
173
					}
174
				}
175
			});
176
			doPostAjaxRequestWithJsonHandler("/content/media/upload", JSON.stringify(jsonObject), function(response){
177
				bootbox.alert("Images uploaded successfully");
178
			});
179
 
180
		}
181
		$(".selectedItem");
182
		return false;
183
	});
184
 
185
	$("#fileUpload").on('change', function() {
186
	  //Get count of selected files
187
	  var countFiles = this.files.length;
188
	  var imgPath = this.value;
189
	  var extn = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();
190
	  var image_holder = $("#image-holder");
191
	  image_holder.remove(".new");
192
	  if (extn == "gif" || extn == "png" || extn == "jpg" || extn == "jpeg") {
193
	    if (typeof(FileReader) != "undefined") {
194
	      //loop for each file selected for uploaded.
195
	      for (var i = 0; i < countFiles; i++) 
196
	      {
197
	        var reader = new FileReader();
198
	        var filename = this.files[i].name
199
	        reader.description = filename.substring(0, filename.lastIndexOf('.')); 
200
	        reader.onload = function(e) {
201
				var divObj = 
202
				$(`<div class="thumb-image-container new">
203
					<div class="radio">
204
				  		<label>
205
				    		<input type="radio" name="optionsRadios">
206
				    		Set as default
207
					  	</label>
208
					</div>
209
					<div><input type="text" name="descriptions[]" placeholder="Image Description"/></div>
210
				</div>`).appendTo(image_holder);
211
				$("<img />", {
212
					"src": e.target.result,
213
					"class": "thumb-image"
214
				}).appendTo(divObj);
215
				divObj.find('input[type=text]').val(this.description);
216
	        }
217
	        reader.readAsDataURL(this.files[i]);
218
	      }
219
	    } else {
220
	      alert("This browser does not support FileReader.");
221
	    }
222
	  } 
223
	  else {
224
	  	alert("Pls select only images");
225
	  }
226
	});
227
	getEntityAheadOptions($("#entityData"), function(selectedEntity){
228
		entityId = selectedEntity.catalogId_i;
229
	});
230
});
231
</script>
232