File indexing completed on 2025-05-04 05:29:32
0001 <?php 0002 /** 0003 * ocs-webserver 0004 * 0005 * Copyright 2016 by pling GmbH. 0006 * 0007 * This file is part of ocs-webserver. 0008 * 0009 * This program is free software: you can redistribute it and/or modify 0010 * it under the terms of the GNU Affero General Public License as 0011 * published by the Free Software Foundation, either version 3 of the 0012 * License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU Affero General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Affero General Public License 0020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 **/ 0022 0023 $this->headLink()->appendStylesheet('/theme/flatui/css/stylesheets/general.css'); 0024 $this->headLink()->appendStylesheet('/theme/flatui/css/select2.min.css'); 0025 $this->headLink()->appendStylesheet('/theme/flatui/css/select2.custmized.css'); 0026 $this->inlineScript()->appendFile('/theme/flatui/js/lib/select2.min.js'); 0027 0028 $this->tab = 'products'; 0029 ?> 0030 <link href="/theme/flatui/css/chosen.css" media="screen" rel="stylesheet" type="text/css" /> 0031 0032 <link rel="stylesheet" href="/tools/bootstrap-multiselect/css/bootstrap-multiselect.css" type="text/css"> 0033 <script type="text/javascript" src="/tools/bootstrap-multiselect/js/bootstrap-multiselect.js"></script> 0034 0035 <style type="text/css"> 0036 div.datafiledroparea{ 0037 overflow-y: scroll !important; 0038 overflow-x: scroll !important; 0039 } 0040 0041 div.datafiledroparea button.multiselect { 0042 padding-top: 3px; 0043 padding-bottom: 3px; 0044 } 0045 </style> 0046 <main class="user-admin-page"> 0047 0048 <?php echo $this->render('user/partials/userHeader_top.phtml'); ?> 0049 0050 <section class="body-wrap"> 0051 0052 <section class="wrapper product-page"> 0053 0054 <!-- PAGE BODY --> 0055 0056 <section class="my-products-page"> 0057 0058 <!-- NAVIGATION --> 0059 0060 <?php echo $this->render('user/partials/userHeader.phtml'); ?> 0061 <?php echo $this->render('product/partials/header.phtml'); ?> 0062 0063 <!-- /NAVIGATION --> 0064 0065 <div class="my-products-heading"> 0066 <h1 class="page-title left"><?= $this->translate('Products') ?></h1> 0067 0068 <div class="right light lightgrey num-products"> 0069 <span class="label label-default"> 0070 <?= $this->products->getTotalItemCount() ?> <?= $this->translate('products') ?> 0071 </span> 0072 </div> 0073 </div> 0074 0075 <div class="my-products-list"> 0076 <div class="row"> 0077 <?php echo $this->partialLoop('user/partials/loopMyProducts.phtml', $this->products, $this->productFiles); ?> 0078 </div> 0079 </div> 0080 0081 <section style="text-align: center;"> 0082 <?php echo $this->paginationControl($this->products, 'Sliding', '/partials/paginationControlBootstrap.phtml', 0083 array('dom_target' => 'section.my-products-page')); ?> 0084 </section> 0085 0086 </section> 0087 0088 <!-- /PAGE BODY --> 0089 0090 </section> 0091 0092 </section> 0093 0094 </main> 0095 0096 <script type="text/javascript"> 0097 var myProducts = (function () { 0098 return { 0099 setup: function () { 0100 this.initBtnPublish(); 0101 this.initFilesPopup(); 0102 }, 0103 0104 initBtnPublish: function () { 0105 $('body').off('click', 'a[data-target]').on('click', 'a[data-target]', function (event) { 0106 event.preventDefault(); 0107 var url = this.href; 0108 var target = $(this).attr("data-target"); 0109 0110 $(target).empty().html('<img src="/images/system/ajax-loader.gif" style="display: inline;height: 20px; margin: 1px;"/>').load(url + ' ' + target + ' > *', function (response, status, xhr) { 0111 if (status == "error") { 0112 $(target).find('#error').html('Sorry, but there was an error. Please try again later.'); 0113 return; 0114 } else { 0115 return response; 0116 } 0117 }); 0118 return false; 0119 }); 0120 }, 0121 0122 initFilesPopup: function () { 0123 0124 $('body').off("click", "#github_picker").on("click", "#github_picker", function (event) { 0125 0126 html = '<form id="get-url-form">' + 0127 '<div class="form-group">' + 0128 '<input type="url" class="form-control" id="get-url" placeholder="Enter a URL where the files can be downloaded" required="required" />' + 0129 '<span id="get-url-help" class="help-block small">e.g. https://github.com/mongodb/mongo/archive/r3.5.2.tar.gz</span></div>' + 0130 '<button type="submit" class="btn btn-native btn-sm" id="get-url-submit">Submit</button>' + 0131 '</form>'; 0132 0133 var msgBox = $('#generic-dialog'); 0134 msgBox.modal('hide'); 0135 msgBox.find('.modal-header-text').empty().append('Enter a download URL:'); 0136 msgBox.find('.modal-body').empty().append(html); 0137 setTimeout(function () { 0138 msgBox.modal('show'); 0139 }, 900); 0140 0141 }); 0142 0143 $('body').off('submit', '#get-url-form').on('submit', '#get-url-form', function(event) { 0144 if (! $('#get-url-form').validate()) { 0145 return true; 0146 } 0147 event.preventDefault(); 0148 $.ajax({ 0149 url: '/file/link/', 0150 type: 'post', 0151 data: { 0152 project_id: $('#modal-ppload').attr('data-product-id'), 0153 u: $('#get-url').val() 0154 }, 0155 success: function(returned_data) { 0156 if (!returned_data.file) { 0157 $('#get-url').addClass('hasError').focus(); 0158 $('#get-url-help').html('An Error occurred. Please check your URL or try again later.'); 0159 return; 0160 } 0161 data_file = returned_data.file; 0162 $modalPpload.attr('data-ppload-collection-id', data_file.collection_id); 0163 $('#get-url').val('').removeClass('hasError'); 0164 $('#get-url-help').html(''); 0165 $('#generic-dialog').modal('hide'); 0166 getPploadFiles(); 0167 }, 0168 error: function() { 0169 $('#get-url').addClass('hasError').focus(); 0170 $('#get-url-help').html('An Error occurred. Please check your URL or try again later.'); 0171 } 0172 }); 0173 }); 0174 0175 $('body').off('change', '#get-url').on('change', '#get-url', function(event) { 0176 $('#get-url-help').empty(); 0177 }); 0178 0179 var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}} 0180 0181 $('button[rel="tooltip"]').tooltip(); 0182 0183 var $modalPpload = $('#modal-ppload'); 0184 0185 var pploadApiUri = $modalPpload.attr('data-ppload-api-uri'); 0186 0187 var pploadUploads = { 0188 queue: {}, 0189 currentUploadId: null, 0190 uploading: null 0191 }; 0192 0193 function keysrt(key, asc) { 0194 if(asc) { 0195 return function(a,b){ 0196 if (a[key] > b[key]) return 1; 0197 if (a[key] < b[key]) return -1; 0198 return 0; 0199 } 0200 } else { 0201 return function(a,b){ 0202 if (a[key] < b[key]) return 1; 0203 if (a[key] > b[key]) return -1; 0204 return 0; 0205 } 0206 } 0207 } 0208 0209 function getPploadFiles(page) { 0210 var collectionId = $modalPpload.attr('data-ppload-collection-id'); 0211 var catId = $modalPpload.attr('data-product-cat-id'); 0212 var prodId = $modalPpload.attr('data-product-id'); 0213 0214 if (!page) { 0215 page = 1; 0216 $modalPpload.find('table[data-ppload-files] tbody').empty(); 0217 } 0218 $.ajax({ 0219 //url: pploadApiUri + 'files/index', 0220 url: '/p/'+prodId+'/getfilesajax', 0221 type: 'GET', 0222 data: { 0223 collection_id: collectionId, 0224 perpage: 1000, 0225 page: page, 0226 async: false, 0227 cache: false, 0228 format: 'json', 0229 ignore_status_code: 0, 0230 status: 'active' 0231 }, 0232 dataType: 'json', 0233 success: function (data, textStatus, jqXHR) { 0234 if (data.status != 'success') { 0235 return; 0236 } 0237 0238 //get cat-tag-groups 0239 var tagGroups = null; 0240 var tagGroupsCount = 0; 0241 $.ajax({ 0242 url: '/p/'+prodId+'/gettaggroupsforcatajax', 0243 type: 'GET', 0244 timeout: 30000, 0245 async: false, 0246 cache: false, 0247 data: {project_cat_id: catId}, 0248 dataType: 'json', 0249 success: function (data, textStatus, jqXHR) { 0250 if (data.status != 'success') { 0251 $modalPpload.find('table[data-ppload-files] thead').html(''); 0252 0253 tagGroups = data.tag_groups; 0254 tagGroupsCount = data.ResultSize; 0255 0256 var tableHeader = ''; 0257 tableHeader += '<tr>'; 0258 tableHeader += ' <th><?= $this->translate('Filename') ?></th>'; 0259 tableHeader += ' <th><?= $this->translate('MD5SUM') ?></th>'; 0260 tableHeader += ' <th><?= $this->translate('Version') ?></th>'; 0261 tableHeader += ' <th><?= $this->translate('Description') ?></th>'; 0262 0263 if(tagGroupsCount>0) { 0264 $.each(tagGroups, function() { 0265 tableHeader += '<th>'+this.group_display_name+'</th>'; 0266 }); 0267 } else { 0268 tableHeader += '<th></th>'; 0269 } 0270 0271 tableHeader += ' <th><?= $this->translate('Date added') ?></th>'; 0272 tableHeader += ' <th style="text-align: right"><?= $this->translate('Filesize') ?></th>'; 0273 tableHeader += ' <th style="text-align: right"><?= $this->translate('# DLs') ?></th>'; 0274 tableHeader += ' <th></th>'; 0275 tableHeader += '</tr>'; 0276 $modalPpload.find('table[data-ppload-files] thead').append(tableHeader); 0277 0278 0279 return; 0280 } 0281 }, 0282 error: function (jqXHR, textStatus, errorThrown) { 0283 return; 0284 } 0285 }); 0286 0287 var updatePploadFileBtn = '<a href="#" class="btn btn-native btn-xs btn-file-dropzone" data-updatepploadfile-btn="">Update</a>'; 0288 var updatePploadFileBtnPerFile = ''; 0289 var deletePploadFileBtn = '<a href="#" class="btn btn-native btn-xs btn-file-dropzone" data-deletepploadfile-btn=""><span class="glyphicon glyphicon-trash"></span></a>'; 0290 var deletePploadFileBtnPerFile = ''; 0291 0292 var myArray = $.map(data.files, function(entry) { 0293 return entry; 0294 }); 0295 myArray.sort(keysrt('created_timestamp'), false); 0296 0297 //var tagOptions = UserTags.getTagOptions(); 0298 var fileTagsArray = null; 0299 var fileTagsArraySize = 0; 0300 0301 $.each(myArray, function () { 0302 if(null != tagGroups && tagGroupsCount > 0) { 0303 //get cat-tag-groups 0304 $.ajax({ 0305 url: '/p/'+prodId+'/gettaggroupsforcatajax', 0306 type: 'GET', 0307 timeout: 30000, 0308 async: false, 0309 cache: false, 0310 data: {project_cat_id: catId, file_id: this.id, test: false}, 0311 dataType: 'json', 0312 success: function (data, textStatus, jqXHR) { 0313 if (data.status != 'success') { 0314 tagGroups = data.tag_groups; 0315 return; 0316 } 0317 }, 0318 error: function (jqXHR, textStatus, errorThrown) { 0319 return; 0320 } 0321 }); 0322 } else { 0323 //get cat-tag-groups 0324 $.ajax({ 0325 url: '/p/'+prodId+'/getfiletagsajax', 0326 type: 'GET', 0327 timeout: 30000, 0328 async: false, 0329 cache: false, 0330 data: {file_id: this.id}, 0331 dataType: 'json', 0332 success: function (data, textStatus, jqXHR) { 0333 if (data.status != 'success') { 0334 fileTagsArray = data.file_tags; 0335 fileTagsArraySize = data.ResultSize; 0336 return; 0337 } 0338 }, 0339 error: function (jqXHR, textStatus, errorThrown) { 0340 return; 0341 } 0342 }); 0343 } 0344 0345 var fileDescription = ''; 0346 if (this.description) { 0347 fileDescription = this.description; 0348 fileDescription = fileDescription.replace(/<\/?[^>]+(>|$)/g, ""); 0349 } 0350 0351 var inputFileDescription = '<input data-ppload-file-description="" class="form-control input-sm"' 0352 + ' type="text" maxlength="140" placeholder="File description"' 0353 + ' value="' + fileDescription + '">'; 0354 if(this.active == '0') { 0355 inputFileDescription = '<input disabled="disabled" data-ppload-file-description="" class="form-control input-sm"' 0356 + ' type="text" maxlength="140" placeholder="File description"' 0357 + ' value="' + fileDescription + '">'; 0358 } 0359 0360 var versionText; 0361 if(this.version==null) {versionText = '';} else{versionText = this.version;} 0362 versionText = versionText.replace(/<\/?[^>]+(>|$)/g, ""); 0363 0364 var version = '<input data-ppload-file-version="" class="form-control input-sm"' 0365 + ' type="text" maxlength="140" placeholder="File version"' 0366 + ' value="' + versionText + '">'; 0367 if(this.active == '0') { 0368 version = '<input disabled="disabled" data-ppload-file-version="" class="form-control input-sm"' 0369 + ' type="text" maxlength="140" placeholder="File version"' 0370 + ' value="' + versionText + '">'; 0371 } 0372 0373 var fileCategory = ''; 0374 if (this.category) { 0375 fileCategory = this.category; 0376 } 0377 var link = ''; 0378 var fileTags = ''; 0379 0380 $.each(tagGroups, function() { 0381 eval('var '+ this.group_legacy_name + 'Id = \'\';'); 0382 }); 0383 0384 0385 //downloadlink is now: domain/api/files/download/id/ID/s/TOKEN/t/TIMESTAMP/u/USERID/FILE_NAME 0386 $projectId = $('#modal-ppload').attr('data-product-id') 0387 var downloadUrl = "https://<?= $_SERVER["SERVER_NAME"]?>/p/"+$projectId+"/startdownload?file_id=" + this.id + "&file_name=" + this.name + "&file_type=" + this.type + "&file_size=" + this.size; 0388 0389 var downloadLinkFilename = link ? this.name + ' (External Link)' : this.name; 0390 var downloadLink = '<a href="' + downloadUrl + '" id="data-link' + this.id + '" class="opendownloadfile" data-file_id="' + this.id + '" data-file_name="' + this.name + '" data-file_type="' + this.type + '" data-file_size="' + this.size + '" data-project_id="'+$projectId+'" data-link_type="download">' + downloadLinkFilename + '</a>'; 0391 0392 0393 0394 if(this.active == '1') { 0395 updatePploadFileBtnPerFile = updatePploadFileBtn; 0396 deletePploadFileBtnPerFile = deletePploadFileBtn; 0397 } else { 0398 updatePploadFileBtnPerFile = ''; 0399 deletePploadFileBtnPerFile = ''; 0400 } 0401 0402 //var numDownloads = this.downloaded_count; 0403 //numDownloads = numDownloads || 0; 0404 0405 //var numDownloads = this.downloaded_count_live || 0; 0406 var numDownloads = this.downloaded_count_uk || 0; 0407 0408 var tableString = ''; 0409 tableString += '<tr data-ppload-file-id="' + this.id + '" data-ppload-file-category="' + fileCategory + '" data-ppload-file-tags="' + fileTags + '">'; 0410 tableString += '<td>' + downloadLink + '</td>'; 0411 if(this.md5sum != 'NULL' && this.md5sum != 'null' && this.md5sum != null) { 0412 tableString += '<td>' + this.md5sum + '</td>'; 0413 } else { 0414 tableString += '<td></td>'; 0415 } 0416 tableString += '<td>' + version + '</td>'; 0417 tableString += '<td>' + inputFileDescription + '</td>'; 0418 0419 var fileId = this.id; 0420 if(tagGroupsCount>0) { 0421 $.each(tagGroups, function() { 0422 tableString += '<td>'; 0423 0424 //Tag-Group Multiselect? 0425 if(this.is_multi_select == 1) { 0426 tableString +='<select multiple="multiple" id="data-select-' + this.group_legacy_name + fileId + '" data-'+this.group_legacy_name+'-id="" data-tag-group-id="' + this.tag_group_id + '" data-tag-group="' + this.group_legacy_name + '" name="' + this.group_legacy_name + '" class="multi" style="width: 150px;">'; 0427 } else { 0428 tableString +='<select id="data-select-' + this.group_legacy_name + fileId + '" data-'+this.group_legacy_name+'-id="" data-tag-group-id="' + this.tag_group_id + '" data-tag-group="' + this.group_legacy_name + '" name="' + this.group_legacy_name + '" class="" style="width: 150px;">'; 0429 tableString +='<option value=""></option>'; 0430 } 0431 0432 0433 0434 //tableString +='<select id="data-select-' + this.group_legacy_name + fileId + '" data-'+this.group_legacy_name+'-id="" data-tag-group-id="' + this.tag_group_id + '" data-tag-group="' + this.group_legacy_name + '" name="' + this.group_legacy_name + '" class="form-control input-sm" style="width: 150px;">'; 0435 //tableString += '<option value=\"\"></option>'; 0436 0437 for(key in this.tag_list) { 0438 tableString += '<option value=\"'+key+'\"'; 0439 if(null != this.selected_tags) { 0440 $.each(this.selected_tags, function() { 0441 if(key == this.tag_id) { 0442 tableString += ' selected="selected"'; 0443 } 0444 }) 0445 } 0446 0447 tableString += '>' + this.tag_list[key] + '</option>'; 0448 } 0449 0450 tableString += '</select>'; 0451 tableString += '</td>'; 0452 }); 0453 } else { 0454 if(fileTagsArraySize>0) { 0455 tableString += '<td>'; 0456 0457 tableString += '<span class="select2 select2-container select2-container--default select2-container--below select2-container--focus" dir="ltr" style="width: auto;">'; 0458 tableString += ' <span class="selection">'; 0459 tableString += ' <span class="select2-selection select2-selection--multiple" aria-expanded="false" tabindex="-1">'; 0460 tableString += ' <ul class="select2-selection__rendered">'; 0461 0462 $.each(fileTagsArray, function() { 0463 tableString += ' <li id="file-tag-'+fileId+'-'+this.tag_id+'" class="select2-selection__choice" style="line-height: 20px !important; font-size: 9px !important;" title="'+this.name+'">'; 0464 tableString += ' <span class="select2-selection__choice__remove" data-file-id="'+fileId+'" data-file-tag-id="'+this.tag_id+'" role="presentation">×</span>'+this.name+'</li>'; 0465 }); 0466 tableString += ' </ul>'; 0467 tableString += ' </span>'; 0468 tableString += ' </span>'; 0469 tableString += '</span>'; 0470 0471 tableString += '</td>'; 0472 } else { 0473 tableString += '<td></td>'; 0474 } 0475 } 0476 0477 tableString += '<td>' + this.created_timestamp + '</td>'; 0478 tableString += '<td style="text-align: right">' + humanFileSize(this.size) + '</td>'; 0479 tableString +='<td style="text-align: right">' + numDownloads + '</td>'; 0480 tableString +='<td>' + updatePploadFileBtnPerFile + '</td>'; 0481 tableString +='<td>' + deletePploadFileBtnPerFile + '</td>'; 0482 tableString +='</tr>'; 0483 $modalPpload.find('table[data-ppload-files] tbody').append(tableString); 0484 0485 $('.multi').multiselect({ 0486 includeSelectAllOption: true, 0487 buttonClass: 'btn btn-native btn-xs' 0488 }); 0489 0490 if ((typeof link != 'undefined') && (link != "")) { 0491 //$("#data-link" + this.id).attr('href', decodeURIComponent(link)); 0492 $("#data-link" + this.id).attr('target','_blank'); 0493 $("#data-link" + this.id).html($("#data-link" + this.id).html() + " (External Link)"); 0494 } 0495 }); 0496 0497 $modalPpload.find('p[data-file-upload-msg]').show(); 0498 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 0499 $modalPpload.find('button[data-file-upload-ok-btn]').removeAttr('disabled'); 0500 0501 $modalPpload.find('button[data-deletepploadfiles-btn]').removeAttr('disabled'); 0502 0503 if ($modalPpload.find('input[data-accept-checkbox]').is(':checked')) { 0504 $modalPpload.find('button[data-addpploadfile-btn]').removeAttr('disabled'); 0505 $modalPpload.find('#github_picker').removeAttr('disabled'); 0506 } else { 0507 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 0508 $modalPpload.find('#github_picker').attr('disabled', 'disabled'); 0509 } 0510 0511 /*if (data.pagination !== 'undefined' && data.pagination.next) { 0512 getPploadFiles(data.pagination.next); 0513 }*/ 0514 }, 0515 error: function (jqXHR, textStatus, errorThrown) { 0516 return; 0517 } 0518 }); 0519 } 0520 0521 function addFileToPploadUploadQueue(fileId, fileUpload) { 0522 var uploadId = 'file-upload-' + Math.floor(Math.random() * 1000) + '-' + new Date().getTime(); 0523 pploadUploads.queue[uploadId] = { 0524 fileId: fileId, 0525 fileUpload: fileUpload 0526 }; 0527 0528 $modalPpload.find('table[data-file-upload] tbody').append( 0529 '<tr data-file-upload-id="' + uploadId + '">' 0530 + '<td>' + fileUpload.name + ' (' + humanFileSize(fileUpload.size) + ')</td>' 0531 + '<td>' 0532 + '<progress max="100" value="0" data-file-upload-progress=""></progress>' 0533 + '<br>' 0534 + '<span' 0535 + ' data-file-upload-progress=""' 0536 + ' data-file-upload-loaded="0"' 0537 + ' data-file-upload-time="0"></span>' 0538 + '</td>' 0539 + '<td><a href="#" data-file-upload-cancel-btn="">×</a></td>' 0540 + '</tr>' 0541 ); 0542 } 0543 0544 function startUploadPploadFiles() { 0545 if ($.isEmptyObject(pploadUploads.queue) || pploadUploads.uploading) { 0546 return; 0547 } 0548 0549 //var productId = $modalPpload.attr('data-product-id'); 0550 var uploadId = null; 0551 var formData = new FormData(); 0552 $.each(pploadUploads.queue, function (key, value) { 0553 uploadId = key; 0554 if (value.fileId) { 0555 formData.append('file_id', value.fileId); 0556 } 0557 formData.append('file_upload', value.fileUpload); 0558 return false; 0559 }); 0560 var $uploadContainer = $modalPpload.find('tr[data-file-upload-id="' + uploadId + '"]'); 0561 var $uploadProgressBar = $uploadContainer.find('progress[data-file-upload-progress]'); 0562 var $uploadProgress = $uploadContainer.find('span[data-file-upload-progress]'); 0563 $uploadProgress.attr('data-file-upload-time', new Date().getTime()); 0564 0565 $modalPpload.find('button[data-deletepploadfiles-btn]').attr('disabled', 'disabled'); 0566 $modalPpload.find('button[data-file-upload-ok-btn]').attr('disabled', 'disabled'); 0567 $modalPpload.find('button[data-file-upload-cancel-btn]').removeAttr('disabled'); 0568 0569 pploadUploads.currentUploadId = uploadId; 0570 0571 var url = ''; 0572 if (formData.has('file_id')) { 0573 url = $modalPpload.attr('data-updatepploadfile-uri'); 0574 } else { 0575 url = $modalPpload.attr('data-addpploadfile-uri'); 0576 } 0577 0578 pploadUploads.uploading = $.ajax({ 0579 xhr: function () { 0580 var xhr = $.ajaxSettings.xhr(); 0581 if (xhr.upload) { 0582 xhr.upload.addEventListener('progress', function (event) { 0583 var progress = parseInt(event.loaded / event.total * 10000) / 100; 0584 var previousLoaded = parseInt($uploadProgress.attr('data-file-upload-loaded')); 0585 var previousTime = parseInt($uploadProgress.attr('data-file-upload-time')); 0586 var currentTime = new Date().getTime(); 0587 var rate = '--'; 0588 if (previousTime < currentTime) { 0589 $uploadProgress.attr('data-file-upload-loaded', event.loaded); 0590 $uploadProgress.attr('data-file-upload-time', currentTime); 0591 rate = humanFileSize(Math.floor((event.loaded - previousLoaded) / (currentTime - previousTime) * 1000)); 0592 } 0593 $uploadProgressBar.attr('value', progress); 0594 $uploadProgress.html(progress + '% | ' + rate + '/s'); 0595 }, false); 0596 } 0597 xhr.addEventListener('abort', function (event) { 0598 if (pploadUploads.queue[uploadId].fileId) { 0599 $modalPpload.find('tr[data-ppload-file-id="' + pploadUploads.queue[uploadId].fileId + '"]').show(); 0600 } 0601 delete pploadUploads.queue[uploadId]; 0602 pploadUploads.currentUploadId = null; 0603 pploadUploads.uploading = null; 0604 $uploadContainer.remove(); 0605 if ($modalPpload.attr('data-ppload-collection-id')) { 0606 $modalPpload.find('button[data-deletepploadfiles-btn]').removeAttr('disabled'); 0607 } 0608 $modalPpload.find('button[data-file-upload-ok-btn]').removeAttr('disabled'); 0609 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 0610 startUploadPploadFiles(); 0611 }, false); 0612 return xhr; 0613 }, 0614 url: url, 0615 type: 'POST', 0616 data: formData, 0617 dataType: 'json', 0618 contentType: false, 0619 processData: false, 0620 success: function (data, textStatus, jqXHR) { 0621 if (data.status != 'ok') { 0622 return; 0623 } 0624 0625 if (pploadUploads.queue[uploadId].fileId) { 0626 $modalPpload.find('tr[data-ppload-file-id="' + pploadUploads.queue[uploadId].fileId + '"]').remove(); 0627 } 0628 delete pploadUploads.queue[uploadId]; 0629 pploadUploads.currentUploadId = null; 0630 pploadUploads.uploading = null; 0631 $uploadContainer.remove(); 0632 $('a[href="#modal-ppload"][data-product-id="' + $modalPpload.attr('data-product-id') + '"]') 0633 .attr('data-ppload-collection-id', data.file.collection_id); 0634 $modalPpload.attr('data-ppload-collection-id', data.file.collection_id); 0635 0636 var versionText; 0637 if(data.file.version==null) {versionText = '';} else{versionText = data.file.version;} 0638 versionText = versionText.replace(/<\/?[^>]+(>|$)/g, ""); 0639 0640 var version = '<input data-ppload-file-version="" class="form-control input-sm"' 0641 + ' type="text" maxlength="140" placeholder="File version"' 0642 + ' value="' + versionText + '">'; 0643 0644 var fileDescription = ''; 0645 if (data.file.description) { 0646 fileDescription = data.file.description; 0647 } 0648 var fileCategory = ''; 0649 if (data.file.category) { 0650 fileCategory = data.file.category; 0651 } 0652 var fileTags = ''; 0653 if (data.file.tags) { 0654 fileTags = data.file.tags; 0655 } 0656 0657 //var tagOptions = UserTags.getTagOptions(); 0658 0659 var tableString = ''; 0660 tableString += '<tr data-ppload-file-id="' + data.file.id + '" data-ppload-file-category="' + fileCategory + '" data-ppload-file-tags="' + fileTags + '">'; 0661 tableString += '<td><a href="' + pploadApiUri + 'files/download/'; 0662 tableString += 'id/' + data.file.id + '/' + data.file.name + '">' + data.file.name + '</a></td>'; 0663 if(data.file.md5sum != 'NULL' && data.file.md5sum != 'null' && data.file.md5sum != null) { 0664 tableString += '<td>' + data.file.md5sum + '</td>'; 0665 } else { 0666 tableString += '<td></td>'; 0667 } 0668 tableString += '<td>' + version + '</td>'; 0669 tableString += '<td><input data-ppload-file-description="" class="form-control input-sm"'; 0670 tableString += ' type="text" maxlength="140" placeholder="File description"'; 0671 tableString += ' value="' + fileDescription + '"></td>'; 0672 0673 var fileId = data.file.id; 0674 0675 0676 //get cat-tag-groups 0677 var tagGroups = null; 0678 var tagGroupsCount = 0; 0679 var catId = $modalPpload.attr('data-product-cat-id'); 0680 0681 $.ajax({ 0682 url: '/p/'+$modalPpload.attr('data-product-id')+'/gettaggroupsforcatajax', 0683 type: 'GET', 0684 async: false, 0685 cache: false, 0686 timeout: 30000, 0687 data: {project_cat_id: catId}, 0688 dataType: 'json', 0689 success: function (data, textStatus, jqXHR) { 0690 tagGroups = data.tag_groups; 0691 tagGroupsCount = data.ResultSize; 0692 }, 0693 error: function (jqXHR, textStatus, errorThrown) { 0694 return; 0695 } 0696 }); 0697 0698 if(tagGroupsCount>0) { 0699 $.each(tagGroups, function() { 0700 tableString += '<td>'; 0701 0702 if(this.is_multi_select == 1) { 0703 tableString +='<select multiple="multiple" id="data-select-' + this.group_legacy_name + fileId + '" data-'+this.group_legacy_name+'-id="" data-tag-group-id="' + this.tag_group_id + '" data-tag-group="' + this.group_legacy_name + '" name="' + this.group_legacy_name + '" class="multi" style="width: 150px;">'; 0704 } else { 0705 tableString +='<select id="data-select-' + this.group_legacy_name + fileId + '" data-'+this.group_legacy_name+'-id="" data-tag-group-id="' + this.tag_group_id + '" data-tag-group="' + this.group_legacy_name + '" name="' + this.group_legacy_name + '" class="" style="width: 150px;">'; 0706 tableString +='<option value=""></option>'; 0707 } 0708 0709 0710 0711 //tableString +='<select id="data-select-' + this.group_legacy_name + fileId + '" data-'+this.group_legacy_name+'-id="" data-tag-group-id="' + this.tag_group_id + '" data-tag-group="' + this.group_legacy_name + '" name="' + this.group_legacy_name + '" class="form-control input-sm" style="width: 150px;">'; 0712 //tableString += '<option value=\"\"></option>'; 0713 0714 for(key in this.tag_list) { 0715 tableString += '<option value=\"'+key+'\"'; 0716 if(null != this.selected_tags) { 0717 $.each(this.selected_tags, function() { 0718 if(key == this.tag_id) { 0719 tableString += ' selected="selected"'; 0720 } 0721 }) 0722 } 0723 0724 tableString += '>' + this.tag_list[key] + '</option>'; 0725 } 0726 0727 tableString += '</select>'; 0728 tableString += '</td>'; 0729 }); 0730 } else { 0731 tableString += '<td></td>'; 0732 } 0733 0734 0735 tableString += '<td>' + data.file.created_timestamp + '</td>'; 0736 tableString += '<td style="text-align: right">' + humanFileSize(data.file.size) + '</td>'; 0737 tableString +='<td style="text-align: right">0</td>'; 0738 tableString += '<td><a href="#" class="btn btn-native btn-xs btn-file-dropzone" data-updatepploadfile-btn="">Update</a></td>'; 0739 tableString += '<td><a href="#" class="btn btn-native btn-xs btn-file-dropzone" data-deletepploadfile-btn=""><span class="glyphicon glyphicon-trash"></span></a></td>'; 0740 tableString += '</tr>'; 0741 $modalPpload.find('table[data-ppload-files] tbody').append(tableString); 0742 0743 $('.multi').multiselect({ 0744 includeSelectAllOption: true, 0745 buttonClass: 'btn btn-native btn-xs' 0746 }); 0747 0748 //UserTags.activateSelect(data.file.id, ''); 0749 0750 $modalPpload.find('button[data-deletepploadfiles-btn]').removeAttr('disabled'); 0751 $modalPpload.find('button[data-file-upload-ok-btn]').removeAttr('disabled'); 0752 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 0753 startUploadPploadFiles(); 0754 }, 0755 error: function (jqXHR, textStatus, errorThrown) { 0756 alert("Error: " + textStatus + ", " + errorThrown); 0757 return; 0758 } 0759 }); 0760 } 0761 0762 function updatePploadFile(fileId, fileDescription, fileCategory, fileTags) { 0763 $.ajax({ 0764 url: $modalPpload.attr('data-updatepploadfile-uri'), 0765 type: 'POST', 0766 data: { 0767 file_id: fileId, 0768 file_description: fileDescription, 0769 file_category: fileCategory 0770 }, 0771 dataType: 'json', 0772 success: function (data, textStatus, jqXHR) { 0773 if (data.status != 'ok') { 0774 return; 0775 } 0776 0777 }, 0778 error: function (jqXHR, textStatus, errorThrown) { 0779 alert("Error: " + textStatus + ", " + errorThrown); 0780 return; 0781 } 0782 }); 0783 } 0784 0785 function updateFileTag(fileId, tagId, tagGroupId) { 0786 $.ajax({ 0787 url: $modalPpload.attr('data-updatefiletag-uri'), 0788 type: 'POST', 0789 data: { 0790 file_id: fileId, 0791 tag_id: tagId, 0792 tag_group_id: tagGroupId 0793 }, 0794 dataType: 'json', 0795 success: function (data, textStatus, jqXHR) { 0796 if (data.status != 'ok') { 0797 return; 0798 } 0799 0800 }, 0801 error: function (jqXHR, textStatus, errorThrown) { 0802 alert("Error: " + textStatus + ", " + errorThrown); 0803 return; 0804 } 0805 }); 0806 } 0807 0808 function deleteFileTag(fileId, tagId) { 0809 $.ajax({ 0810 url: $modalPpload.attr('data-deletefiletag-uri'), 0811 type: 'POST', 0812 data: { 0813 file_id: fileId, 0814 tag_id: tagId 0815 }, 0816 dataType: 'json', 0817 success: function (data, textStatus, jqXHR) { 0818 if (data.status == 'ok') { 0819 $('#file-tag-'+fileId+'-'+tagId).remove(); 0820 return true; 0821 } 0822 0823 }, 0824 error: function (jqXHR, textStatus, errorThrown) { 0825 alert("Error: " + textStatus + ", " + errorThrown); 0826 return false; 0827 } 0828 }); 0829 0830 } 0831 0832 function updatePploadFileVersion(fileId, version) { 0833 version = version.replace(/<\/?[^>]+(>|$)/g, ""); 0834 $.ajax({ 0835 url: $modalPpload.attr('data-updatepploadfile-uri'), 0836 type: 'POST', 0837 data: { 0838 file_id: fileId, 0839 file_version: version 0840 }, 0841 dataType: 'json', 0842 success: function (data, textStatus, jqXHR) { 0843 if (data.status != 'ok') { 0844 return; 0845 } 0846 0847 }, 0848 error: function (jqXHR, textStatus, errorThrown) { 0849 alert("Error: " + textStatus + ", " + errorThrown); 0850 return; 0851 } 0852 }); 0853 } 0854 0855 function updatePploadFileTags(fileId, fileTags) { 0856 $.ajax({ 0857 url: $modalPpload.attr('data-updatepploadfile-uri'), 0858 type: 'POST', 0859 data: { 0860 file_id: fileId, 0861 file_tags: fileTags 0862 }, 0863 dataType: 'json', 0864 success: function (data, textStatus, jqXHR) { 0865 if (data.status != 'ok') { 0866 return; 0867 } 0868 0869 }, 0870 error: function (jqXHR, textStatus, errorThrown) { 0871 alert("Error: " + textStatus + ", " + errorThrown); 0872 return; 0873 } 0874 }); 0875 } 0876 0877 function deletePploadFile(fileId) { 0878 $.ajax({ 0879 url: $modalPpload.attr('data-deletepploadfile-uri'), 0880 type: 'POST', 0881 data: {file_id: fileId}, 0882 dataType: 'json', 0883 success: function (data, textStatus, jqXHR) { 0884 if (data.status != 'ok') { 0885 //alert('Error: ' + data.error_text); 0886 return; 0887 } 0888 $modalPpload.find('table[data-ppload-files] thead').html(''); 0889 $modalPpload.find('table[data-ppload-files] tbody').html(''); 0890 $modalPpload.find('table[data-file-upload] tbody').html(''); 0891 getPploadFiles(); 0892 /** 0893 $modalPpload.find('tr[data-ppload-file-id="' + fileId + '"]').remove(); 0894 if ($modalPpload.find('tr[data-ppload-file-id]').size() === 0) { 0895 $modalPpload.find('table[data-ppload-files] tbody').html(''); 0896 $modalPpload.find('table[data-file-upload] tbody').html(''); 0897 $modalPpload.find('p[data-file-upload-msg]').show(); 0898 $modalPpload.find('button[data-deletepploadfiles-btn]').attr('disabled', 'disabled'); 0899 $modalPpload.find('button[data-file-upload-ok-btn]').removeAttr('disabled'); 0900 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 0901 0902 if ($modalPpload.find('input[data-accept-checkbox]').is('checked')) { 0903 $modalPpload.find('button[data-addpploadfile-btn]').removeAttr('disabled'); 0904 } else { 0905 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 0906 } 0907 0908 } 0909 **/ 0910 }, 0911 error: function (jqXHR, textStatus, errorThrown) { 0912 //alert("Error: " + textStatus + ", " + errorThrown); 0913 return; 0914 } 0915 }); 0916 } 0917 0918 function deletePploadFiles() { 0919 $.ajax({ 0920 url: $modalPpload.attr('data-deletepploadfiles-uri'), 0921 type: 'POST', 0922 data: {}, 0923 dataType: 'json', 0924 success: function (data, textStatus, jqXHR) { 0925 if (data.status != 'ok') { 0926 return; 0927 } 0928 $modalPpload.find('table[data-ppload-files] thead').html(''); 0929 $modalPpload.find('table[data-ppload-files] tbody').html(''); 0930 $modalPpload.find('table[data-file-upload] tbody').html(''); 0931 $modalPpload.find('p[data-file-upload-msg]').show(); 0932 0933 //$modalPpload.find('button[data-addpploadfile-btn]').removeAttr('disabled'); 0934 $modalPpload.find('button[data-deletepploadfiles-btn]').attr('disabled', 'disabled'); 0935 $modalPpload.find('button[data-file-upload-ok-btn]').removeAttr('disabled'); 0936 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 0937 0938 $modalPpload.find('input[data-accept-checkbox]').removeAttr('disabled'); 0939 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 0940 }, 0941 error: function (jqXHR, textStatus, errorThrown) { 0942 return; 0943 } 0944 }); 0945 } 0946 0947 function humanFileSize(bytes) { 0948 var size = ''; 0949 size = (bytes / 1048576).toFixed(2) + ' MB'; 0950 /* 0951 if (bytes >= 1073741824) { 0952 size = (bytes / 1073741824).toFixed(2) + 'GB'; 0953 } 0954 else if (bytes >= 1048576) { 0955 size = (bytes / 1048576).toFixed(2) + 'MB'; 0956 } 0957 else if (bytes >= 1024) { 0958 size = (bytes / 1024).toFixed(2) + 'KB'; 0959 } 0960 else { 0961 size = bytes + 'bytes'; 0962 }*/ 0963 return size; 0964 } 0965 0966 $('a[href="#modal-ppload"]').off('click').on('click', function (event) { 0967 event.preventDefault(); 0968 $modalPpload.attr('data-ppload-collection-id', $(this).attr('data-ppload-collection-id')); 0969 $modalPpload.attr('data-product-id', $(this).attr('data-product-id')); 0970 $modalPpload.attr('data-product-cat-id', $(this).attr('data-product-cat-id')); 0971 $modalPpload.attr('data-product-tile', $(this).attr('data-product-title')); 0972 $modalPpload.attr('data-product-version', $(this).attr('data-product-version')); 0973 $modalPpload.attr('data-addpploadfile-uri', $(this).attr('data-addpploadfile-uri')); 0974 $modalPpload.attr('data-updatefiletag-uri', $(this).attr('data-updatefiletag-uri')); 0975 $modalPpload.attr('data-deletefiletag-uri', $(this).attr('data-deletefiletag-uri')); 0976 $modalPpload.attr('data-updatepploadfile-uri', $(this).attr('data-updatepploadfile-uri')); 0977 $modalPpload.attr('data-deletepploadfile-uri', $(this).attr('data-deletepploadfile-uri')); 0978 $modalPpload.attr('data-deletepploadfiles-uri', $(this).attr('data-deletepploadfiles-uri')); 0979 $modalPpload.find('div[data-file-upload]').css({ 0980 'min-height': '200px', 0981 'max-height': '400px', 0982 'border-width': '5px', 0983 'border-style': 'dashed', 0984 'border-color': '#cccccc', 0985 'overflow': 'inherit' 0986 }); 0987 0988 $modalPpload.find('h3[data-ppload-label]').html('Files for ' + $modalPpload.attr('data-product-tile')); 0989 $modalPpload.find('#product-version').val($modalPpload.attr('data-product-version')); 0990 0991 $modalPpload.find('table[data-ppload-files] thead').html(''); 0992 $modalPpload.find('table[data-ppload-files] tbody').html(''); 0993 $modalPpload.find('table[data-file-upload] tbody').html(''); 0994 $modalPpload.find('p[data-file-upload-msg]').show(); 0995 0996 $modalPpload.find('#update-list').html(''); 0997 0998 $modalPpload.find('input[data-accept-checkbox]').removeAttr('disabled'); 0999 1000 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 1001 $modalPpload.find('button[data-deletepploadfiles-btn]').attr('disabled', 'disabled'); 1002 $modalPpload.find('button[data-file-upload-ok-btn]').removeAttr('disabled'); 1003 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 1004 1005 if ($modalPpload.attr('data-ppload-collection-id')) { 1006 getPploadFiles(); 1007 } 1008 1009 }); 1010 1011 $modalPpload.off('dragover', 'div[data-file-upload]').on('dragover', 'div[data-file-upload]', function (event) { 1012 event.preventDefault(); 1013 }); 1014 1015 $modalPpload.off('dragenter', 'div[data-file-upload]').on('dragenter', 'div[data-file-upload]', function (event) { 1016 event.preventDefault(); 1017 $(this).css('border-color', '#00ccff'); 1018 }); 1019 1020 $modalPpload.off('dragleave', 'div[data-file-upload]').on('dragleave', 'div[data-file-upload]', function (event) { 1021 event.preventDefault(); 1022 $(this).css('border-color', '#cccccc'); 1023 }); 1024 1025 $modalPpload.off('drop', 'div[data-file-upload]').on('drop', 'div[data-file-upload]', function (event) { 1026 event.preventDefault(); 1027 $.each(event.originalEvent.dataTransfer.files, function () { 1028 addFileToPploadUploadQueue(null, this); 1029 }); 1030 startUploadPploadFiles(); 1031 $(this).css('border-color', '#cccccc'); 1032 }); 1033 1034 $modalPpload.off('change', 'input[data-file-upload]').on('change', 'input[data-file-upload]', function (event) { 1035 $.each(this.files, function () { 1036 addFileToPploadUploadQueue(null, this); 1037 }); 1038 startUploadPploadFiles(); 1039 }); 1040 1041 $modalPpload.off('click', 'button[data-addpploadfile-btn]').on('click', 'button[data-addpploadfile-btn]', function (event) { 1042 event.preventDefault(); 1043 $modalPpload.find('input[data-file-upload]').click(); 1044 }); 1045 1046 $modalPpload.off('change', 'input[data-file-upload-update]').on('change', 'input[data-file-upload-update]', function (event) { 1047 if ($(this).attr('data-ppload-file-id')) { 1048 var fileId = $(this).attr('data-ppload-file-id'); 1049 $modalPpload.find('tr[data-ppload-file-id="' + fileId + '"]').hide(); 1050 addFileToPploadUploadQueue(fileId, this.files[0]); 1051 startUploadPploadFiles(); 1052 } 1053 }); 1054 1055 $modalPpload.off('click', 'tr[data-ppload-file-id] a[data-updatepploadfile-btn]').on('click', 'tr[data-ppload-file-id] a[data-updatepploadfile-btn]', function (event) { 1056 event.preventDefault(); 1057 var $inputForm = $modalPpload.find('input[data-file-upload-update]'); 1058 $inputForm.attr('data-ppload-file-id', $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id')); 1059 $inputForm.click(); 1060 }); 1061 1062 $modalPpload.off('click', 'input[data-accept-checkbox]').on('click', 'input[data-accept-checkbox]', function (event) { 1063 if ($modalPpload.find('input[data-accept-checkbox]').is(':checked')) { 1064 $modalPpload.find('button[data-addpploadfile-btn]').removeAttr('disabled'); 1065 $modalPpload.find('#github_picker').removeAttr('disabled'); 1066 } else { 1067 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 1068 $modalPpload.find('#github_picker').attr('disabled', 'disabled'); 1069 } 1070 }); 1071 1072 $modalPpload.off('click', 'tr[data-ppload-file-id] a[data-deletepploadfile-btn]').on('click', 'tr[data-ppload-file-id] a[data-deletepploadfile-btn]', function (event) { 1073 event.preventDefault(); 1074 deletePploadFile($(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id')); 1075 }); 1076 1077 $modalPpload.off('click', 'button[data-deletepploadfiles-btn]').on('click', 'button[data-deletepploadfiles-btn]', function (event) { 1078 event.preventDefault(); 1079 deletePploadFiles(); 1080 }); 1081 1082 $modalPpload.off('click', 'button[data-ppload-cancel-btn]').on('click', 'button[data-ppload-cancel-btn]', function (event) { 1083 event.preventDefault(); 1084 $modalPpload.modal('hide'); 1085 }); 1086 1087 $modalPpload.off('click', 'button[data-file-upload-cancel-btn]').on('click', 'button[data-file-upload-cancel-btn]', function (event) { 1088 event.preventDefault(); 1089 pploadUploads.uploading.abort(); 1090 pploadUploads.queue = {}; 1091 $modalPpload.find('table[data-file-upload] tbody').html(''); 1092 }); 1093 1094 $modalPpload.off('click', 'tr[data-file-upload-id] a[data-file-upload-cancel-btn]').on('click', 'tr[data-file-upload-id] a[data-file-upload-cancel-btn]', function (event) { 1095 event.preventDefault(); 1096 var uploadId = $(this).closest('tr[data-file-upload-id]').attr('data-file-upload-id'); 1097 if (uploadId == pploadUploads.currentUploadId) { 1098 pploadUploads.uploading.abort(); 1099 } 1100 else { 1101 delete pploadUploads.queue[uploadId]; 1102 $modalPpload.find('tr[data-file-upload-id="' + uploadId + '"]').remove(); 1103 } 1104 }); 1105 1106 $modalPpload.off('change', 'input[data-ppload-file-description]').on('change', 'input[data-ppload-file-description]', function (event) { 1107 event.preventDefault(); 1108 var fileId = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id'); 1109 var fileDescription = $(this).closest('input[data-ppload-file-description]').val(); 1110 var fileCategory = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-category'); 1111 var fileTags = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-tags'); 1112 1113 $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-tags', fileTags); 1114 fileDescription = fileDescription.replace(/<\/?[^>]+(>|$)/g, ""); 1115 updatePploadFile(fileId, fileDescription, fileCategory, fileTags); 1116 }); 1117 1118 $modalPpload.off('change', 'input[data-ppload-file-version]').on('change', 'input[data-ppload-file-version]', function (event) { 1119 event.preventDefault(); 1120 var fileId = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id'); 1121 var fileVersion = $(this).closest('input[data-ppload-file-version]').val(); 1122 updatePploadFileVersion(fileId, fileVersion); 1123 }); 1124 1125 $modalPpload.off('change', 'select[data-tag-group]').on('change', 'select[data-tag-group]', function(event) { 1126 event.preventDefault(); 1127 var fileId = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id'); 1128 var fileTags = $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags'); 1129 var tagId = $(this).val(); 1130 var tagGroupId = $(this).attr('data-tag-group-id'); 1131 var tagGroupName = $(this).attr('data-tag-group'); 1132 1133 var newFileTags = ''; 1134 if (fileTags) { 1135 1136 $.each(fileTags.split(','), function () { 1137 // skip old entries 1138 if ((this.length == 0) || (this.indexOf(tagGroupName+'id-') == 0) || (this.indexOf(tagGroupName+'id##') == 0)) { 1139 return true; 1140 } 1141 newFileTags += ',' + this; 1142 }); 1143 1144 } 1145 newFileTags += ','+tagGroupName+'id-'+tagId; 1146 //updatePploadFileTags(fileId, newFileTags); 1147 $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags',newFileTags); 1148 updateFileTag(fileId, tagId, tagGroupId); 1149 }); 1150 1151 1152 $modalPpload.off('click', 'span[data-file-tag-id]').on('click', 'span[data-file-tag-id]', function (event) { 1153 event.preventDefault(); 1154 1155 $tagId = $(this).attr('data-file-tag-id'); 1156 $fileId = $(this).attr('data-file-id'); 1157 var fileTags = $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags'); 1158 1159 /* 1160 var newFileTags = ''; 1161 if (fileTags) { 1162 1163 $.each(fileTags.split(','), function () { 1164 // skip old entries 1165 if ((this.length == 0) || (this.indexOf(tagGroupName+'id-') == 0) || (this.indexOf(tagGroupName+'id##') == 0)) { 1166 return true; 1167 } 1168 newFileTags += ',' + this; 1169 }); 1170 1171 } 1172 newFileTags += ','+tagGroupName+'id-'+tagId; 1173 updatePploadFileTags(fileId, newFileTags); 1174 1175 $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags',newFileTags); 1176 1177 */ 1178 deleteFileTag($fileId, $tagId); 1179 }); 1180 1181 1182 1183 1184 var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}} 1185 1186 $('button[rel="tooltip"]').tooltip(); 1187 1188 var $modalUpdates = $('#modal-updates'); 1189 1190 $('a[href="#modal-updates"]').off('click').on('click', function (event) { 1191 event.preventDefault(); 1192 1193 $modalUpdates.attr('data-product-id', $(this).attr('data-product-id')); 1194 $modalUpdates.attr('data-product-title', $(this).attr('data-product-title')); 1195 1196 $modalUpdates.find('h3[data-ppload-label]').html('Changelog for ' + $modalUpdates.attr('data-product-tile')); 1197 1198 $modalUpdates.find('#update-list').html(''); 1199 1200 if ($modalUpdates.attr('data-product-id')) { 1201 getUpdates(); 1202 } 1203 1204 }); 1205 1206 1207 function getUpdates(page) { 1208 $modalUpdates.find('#update-list').html(''); 1209 1210 var productId = $modalUpdates.attr('data-product-id'); 1211 $.ajax({ 1212 url: '/p/'+productId+'/getupdatesajax/', 1213 type: 'GET', 1214 data: { 1215 format: 'json', 1216 ignore_status_code: 1 1217 }, 1218 dataType: 'json', 1219 success: function (data, textStatus, jqXHR) { 1220 if (data.status != 'success') { 1221 return; 1222 } 1223 $modalUpdates.find('#update-list').append('<br/><br/><br/>'); 1224 1225 $.each(data.updates, function () { 1226 var id = ''; 1227 if (this.project_update_id) { 1228 id = this.project_update_id; 1229 } 1230 var title = ''; 1231 if (this.title) { 1232 title = this.title; 1233 } 1234 var text = ''; 1235 if (this.text) { 1236 text = this.text; 1237 } 1238 var date = ''; 1239 if (this.created_at) { 1240 date = this.created_at; 1241 } 1242 1243 1244 var divEl = $('<div />'); 1245 divEl.attr('data-uptdate-id', id); 1246 divEl.append( 1247 '<a name="anker_'+id+'"></a>' 1248 + '<h4>'+title+'</h4>' 1249 + '<div class="small light lightgrey product-update-date">'+date+ '</div>' 1250 + text + '<br/><br/>' 1251 ); 1252 1253 var btnEdit = $('<button type="submit" class="btn btn-native btn-sm">Edit</button>'); 1254 btnEdit.attr('data-change-update-btn',id); 1255 btnEdit.attr('data-change-title',title); 1256 btnEdit.attr('data-change-text',text); 1257 1258 1259 var btnDelete = $('<button type="submit" class="btn btn-native btn-sm">Delete</button>'); 1260 btnDelete.attr('data-delete-update-btn',id); 1261 1262 divEl.append(btnEdit); 1263 divEl.append(' '); 1264 divEl.append(btnDelete); 1265 divEl.append('<br/><br/><br/><br/>'); 1266 1267 $modalUpdates.find('#update-list').append(divEl); 1268 1269 }); 1270 }, 1271 error: function (jqXHR, textStatus, errorThrown) { 1272 return; 1273 } 1274 }); 1275 1276 } 1277 1278 $modalUpdates.off('click', 'button[data-add-update-btn]').on('click', 'button[data-add-update-btn]', function (event) { 1279 //var product_version = $modalPpload.find('#product-version').val(); 1280 var update_id = $modalUpdates.find('#update-id').val(); 1281 var title = $modalUpdates.find('#update-title').val(); 1282 var text = $modalUpdates.find('#update-text').val(); 1283 var productId = $modalUpdates.attr('data-product-id'); 1284 event.preventDefault(); 1285 1286 $.ajax({ 1287 url: '/p/'+productId+'/saveupdateajax', 1288 type: 'POST', 1289 data: {title: title, text: text, update_id: update_id/*, product_version: product_version*/}, 1290 dataType: 'json', 1291 success: function (data, textStatus, jqXHR) { 1292 if (data.status != 'success') { 1293 return; 1294 } 1295 //$modalPpload.find('#product-version').val(''); 1296 $modalUpdates.find('#update-title').val(''); 1297 $modalUpdates.find('#update-text').val(''); 1298 $modalUpdates.find('#update-id').val(''); 1299 1300 //if(update_id) { 1301 getUpdates(); 1302 //} else { 1303 // $modalPpload.modal('hide'); 1304 // location.reload(); 1305 //} 1306 }, 1307 error: function (jqXHR, textStatus, errorThrown) { 1308 return; 1309 } 1310 }); 1311 1312 }); 1313 1314 1315 $modalUpdates.off('click', 'button[data-delete-update-btn]').on('click', 'button[data-delete-update-btn]', function (event) { 1316 var updateId = $(this).attr('data-delete-update-btn'); 1317 var productId = $modalUpdates.attr('data-product-id'); 1318 event.preventDefault(); 1319 1320 $.ajax({ 1321 url: '/p/'+productId+'/deleteupdateajax', 1322 type: 'POST', 1323 data: {update_id: updateId}, 1324 dataType: 'json', 1325 success: function (data, textStatus, jqXHR) { 1326 if (data.status != 'success') { 1327 alert('Update could not be deleted!'); 1328 return; 1329 } 1330 getUpdates(); 1331 }, 1332 error: function (jqXHR, textStatus, errorThrown) { 1333 return; 1334 } 1335 }); 1336 1337 }); 1338 1339 $modalUpdates.off('click', 'button[data-change-update-btn]').on('click', 'button[data-change-update-btn]', function (event) { 1340 var updateId = $(this).attr('data-change-update-btn'); 1341 var title = $(this).attr('data-change-title'); 1342 var text = $(this).attr('data-change-text'); 1343 1344 $modalUpdates.find('#update-title').val(title); 1345 $modalUpdates.find('#update-text').val(text); 1346 $modalUpdates.find('#update-id').val(updateId); 1347 1348 $modalUpdates.find('#update-title').focus(); 1349 1350 event.preventDefault(); 1351 1352 }); 1353 1354 $modalUpdates.off('click', 'button[data-updates-cancel-btn]').on('click', 'button[data-updates-cancel-btn]', function (event) { 1355 event.preventDefault(); 1356 $modalUpdates.modal('hide'); 1357 }); 1358 1359 } 1360 } 1361 })(); 1362 </script> 1363 <!-- updates --> 1364 <div id="modal-updates" 1365 class="modal fade" 1366 role="dialog" 1367 aria-labelledby="modal-updates-label" 1368 data-product-id="" 1369 data-product-title=""> 1370 <div class="modal-dialog content-modal" style="width: 95%"> 1371 <div class="modal-content"> 1372 <div class="modal-header"> 1373 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 1374 <h3 id="modal-updates-label" data-updates-label=""><?= $this->translate('Changelog') ?></h3> 1375 </div> 1376 <div class="modal-body" style="font-size: small;"> 1377 <div role="form" class=""> 1378 <input type="hidden" id="update-id" data-update-id="" value=""> 1379 <?php /** 1380 <div class="form-group"> 1381 <label for="tile">Product Version:</label> 1382 <input type="text" id="product-version" data-product-version="" class="form-control input-sm" placeholder="Product Version Number"> 1383 </div> 1384 * 1385 */?> 1386 <div class="form-group"> 1387 <label for="tile">Changelog Title:</label> 1388 <input type="text" id="update-title" data-update-title="" class="form-control input-sm" placeholder="Enter a Changelog Title"> 1389 </div> 1390 <div class="form-group"> 1391 <label for="text">Changelog Text:</label> 1392 <textarea id="update-text" data-update-text="" class="form-control input-sm" rows="3" placeholder="Enter a Changelog Text"></textarea> 1393 </div> 1394 <button class="btn btn-native pull-right btn-xs btn-file-action" data-updates-cancel-btn=""><?= $this->translate('Cancel') ?></button> 1395 <button type="submit" class="btn btn-native pull-right btn-xs btn-file-action" data-add-update-btn="">Save</button> 1396 </div> 1397 1398 <article id="update-list"> 1399 </article> 1400 1401 1402 </div> 1403 <div class="modal-footer"> 1404 1405 </div> 1406 </div> 1407 </div> 1408 </div> 1409 1410 <!-- ppload --> 1411 1412 <div id="modal-ppload" 1413 class="modal fade" 1414 role="dialog" 1415 aria-labelledby="modal-ppload-label" 1416 data-ppload-api-uri="<?= PPLOAD_API_URI ?>" 1417 data-ppload-collection-id="" 1418 data-product-version="" 1419 data-product-id="" 1420 data-product-cat-id="" 1421 data-product-tile="" 1422 data-addpploadfile-uri="" 1423 data-updatepploadfile-uri="" 1424 data-updatefiletag-uri="" 1425 data-deletefiletag-uri="" 1426 data-deletepploadfile-uri="" 1427 data-deletepploadfiles-uri=""> 1428 <div class="modal-dialog content-modal" style="width: 95%"> 1429 <div class="modal-content"> 1430 <div class="modal-header"> 1431 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 1432 <h3 id="modal-ppload-label" data-ppload-label=""><?= $this->translate('Files') ?></h3> 1433 </div> 1434 <div class="modal-body"> 1435 <input type="file" style="display: none;" data-file-upload="" multiple> 1436 <input type="file" style="display: none;" data-file-upload-update="" data-ppload-file-id=""> 1437 1438 <p data-file-upload-msg=""><?= $this->translate('Drop file(s) here') ?>:</p> 1439 1440 <div data-file-upload="" dropzone style="font-size: small; " class="datafiledroparea"> 1441 <table class="table" data-ppload-files=""> 1442 <thead> 1443 1444 </thead> 1445 <tbody></tbody> 1446 </table> 1447 <table class="table" data-file-upload=""> 1448 <tbody></tbody> 1449 </table> 1450 </div> 1451 1452 1453 <div style="float: right; padding-top: 10px;" class="small light"> 1454 Deleted files are archived. Number of downloads are kept. * 1455 </div> 1456 </div> 1457 1458 <div class="modal-footer" style="margin-top: 20px;"> 1459 <span class="pull-left"> 1460 <input type="checkbox" data-accept-checkbox=""> 1461 <?= $this->translate('I accept the ') ?> 1462 <a href="/content/terms"><?= $this->translate('Terms and Conditions') ?></a> 1463 </span> 1464 1465 </div> 1466 <div class="modal-footer"> 1467 <button class="btn btn-native pull-left" data-addpploadfile-btn=""> 1468 <?= $this->translate('Add File(s)') ?> 1469 </button> 1470 <button class="btn btn-danger pull-left" data-file-upload-cancel-btn=""> 1471 <?= $this->translate('Cancel Upload') ?> 1472 </button> 1473 <button id="github_picker" class="btn btn-native pull-left" data-toggle="" data-target="#generic-dialog" data-username="<?=$this->member->link_github?>" title="add an URL here"> 1474 <?= $this->translate('Add URL') ?> 1475 </button> 1476 <button class="btn btn-native pull-right" data-ppload-cancel-btn=""><?= $this->translate('Close') ?></button> 1477 </div> 1478 <div class="modal-footer"> 1479 1480 </div> 1481 </div> 1482 </div> 1483 </div> 1484 1485 <script type="text/javascript" src="/theme/flatui/js/lib/chosen.jquery.min.js"></script> 1486 <!-- /ppload --> 1487 1488 <?php 1489 $this->inlineScript()->appendScript( 1490 ' $(document).ready(function(){ 1491 TagingLoopMyProducts.setup(); 1492 Opendownloadfile.setup(); 1493 myProducts.setup(); 1494 Partials.setup(); 1495 }); 1496 '); 1497 1498 ?>