File indexing completed on 2025-05-04 05:29:26
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 0024 0025 //$this->os = Zend_Registry::get('application_os'); 0026 $this->tab = 'add'; 0027 $helperImage = new Default_View_Helper_Image(); 0028 $helpMemberUrl = new Default_View_Helper_BuildMemberUrl(); 0029 $helpProductUrl = new Default_View_Helper_BuildProductUrl(); 0030 $helpBaseUrl = new Default_View_Helper_BuildBaseUrl(); 0031 0032 $helperUserRole = new Backend_View_Helper_UserRole(); 0033 $userRoleName = $helperUserRole->userRole(); 0034 $isAdmin = false; 0035 if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { 0036 $isAdmin = true; 0037 } 0038 0039 $modelCategory = new Default_Model_DbTable_ProjectCategory(); 0040 $valueCatId = $this->form->project_category_id->getValue(); 0041 //$valueCatId = 55; 0042 if($this->catId) 0043 { 0044 $valueCatId = $this->catId; 0045 } 0046 $storeCatIds = Zend_Registry::isRegistered('store_category_list') ? Zend_Registry::get('store_category_list') : null; 0047 0048 $categoryAncestors = $modelCategory->fetchAncestorsAsId($valueCatId); 0049 0050 $categories = $modelCategory->fetchCategoriesForFormNew($valueCatId); 0051 $categoriesFallback = $modelCategory->fetchCategoriesForForm($valueCatId); 0052 //$categories2 = array(); 0053 0054 0055 if (count($categoryAncestors) > 0) { 0056 $categoryPath = explode(',',$categoryAncestors['ancestors']); 0057 } 0058 $categoryPath[] = $valueCatId; 0059 0060 0061 $this->headLink()->appendStylesheet('/theme/flatui/css/chosen.css'); 0062 $this->inlineScript()->appendFile('/theme/flatui/js/lib/chosen.jquery.min.js'); 0063 $this->inlineScript()->appendScript(' 0064 $(document).ready(function(){ 0065 $("select.chosen").chosen({ 0066 width: "100%", 0067 max_selected_options: "5", 0068 disable_search: "false", 0069 disable_search_threshold: "5" 0070 }); 0071 }); 0072 '); 0073 0074 ?> 0075 <style> 0076 0077 .wizard, .tabcontrol { 0078 overflow: visible; 0079 } 0080 0081 .wizard > .content { 0082 overflow: visible; 0083 } 0084 0085 .wizard > .content > .body { 0086 position: relative; 0087 } 0088 0089 input[type=checkbox] { 0090 /*display: none;*/ 0091 } 0092 0093 div.datafiledroparea{ 0094 /*overflow-x: scroll !important; 0095 overflow-y: scroll !important;*/ 0096 } 0097 0098 /* 0099 - Style each label that is directly after the input 0100 - position: relative; will ensure that any position: absolute children will position themselves in relation to it 0101 */ 0102 /* 0103 input[type=checkbox] + label { 0104 display: block; 0105 border-radius: 50%; 0106 position: relative; 0107 box-shadow: 0 0 1px #FFF; 0108 background: #2184be none repeat scroll 0 0; 0109 border: 3px solid #9dc8e2; 0110 color: white; 0111 height: 25px; 0112 transition: all 0.4s ease 0s; 0113 width: 25px; 0114 } 0115 */ 0116 0117 /* Provide a border when hovered and when the checkbox before it is checked */ 0118 input[type=checkbox] + label:hover, 0119 input[type=checkbox]:checked + label { 0120 border: 3px solid #9dc8e2; 0121 box-shadow: 0 0 1px #fff; 0122 } 0123 0124 /* 0125 - Create a pseudo element :after when checked and provide a tick 0126 - Center the content 0127 */ 0128 input[type=checkbox]:checked + label:after { 0129 content: '\2714'; /*content is required, though it can be empty - content: '';*/ 0130 bottom: 2px; 0131 color: white; 0132 display: block; 0133 height: 1em; 0134 left: 3px; 0135 margin: auto; 0136 position: absolute; 0137 right: 0; 0138 top: -4px; 0139 width: 1em; 0140 } 0141 0142 .add-product-page { 0143 padding-top: 15px; 0144 } 0145 0146 section.body { 0147 width: 100% !important; 0148 } 0149 0150 #is_original-element 0151 { 0152 width: 25px; 0153 float: left; 0154 } 0155 0156 #is_gitlab_project 0157 { 0158 width: 25px; 0159 float: left; 0160 } 0161 0162 #gitlab_project_name-element 0163 { 0164 width: 300px; 0165 float: left; 0166 } 0167 0168 #gitlab_project_id 0169 { 0170 width: 300px; 0171 float: left; 0172 } 0173 0174 #show_gitlab_project_issues 0175 { 0176 width: 25px; 0177 float: left; 0178 } 0179 0180 #use_gitlab_project_readme 0181 { 0182 width: 25px; 0183 float: left; 0184 } 0185 0186 .wizard > .content > .body ul.multiselect-container { 0187 list-style: none !important; 0188 } 0189 0190 .wizard > .content > .body button.multiselect { 0191 padding-top: 3px; 0192 padding-bottom: 3px; 0193 } 0194 0195 </style> 0196 0197 <link rel="stylesheet" href="/tools/bootstrap-multiselect/css/bootstrap-multiselect.css" type="text/css"> 0198 <script type="text/javascript" src="/tools/bootstrap-multiselect/js/bootstrap-multiselect.js"></script> 0199 0200 <main class="user-admin-page"> 0201 0202 <?php echo $this->render('user/partials/userHeader_top.phtml'); ?> 0203 0204 <section class="body-wrap"> 0205 0206 <section class="wrapper product-page"> 0207 0208 <!-- PAGE BODY --> 0209 0210 <section class="my-products-page"> 0211 0212 <!-- NAVIGATION --> 0213 0214 <?php echo $this->render('user/partials/userHeader.phtml'); ?> 0215 0216 <?php echo $this->render('product/partials/header.phtml'); ?> 0217 0218 <!-- /NAVIGATION --> 0219 0220 0221 0222 <!-- PAGE BODY --> 0223 0224 <section class="add-product-page"> 0225 0226 0227 <form enctype="multipart/form-data" role="application" class="wizard clearfix" action="" method="post" id="add-product-form"> 0228 <?= $this->form->project_id ?> 0229 <h3>Basics</h3> 0230 <section id="required"> 0231 <div class="form-group"><p class="col-sm-10">(*) Mandatory fields.</p></div> 0232 <div id="preview_img_msg"> 0233 0234 </div> 0235 <?php // $this->form->title ?> 0236 0237 0238 <?php /* 0239 <div class="form-group"> 0240 <div class="col-sm-12 margin-top-15"> 0241 <div class="small grey bold-font pull-left margin-right-5">*</div> 0242 <label class="form-label" for="title">Legal Uploads</label> 0243 </div> 0244 <div class="col-sm-12"> 0245 <div class="alert alert-danger" id="banner-cc"> 0246 <span class=""> 0247 <input id="legal_uploads_only" name="legal_uploads_only" class="required form-control" type="checkbox" style="height: 10px; width: 10px"> 0248 Please only upload legally open source or Creative Commons content, which license does permit uploading it here. 0249 </span> 0250 </div> 0251 0252 </div> 0253 </div> 0254 * 0255 */?> 0256 0257 <div class="form-group"> 0258 <div class="col-sm-12 margin-top-15"> 0259 <div class="small grey bold-font pull-left margin-right-5">*</div> 0260 <label class="form-label" for="title">Product Name (4 letters min.)</label> 0261 </div> 0262 <div class="col-sm-12"> 0263 <input id="title" 0264 class="required form-control valid" 0265 type="text" 0266 name="title" 0267 pattern="[^\x22]+" 0268 <?php //pattern="^[ .\-&_A-z0-9]{1,}$" ?> 0269 <?php // pattern="^[^\\'\^;*!\u0022\$]{1,}$" ?> 0270 value="<?= $this->escape($this->form->title->getValue()) ?>" 0271 title="Please use only letters." 0272 maxlength="60" 0273 aria-required="true" 0274 aria-invalid="false" 0275 data-rule-minlength="4" 0276 data-rule-maxlength="60" 0277 data-msg-minlength="At least 4 chars" 0278 data-msg-maxlength="At most 60 chars"> 0279 <?php if ($this->form->title->getMessages()) { 0280 $errorHtml = ''; 0281 foreach ($this->form->title->getMessages() as $currentError) { 0282 $errorHtml .= '<label id="<?=$this->escape($this->form->title->getName())?>-error" class="error" for="<?=$this->escape($this->form->title->getName())?>">' . $currentError . '</label>'; 0283 } 0284 ?> 0285 <?php echo $errorHtml ?> 0286 <?php } ?> 0287 </div> 0288 </div> 0289 0290 <?= $this->form->project_category_id ?> 0291 <?= $this->form->project_subcategory_id ?> 0292 <?= $this->form->project_sub_subcategory_id ?> 0293 <?= $this->form->description ?> 0294 <?= $this->form->version ?> 0295 0296 <?= $this->form->source_url ?> 0297 0298 <div class="form-group"> 0299 <div class="col-sm-12 margin-top-15"> 0300 <?php /* 0301 <?= $this->form->is_original ?> Check this box, if this is your own original work and not based on something else. If based on some other work you need to change 60%-70% to mark as an original. 0302 */?> 0303 0304 <?php 0305 echo $this->form->is_original_or_modification . " Select Original, if this is your own original work and not based on something else. If based on some other work you need to change 60%-70% to mark as an original. Select Modification, if you changed at least 5-10%. If you changed < 5%, leave blank. <br>For nature or any other camera taken pictures, if you claim you have not used any other picture as base, you need to provide the original picture yourself by uploading the original file as well under \"files\"."; 0306 ?> 0307 0308 </div> 0309 </div> 0310 0311 <?= $this->form->license_tag_id ?> 0312 <?php 0313 if($this->project_id) 0314 { 0315 $tagmodel = new Default_Model_Tags(); 0316 $tagscat = $tagmodel->getTagsCategory($this->project_id, Default_Model_Tags::TAG_TYPE_PROJECT); 0317 if(strlen($tagscat)>0) 0318 { 0319 ?> 0320 <div class="form-group"> 0321 <div class="col-sm-12 margin-top-15"> 0322 <label class="form-label"> System Auto Tags</label> 0323 </div> 0324 <div class="col-sm-12"> 0325 <?php echo $tagscat ; ?> 0326 </div> 0327 </div> 0328 <?php 0329 } 0330 } 0331 ?> 0332 0333 <?= $this->form->tagsuser ?> 0334 0335 0336 <?= $this->form->image_small ?> 0337 <?= $this->form->image_small_upload ?> 0338 <?php //$this->form->image_big ?> 0339 <?php //$this->form->image_big_upload ?> 0340 <?= $this->form->gallery ?> 0341 <?= $this->form->embed_code ?> 0342 0343 <?= $this->form->link_1 ?> 0344 <?= $this->form->facebook_code ?> 0345 <?= $this->form->twitter_code ?> 0346 0347 </section> 0348 0349 <h3>Git</h3> 0350 0351 <section id="git"> 0352 <?php 0353 if(!empty($this->form->gitlab_project_id->getMultiOptions())) { 0354 ?> 0355 0356 0357 <div class="form-group"> 0358 <div class="col-sm-12 margin-top-15"> 0359 <?= $this->form->is_gitlab_project ?> Check this box, if this a public project on opencode.net 0360 </div> 0361 </div> 0362 0363 <?php 0364 if(empty($this->product) || (!empty($this->product) && $this->product->is_gitlab_project == 0)) { 0365 $this->form->gitlab_project_id->setAttrib('disabled', 'disabled'); 0366 } 0367 ?> 0368 <?= $this->form->gitlab_project_id ?> 0369 0370 <div class="form-group"> 0371 <div class="col-sm-12 margin-top-15"> 0372 <?php 0373 if(empty($this->product) || (!empty($this->product) && $this->product->is_gitlab_project == 0)) { 0374 $this->form->show_gitlab_project_issues->setAttrib('disabled', 'disabled'); 0375 } 0376 ?> 0377 <?= $this->form->show_gitlab_project_issues ?> Check this box, if you want to show the issue list 0378 </div> 0379 </div> 0380 0381 <div class="form-group"> 0382 <div class="col-sm-12 margin-top-15"> 0383 <?php 0384 if(empty($this->product) || (!empty($this->product) && $this->product->is_gitlab_project == 0)) { 0385 $this->form->use_gitlab_project_readme->setAttrib('disabled', 'disabled'); 0386 } 0387 ?> 0388 <?= $this->form->use_gitlab_project_readme ?> Check this box, if you want to show the README.md as project description 0389 </div> 0390 </div> 0391 0392 <?php 0393 } else { 0394 ?> 0395 0396 <div class="form-group"> 0397 <div class="col-sm-12 margin-top-15"> 0398 <dt id="is_gitlab_project-label"><label for="is_gitlab_project" class="optional">Git-Project</label></dt> 0399 <dd id="is_gitlab_project-element"> 0400 You can create a project on <a href="https://opencode.net">opencode.net</a> and link it with this project. 0401 </dd> 0402 </div> 0403 </div> 0404 0405 <?php 0406 } 0407 ?> 0408 </section> 0409 0410 0411 0412 0413 <h3>Files</h3> 0414 <section id="files"> 0415 0416 <!-- ppload --> 0417 0418 <div id="modal-ppload" aria-labelledby="modal-ppload-label" 0419 data-ppload-api-uri="<?= PPLOAD_API_URI ?>" 0420 data-ppload-collection-id="<?= $this->ppload_collection_id ?>" data-product-id="" 0421 data-addpploadfile-uri="<?= $helpProductUrl->buildProductUrl('@@project_id@@', 'addpploadfile') ?>" 0422 data-updatepploadfile-uri="<?= $helpProductUrl->buildProductUrl('@@project_id@@', 'updatepploadfile') ?>" 0423 data-updatefiletag-uri="<?= $helpProductUrl->buildProductUrl('@@project_id@@', 'updatefiletag') ?>" 0424 data-deletefiletag-uri="<?= $helpProductUrl->buildProductUrl('@@project_id@@', 'deletefiletag') ?>" 0425 data-deletepploadfile-uri="<?= $helpProductUrl->buildProductUrl('@@project_id@@', 'deletepploadfile') ?>" 0426 data-deletepploadfiles-uri="<?= $helpProductUrl->buildProductUrl('@@project_id@@', 'deletepploadfiles') ?>"> 0427 <div class="pling-modal" style="width: 100%;"> 0428 <div class=""> 0429 <div class="modal-header"> 0430 <!-- <h3 id="modal-ppload-label"><?= $this->translate('Add your Files') ?></h3> --> 0431 </div> 0432 <div class="modal-body"> 0433 <input type="file" style="display: none;" data-file-upload="" multiple accept=""> 0434 <input type="file" style="display: none;" data-file-upload-update="" data-ppload-file-id="" accept=""> 0435 0436 <p data-file-upload-msg=""><?= $this->translate('Drop file(s) here') ?>:</p> 0437 0438 <div data-file-upload="" dropzone class="datafiledroparea" style="overflow: auto !important;"> 0439 <table class="table" data-ppload-files=""> 0440 <thead> 0441 </thead> 0442 <tbody></tbody> 0443 </table> 0444 <table class="table" data-file-upload=""> 0445 <tbody></tbody> 0446 </table> 0447 </div> 0448 0449 </div> 0450 <div style="float: right; padding-top: 10px;" class="small light"> 0451 Deleted files are archived. Number of downloads are kept. * 0452 </div> 0453 </div> 0454 0455 <div class="modal-footer" style="margin-top: 20px;"> 0456 <span class="pull-left"> 0457 <input type="checkbox" data-accept-checkbox=""> <?= $this->translate('I accept the ') ?> 0458 <a href="/content/terms"><?= $this->translate('Terms and Conditions') ?></a> 0459 </span> 0460 </div> 0461 <div class="modal-footer"> 0462 <button class="btn btn-native pull-left" data-addpploadfile-btn=""> 0463 <?= $this->translate('Add File(s)') ?> 0464 </button> 0465 <button class="btn btn-danger pull-right" data-file-upload-cancel-btn=""> 0466 <?= $this->translate('Cancel Upload') ?> 0467 </button> 0468 <a role="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"> 0469 <?= $this->translate('Add URL') ?> 0470 </a> 0471 </div> 0472 </div> 0473 0474 </div> 0475 </div> 0476 0477 <!-- /ppload --> 0478 0479 </section> 0480 0481 0482 <?php if(isset($this->project_id)) { ?> 0483 <h3>Changelog</h3> 0484 <section id="changlog"> 0485 0486 <div id="modal-changlog" data-product-id=""> 0487 <div class="row"> 0488 <div class="modal-header"> 0489 <h3 id="modal-ppload-label"><?= $this->translate('Changelog') ?></h3> 0490 </div> 0491 <div class="modal-body" style="font-size: small;"> 0492 <div role="form" class=""> 0493 <input type="hidden" data-update-id="" id="update-id" value=""> 0494 <div class="form-group"> 0495 <label for="tile">Changelog Title:</label> 0496 <input type="text" id="update-title" data-update-title="" class="form-control input-sm" placeholder="Enter Changelog Title"> 0497 </div> 0498 <div class="form-group"> 0499 <label for="text">Changelog Text:</label> 0500 <textarea id="update-text" data-update-text="" class="form-control input-sm" rows="3" placeholder="Enter Changelog Text"></textarea> 0501 </div> 0502 <button type="submit" class="btn btn-native" data-add-update-btn="">Save Changelog</button> 0503 </div> 0504 0505 <h4 style="padding-top: 15px;"> Your Entries:</h4> 0506 <article id="update-list"> 0507 0508 </article> 0509 </div> 0510 </div> 0511 </div> 0512 <!-- changlog --> 0513 </section> 0514 <?php } ?> 0515 0516 0517 </form> 0518 0519 <!-- /PAGE BODY --> 0520 0521 </section> 0522 0523 <!-- /PAGE BODY --> 0524 0525 </section> 0526 0527 </section> 0528 </section> 0529 </main> 0530 0531 <script> 0532 $(document).ready(function () { 0533 0534 /* 0535 $('.multiple').multiselect({ 0536 includeSelectAllOption: true 0537 }); 0538 */ 0539 0540 var formElement = $('#add-product-form'); 0541 var validator = formElement.validate({ 0542 ignore: ":disabled,:hidden" 0543 }); 0544 formElement.steps({ 0545 headerTag: "h3", 0546 bodyTag: "section", 0547 enableAllSteps: <?php echo ($this->mode == 'edit') ? "true" : "false"; ?>, 0548 enableCancelButton: true, 0549 showFinishButtonAlways: true, 0550 transitionEffect: "slideLeft", 0551 /* Labels */ 0552 labels: { 0553 cancel: "Cancel", 0554 finish: "Save" 0555 }, 0556 onStepChanging: function (event, currentIndex, newIndex) { 0557 // Allways allow previous action even if the current form is not valid! 0558 if (currentIndex > newIndex) { 0559 formElement.find(".body:eq(" + newIndex + ") .bg-danger").removeClass("bg-danger"); 0560 return true; 0561 } 0562 // Needed in some cases if the user went back (clean up) 0563 if (currentIndex < newIndex) { 0564 // To remove error styles 0565 formElement.find(".body:eq(" + newIndex + ") label.error").remove(); 0566 formElement.find(".body:eq(" + newIndex + ") .error").removeClass("error"); 0567 formElement.find(".body:eq(" + newIndex + ") .bg-danger").removeClass("bg-danger"); 0568 } 0569 0570 if (currentIndex == 0) { 0571 if (ImagePreview.hasError) { 0572 return false; 0573 } 0574 //logo OR preview pic mandatory! 0575 var logoSrc = $('#product-picture-preview').attr('src'); 0576 var gallery = $('.product-gallery div:first-child'); 0577 var galleryPic = gallery.find('.image'); 0578 0579 if (!logoSrc && !galleryPic.attr('style')) { 0580 var msg = $('#preview_img_msg'); 0581 msg.text(''); 0582 msg.append('<label id="description-error" class="error" for="product-gallery">Please add a product logo or at least one product gallery picture!</label>'); 0583 0584 return false; 0585 } 0586 0587 if (formElement.valid()) { 0588 if (ProductForm.mode == 'add' && (ProductForm.project_id == '' || ProductForm.project_id == undefined)) { 0589 var result = ProductForm.saveSection(formElement.find('.body:eq(' + currentIndex + ')').attr('id')); 0590 if (result == false) { 0591 validator.showErrors(ProductForm.errors); 0592 return result; 0593 } 0594 formElement.find("#modal-ppload").attr('data-product-id', ProductForm.project_id); 0595 formElement.find("#modal-changlog").attr('data-product-id', ProductForm.project_id); 0596 } 0597 getPploadFiles(); 0598 return true; 0599 } 0600 return false; 0601 } 0602 return formElement.valid(); 0603 }, 0604 0605 onFinished: function (event, currentIndex) { 0606 //logo OR preview pic mandatory! 0607 var logoSrc = $('#product-picture-preview').attr('src'); 0608 var gallery = $('.product-gallery div:first-child'); 0609 var galleryPic = gallery.find('.image'); 0610 0611 if (!logoSrc && !galleryPic.attr('style')) { 0612 var msg = $('#preview_img_msg'); 0613 msg.text(''); 0614 msg.append('<label id="description-error" class="error" for="product-gallery">Please add a product logo or at least one product gallery picture!</label>'); 0615 0616 return false; 0617 } 0618 0619 if (currentIndex == 0) { 0620 if (ImagePreview.hasError) { 0621 return false; 0622 } 0623 if (ProductForm.mode == 'add' && (ProductForm.project_id == '' || ProductForm.project_id == undefined)) { 0624 var result = ProductForm.saveSection(formElement.find('.body:eq(' + currentIndex + ')').attr('id')); 0625 if (result == false) { 0626 validator.showErrors(ProductForm.errors); 0627 return result; 0628 } 0629 formElement.find("#modal-ppload").attr('data-product-id', ProductForm.project_id); 0630 formElement.find("#modal-changlog").attr('data-product-id', ProductForm.project_id); 0631 } 0632 } 0633 0634 0635 $('[name=project_id]').val(ProductForm.project_id); 0636 formElement.submit(); 0637 }, 0638 0639 onCanceled: function (event, currentIndex) { 0640 window.location.href = "/member/<?php echo $this->member->member_id; ?>/products/"; 0641 } 0642 0643 }); 0644 0645 0646 $('body').on("click", "#github_picker", function (event) { 0647 0648 html = '<form id="get-url-form">' + 0649 '<div class="form-group">' + 0650 '<input type="url" class="form-control" id="get-url" placeholder="Enter a URL where the files can be downloaded" required="required">' + 0651 '<span id="get-url-help" class="help-block small">e.g. https://github.com/mongodb/mongo/archive/r3.5.2.tar.gz</span></div>' + 0652 '<span id="get-url-error" class="help-block small"></span></div>' + 0653 '<button type="submit" class="btn btn-native btn-sm" id="get-url-submit">Submit</button>' + 0654 '</form>'; 0655 0656 var msgBox = $('#generic-dialog'); 0657 msgBox.modal('hide'); 0658 msgBox.find('.modal-header-text').empty().append('Enter a download URL:'); 0659 msgBox.find('.modal-body').empty().append(html); 0660 setTimeout(function () { 0661 msgBox.modal('show'); 0662 }, 900); 0663 0664 }); 0665 0666 $('body').on('submit', '#get-url-form', function(event) { 0667 if (! $('#get-url-form').validate()) { 0668 return true; 0669 } 0670 event.preventDefault(); 0671 $.ajax({ 0672 url: '/file/link/', 0673 type: 'post', 0674 data: { 0675 project_id: ProductForm.project_id, 0676 u: $('#get-url').val() 0677 }, 0678 success: function(returned_data) { 0679 if (!returned_data.file) { 0680 $('#get-url').addClass('hasError').focus(); 0681 $('#get-url-error').html('An Error occurred. Please check your URL or try again later.'); 0682 return; 0683 } 0684 data_file = returned_data.file; 0685 $modalPpload.attr('data-ppload-collection-id', data_file.collection_id); 0686 $('#get-url').val('').removeClass('hasError'); 0687 $('#get-url-error').html(''); 0688 $('#generic-dialog').modal('hide'); 0689 0690 getPploadFiles(null,null); 0691 0692 }, 0693 error: function() { 0694 $('#get-url').addClass('hasError').focus(); 0695 $('#get-url-error').html('An Error occurred. Please check your URL or try again later.'); 0696 } 0697 }); 0698 }); 0699 0700 $('body').on('change', '#get-url', function(event) { 0701 $('#get-url-error').empty(); 0702 }); 0703 0704 0705 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}} 0706 $('button[rel="tooltip"]').tooltip(); 0707 0708 var $modalPpload = $('#modal-ppload'); 0709 var $modalChanglog = $('#modal-changlog'); 0710 0711 var pploadApiUri = $modalPpload.attr('data-ppload-api-uri'); 0712 0713 var pploadUploads = { 0714 queue: {}, 0715 currentUploadId: null, 0716 uploading: null 0717 }; 0718 0719 function keysrt(key, asc) { 0720 if(asc) { 0721 return function(a,b){ 0722 if (a[key] > b[key]) return 1; 0723 if (a[key] < b[key]) return -1; 0724 return 0; 0725 } 0726 } else { 0727 return function(a,b){ 0728 if (a[key] < b[key]) return 1; 0729 if (a[key] > b[key]) return -1; 0730 return 0; 0731 } 0732 } 0733 } 0734 0735 function getUpdates(page) { 0736 0737 $modalChanglog.find('#update-list').html(''); 0738 var productId = <?= isset($this->project_id)?$this->project_id:0 ?>; 0739 $.ajax({ 0740 url: '<?=$helpProductUrl->buildProductUrl($this->project_id, 'getupdatesajax')?>', 0741 type: 'GET', 0742 data: { 0743 format: 'json', 0744 ignore_status_code: 1 0745 }, 0746 dataType: 'json', 0747 success: function (data, textStatus, jqXHR) { 0748 if (data.status != 'success') { 0749 return; 0750 } 0751 $.each(data.updates, function () { 0752 var id = ''; 0753 if (this.project_update_id) { 0754 id = this.project_update_id; 0755 } 0756 var title = ''; 0757 if (this.title) { 0758 title = this.title; 0759 } 0760 var text = ''; 0761 if (this.text) { 0762 text = this.text; 0763 } 0764 var date = ''; 0765 if (this.created_at) { 0766 date = this.created_at; 0767 } 0768 0769 Changelog.setLogMsg(id, this.raw_title, this.raw_text); 0770 0771 var divEl = $('<div />'); 0772 divEl.attr('data-update-id', id); 0773 divEl.append( 0774 '<a name="anker_'+id+'"></a>' 0775 + '<h4>'+title+'</h4>' 0776 + '<div class="small light lightgrey product-update-date">'+date+ '</div>' 0777 + text + '<br/><br/>' 0778 ); 0779 0780 var btnEdit = $('<button type="submit" class="btn btn-native btn-sm" style="line-height: 10px;margin: 5px;">Edit</button>'); 0781 btnEdit.attr('data-change-update-btn',id); 0782 btnEdit.attr('data-change-title',title); 0783 btnEdit.attr('data-change-text',text); 0784 0785 0786 var btnDelete = $('<button type="submit" class="btn btn-native btn-sm" style="line-height: 10px;margin: 5px;">Delete</button>'); 0787 btnDelete.attr('data-delete-update-btn',id); 0788 0789 divEl.append(btnEdit); 0790 divEl.append(btnDelete); 0791 divEl.append('<br/><br/><br/><br/>'); 0792 0793 // $modalPpload.find('#update-list').append(divEl); 0794 $modalChanglog.find('#update-list').append(divEl); 0795 }); 0796 }, 0797 error: function (jqXHR, textStatus, errorThrown) { 0798 return; 0799 } 0800 }); 0801 0802 } 0803 0804 function getPploadFiles(page) { 0805 if (!page) { 0806 page = 1; 0807 $modalPpload.find('table[data-ppload-files] tbody').empty(); 0808 } 0809 0810 var prodId = ProductForm.project_id; 0811 if(!prodId) { 0812 prodId = 0; 0813 } 0814 0815 var catId = $('#project_category_id').val(); 0816 0817 //Is this a Video? Then allow only Videos and srt 0818 /*for (var item in ProductForm.cat_id_path) { 0819 if(item == 586) { 0820 alert('Video'); 0821 } 0822 }*/ 0823 0824 //get cat-tag-groups 0825 var tagGroups = null; 0826 var tagGroupsCount = 0; 0827 $.ajax({ 0828 url: '/p/'+prodId+'/gettaggroupsforcatajax', 0829 type: 'GET', 0830 async: false, 0831 cache: false, 0832 timeout: 30000, 0833 data: {project_cat_id: catId}, 0834 dataType: 'json', 0835 success: function (data, textStatus, jqXHR) { 0836 if (data.status != 'success') { 0837 $modalPpload.find('table[data-ppload-files] thead').html(''); 0838 0839 tagGroups = data.tag_groups; 0840 tagGroupsCount = data.ResultSize; 0841 0842 var tableHeader = ''; 0843 tableHeader += '<tr>'; 0844 tableHeader += ' <th><?= $this->translate('Filename') ?></th>'; 0845 tableHeader += ' <th><?= $this->translate('MD5SUM') ?></th>'; 0846 tableHeader += ' <th><?= $this->translate('Version') ?></th>'; 0847 tableHeader += ' <th><?= $this->translate('Description') ?></th>'; 0848 0849 if(tagGroupsCount>0) { 0850 $.each(tagGroups, function() { 0851 tableHeader += '<th>'+this.group_display_name+'</th>'; 0852 }); 0853 } else { 0854 tableHeader += '<th></th>'; 0855 } 0856 0857 tableHeader += ' <th><?= $this->translate('Date added') ?></th>'; 0858 tableHeader += ' <th style="text-align: right"><?= $this->translate('Filesize') ?></th>'; 0859 tableHeader += ' <th style="text-align: right"><?= $this->translate('# DLs') ?></th>'; 0860 tableHeader += ' <th></th>'; 0861 tableHeader += '</tr>'; 0862 $modalPpload.find('table[data-ppload-files] thead').append(tableHeader); 0863 0864 0865 return; 0866 } 0867 }, 0868 error: function (jqXHR, textStatus, errorThrown) { 0869 return; 0870 } 0871 }); 0872 0873 var collectionId = $modalPpload.attr('data-ppload-collection-id'); 0874 0875 if(!collectionId) { 0876 return; 0877 } else { 0878 $.ajax({ 0879 //url: pploadApiUri + 'files/index', 0880 url: '/p/'+prodId+'/getfilesajax', 0881 type: 'GET', 0882 data: { 0883 collection_id: collectionId, 0884 perpage: 1000, 0885 page: page, 0886 format: 'json', 0887 ignore_status_code: 0, 0888 status: 'active' 0889 }, 0890 dataType: 'json', 0891 success: function (data, textStatus, jqXHR) { 0892 if (data.status != 'success') { 0893 return; 0894 } 0895 var updatePploadFileBtn = '<a href="#" class="btn btn-native btn-xs btn-file-dropzone" data-updatepploadfile-btn="">Update</a>'; 0896 var updatePploadFileBtnPerFile = ''; 0897 var deletePploadFileBtn = '<a href="#" class="btn btn-native btn-xs btn-file-dropzone" data-deletepploadfile-btn=""><span class="glyphicon glyphicon-trash"></span></a>'; 0898 var deletePploadFileBtnPerFile = ''; 0899 0900 var myArray = $.map(data.files, function(entry) { 0901 return entry; 0902 }); 0903 myArray.sort(keysrt('created_timestamp'), false); 0904 0905 var fileTagsArray = null; 0906 var fileTagsArraySize = 0; 0907 $.each(myArray, function () { 0908 0909 0910 0911 if(null != tagGroups && tagGroupsCount > 0) { 0912 //get cat-tag-groups 0913 $.ajax({ 0914 url: '/p/'+prodId+'/gettaggroupsforcatajax', 0915 type: 'GET', 0916 async: false, 0917 cache: false, 0918 timeout: 30000, 0919 data: {project_cat_id: catId, file_id: this.id, test: false}, 0920 dataType: 'json', 0921 success: function (data, textStatus, jqXHR) { 0922 if (data.status != 'success') { 0923 tagGroups = data.tag_groups; 0924 return; 0925 } 0926 }, 0927 error: function (jqXHR, textStatus, errorThrown) { 0928 return; 0929 } 0930 }); 0931 } else { 0932 //get cat-tag-groups 0933 $.ajax({ 0934 url: '/p/'+prodId+'/getfiletagsajax', 0935 type: 'GET', 0936 async: false, 0937 cache: false, 0938 timeout: 30000, 0939 data: {file_id: this.id}, 0940 dataType: 'json', 0941 success: function (data, textStatus, jqXHR) { 0942 if (data.status != 'success') { 0943 fileTagsArray = data.file_tags; 0944 fileTagsArraySize = data.ResultSize; 0945 return; 0946 } 0947 }, 0948 error: function (jqXHR, textStatus, errorThrown) { 0949 return; 0950 } 0951 }); 0952 } 0953 0954 var fileDescription = ''; 0955 if (this.description) { 0956 fileDescription = this.description; 0957 fileDescription = fileDescription.replace(/<\/?[^>]+(>|$)/g, ""); 0958 } 0959 0960 var inputFileDescription = '<input data-ppload-file-description="" class="form-control input-sm"' 0961 + ' type="text" maxlength="140" placeholder="File description"' 0962 + ' value="' + fileDescription + '">'; 0963 if(this.active == '0') { 0964 inputFileDescription = '<input disabled="disabled" data-ppload-file-description="" class="form-control input-sm"' 0965 + ' type="text" maxlength="140" placeholder="File description"' 0966 + ' value="' + fileDescription + '">'; 0967 } 0968 0969 var versionText; 0970 if(this.version==null) {versionText = '';} else{versionText = this.version;} 0971 versionText = versionText.replace(/<\/?[^>]+(>|$)/g, ""); 0972 0973 var version = '<input data-ppload-file-version="" class="form-control input-sm"' 0974 + ' type="text" maxlength="140" placeholder="File version"' 0975 + ' value="' + versionText + '">'; 0976 if(this.active == '0') { 0977 version = '<input disabled="disabled" data-ppload-file-version="" class="form-control input-sm"' 0978 + ' type="text" maxlength="140" placeholder="File version"' 0979 + ' value="' + versionText + '">'; 0980 } 0981 0982 var fileCategory = ''; 0983 if (this.category) { 0984 fileCategory = this.category; 0985 } 0986 var link = ''; 0987 var fileTags = ''; 0988 var osId = null; 0989 0990 //downloadlink is now: domain/api/files/download/id/ID/s/TOKEN/t/TIMESTAMP/u/USERID/FILE_NAME 0991 var downloadUrl = "https://<?= $_SERVER["SERVER_NAME"]?>/p/<?= $this->project_id ?>/startdownload?file_id=" + this.id + "&file_name=" + this.name + "&file_type=" + this.type + "&file_size=" + this.size; 0992 0993 var downloadLinkFilename = link ? this.name + ' (External Link)' : this.name; 0994 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="<?= $this->project_id ?>" data-link_type="download">' + downloadLinkFilename + '</a>'; 0995 0996 if(this.active == '1') { 0997 updatePploadFileBtnPerFile = updatePploadFileBtn; 0998 deletePploadFileBtnPerFile = deletePploadFileBtn; 0999 } else { 1000 updatePploadFileBtnPerFile = ''; 1001 deletePploadFileBtnPerFile = ''; 1002 } 1003 1004 //var numDownloads = this.downloaded_count; 1005 //numDownloads = numDownloads || 0; 1006 1007 //var numDownloads = this.downloaded_count_live || 0; 1008 var numDownloads = this.downloaded_count_uk || 0; 1009 1010 1011 tableString = ''; 1012 tableString += '<tr data-ppload-file-id="' + this.id + '" data-ppload-file-category="' + fileCategory + '" data-ppload-file-tags="' + fileTags + '">'; 1013 tableString += '<td>' + downloadLink + '</td>'; 1014 if(this.md5sum != 'NULL' && this.md5sum != 'null' && this.md5sum != null) { 1015 tableString += '<td>' + this.md5sum + '</td>'; 1016 } else { 1017 tableString += '<td></td>'; 1018 } 1019 tableString += '<td>' + version + '</td>'; 1020 tableString += '<td>' + inputFileDescription + '</td>'; 1021 1022 var fileId = this.id; 1023 1024 if(tagGroupsCount>0) { 1025 1026 $.each(tagGroups, function() { 1027 tableString += '<td>'; 1028 //Tag-Group Multiselect? 1029 if(this.is_multi_select == 1) { 1030 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;">'; 1031 } else { 1032 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;">'; 1033 tableString +='<option value=""></option>'; 1034 } 1035 //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;">'; 1036 //tableString += '<option value=\"\"></option>'; 1037 1038 for(key in this.tag_list) { 1039 tableString += '<option value=\"'+key+'\"'; 1040 if(null != this.selected_tags) { 1041 $.each(this.selected_tags, function() { 1042 if(key == this.tag_id) { 1043 tableString += ' selected="selected"'; 1044 } 1045 }) 1046 } 1047 1048 tableString += '>' + this.tag_list[key] + '</option>'; 1049 } 1050 1051 tableString += '</select>'; 1052 tableString += '</td>'; 1053 }); 1054 1055 } else { 1056 1057 if(fileTagsArraySize>0) { 1058 tableString += '<td>'; 1059 1060 tableString += '<span class="select2 select2-container select2-container--default select2-container--below select2-container--focus" dir="ltr" style="width: auto;">'; 1061 tableString += ' <span class="selection">'; 1062 tableString += ' <span class="select2-selection select2-selection--multiple" aria-expanded="false" tabindex="-1">'; 1063 tableString += ' <ul class="select2-selection__rendered">'; 1064 1065 $.each(fileTagsArray, function() { 1066 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+'">'; 1067 tableString += ' <span class="select2-selection__choice__remove" data-file-id="'+fileId+'" data-file-tag-id="'+this.tag_id+'" role="presentation">×</span>'+this.name+'</li>'; 1068 }); 1069 tableString += ' </ul>'; 1070 tableString += ' </span>'; 1071 tableString += ' </span>'; 1072 tableString += '</span>'; 1073 1074 tableString += '</td>'; 1075 } else { 1076 tableString += '<td></td>'; 1077 } 1078 } 1079 1080 tableString += '<td>' + this.created_timestamp + '</td>'; 1081 tableString += '<td style="text-align: right">' + humanFileSize(this.size) + '</td>'; 1082 tableString +='<td style="text-align: right">' + numDownloads + '</td>'; 1083 tableString += '<td>' + updatePploadFileBtnPerFile + '</td>'; 1084 tableString += '<td>' + deletePploadFileBtnPerFile + '</td>'; 1085 tableString += '</tr>'; 1086 $modalPpload.find('table[data-ppload-files] tbody').append(tableString); 1087 1088 $('.multi').multiselect({ 1089 includeSelectAllOption: true, 1090 buttonClass: 'btn btn-native btn-xs' 1091 }); 1092 1093 if ((typeof link != 'undefined') && (link != "")) { 1094 //$("#data-link" + this.id).attr('href', decodeURIComponent(link)); 1095 $("#data-link" + this.id).attr('target','_blank'); 1096 $("#data-link" + this.id).html($("#data-link" + this.id).html() + " (External Link)"); 1097 } 1098 }); 1099 1100 $modalPpload.find('p[data-file-upload-msg]').show(); 1101 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 1102 $modalPpload.find('#github_picker').attr('disabled', 'disabled'); 1103 1104 if ($modalPpload.find('input[data-accept-checkbox]').is(':checked')) { 1105 $modalPpload.find('button[data-addpploadfile-btn]').removeAttr('disabled'); 1106 $modalPpload.find('#github_picker').removeAttr('disabled'); 1107 } else { 1108 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 1109 $modalPpload.find('#github_picker').attr('disabled', 'disabled'); 1110 } 1111 /*if (data.pagination !== 'undefined' && data.pagination.next) { 1112 getPploadFiles(data.pagination.next); 1113 }*/ 1114 }, 1115 error: function (jqXHR, textStatus, errorThrown) { 1116 return; 1117 } 1118 }); 1119 } 1120 } 1121 1122 function addFileToPploadUploadQueue(fileId, fileUpload) { 1123 var uploadId = 'file-upload-' + Math.floor(Math.random() * 1000) + '-' + new Date().getTime(); 1124 pploadUploads.queue[uploadId] = { 1125 fileId: fileId, 1126 fileUpload: fileUpload 1127 }; 1128 1129 $modalPpload.find('table[data-file-upload] tbody').append( 1130 '<tr data-file-upload-id="' + uploadId + '">' 1131 + '<td>' + fileUpload.name + ' (' + humanFileSize(fileUpload.size) + ')</td>' 1132 + '<td>' 1133 + '<progress max="100" value="0" data-file-upload-progress=""></progress>' 1134 + '<br>' 1135 + '<span' 1136 + ' data-file-upload-progress=""' 1137 + ' data-file-upload-loaded="0"' 1138 + ' data-file-upload-time="0"></span>' 1139 + '</td>' 1140 + '<td><a href="#" data-file-upload-cancel-btn="">×</a></td>' 1141 + '</tr>' 1142 ); 1143 } 1144 1145 function startUploadPploadFiles() { 1146 if ($.isEmptyObject(pploadUploads.queue) || pploadUploads.uploading) { 1147 return; 1148 } 1149 1150 //var productId = $modalPpload.attr('data-product-id'); 1151 var uploadId = null; 1152 var formData = new FormData(); 1153 $.each(pploadUploads.queue, function (key, value) { 1154 uploadId = key; 1155 if (value.fileId) { 1156 formData.append('file_id', value.fileId); 1157 } 1158 formData.append('file_upload', value.fileUpload); 1159 return false; 1160 }); 1161 var $uploadContainer = $modalPpload.find('tr[data-file-upload-id="' + uploadId + '"]'); 1162 var $uploadProgressBar = $uploadContainer.find('progress[data-file-upload-progress]'); 1163 var $uploadProgress = $uploadContainer.find('span[data-file-upload-progress]'); 1164 $uploadProgress.attr('data-file-upload-time', new Date().getTime()); 1165 1166 $modalPpload.find('button[data-file-upload-cancel-btn]').removeAttr('disabled'); 1167 1168 pploadUploads.currentUploadId = uploadId; 1169 1170 var url = ''; 1171 if (formData.has('file_id')) { 1172 url = ($modalPpload.attr('data-updatepploadfile-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1173 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1174 url = ($modalPpload.attr('data-updatepploadfile-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1175 } 1176 } else { 1177 url = ($modalPpload.attr('data-addpploadfile-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1178 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1179 url = ($modalPpload.attr('data-addpploadfile-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1180 } 1181 } 1182 1183 pploadUploads.uploading = $.ajax({ 1184 xhr: function () { 1185 var xhr = $.ajaxSettings.xhr(); 1186 if (xhr.upload) { 1187 xhr.upload.addEventListener('progress', function (event) { 1188 var progress = parseInt(event.loaded / event.total * 10000) / 100; 1189 var previousLoaded = parseInt($uploadProgress.attr('data-file-upload-loaded')); 1190 var previousTime = parseInt($uploadProgress.attr('data-file-upload-time')); 1191 var currentTime = new Date().getTime(); 1192 var rate = '--'; 1193 if (previousTime < currentTime) { 1194 $uploadProgress.attr('data-file-upload-loaded', event.loaded); 1195 $uploadProgress.attr('data-file-upload-time', currentTime); 1196 rate = humanFileSize(Math.floor((event.loaded - previousLoaded) / (currentTime - previousTime) * 1000)); 1197 } 1198 $uploadProgressBar.attr('value', progress); 1199 $uploadProgress.html(progress + '% | ' + rate + '/s'); 1200 }, false); 1201 } 1202 xhr.addEventListener('abort', function (event) { 1203 if (pploadUploads.queue[uploadId].fileId) { 1204 $modalPpload.find('tr[data-ppload-file-id="' + pploadUploads.queue[uploadId].fileId + '"]').show(); 1205 } 1206 delete pploadUploads.queue[uploadId]; 1207 pploadUploads.currentUploadId = null; 1208 pploadUploads.uploading = null; 1209 $uploadContainer.remove(); 1210 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 1211 startUploadPploadFiles(); 1212 }, false); 1213 return xhr; 1214 }, 1215 url: url, 1216 type: 'POST', 1217 data: formData, 1218 dataType: 'json', 1219 contentType: false, 1220 processData: false, 1221 success: function (data, textStatus, jqXHR) { 1222 if (data.status != 'ok') { 1223 return; 1224 } 1225 1226 if (pploadUploads.queue[uploadId].fileId) { 1227 $modalPpload.find('tr[data-ppload-file-id="' + pploadUploads.queue[uploadId].fileId + '"]').remove(); 1228 } 1229 delete pploadUploads.queue[uploadId]; 1230 pploadUploads.currentUploadId = null; 1231 pploadUploads.uploading = null; 1232 $uploadContainer.remove(); 1233 $('a[href="#modal-ppload"][data-product-id="' + $modalPpload.attr('data-product-id') + '"]') 1234 .attr('data-ppload-collection-id', data.file.collection_id); 1235 $modalPpload.attr('data-ppload-collection-id', data.file.collection_id); 1236 1237 var versionText; 1238 if(data.file.version==null) {versionText = '';} else{versionText = data.file.version;} 1239 versionText = versionText.replace(/<\/?[^>]+(>|$)/g, ""); 1240 1241 var version = '<input data-ppload-file-version="" class="form-control input-sm"' 1242 + ' type="text" maxlength="140" placeholder="File version"' 1243 + ' value="' + versionText + '">'; 1244 1245 var fileDescription = ''; 1246 if (data.file.description) { 1247 fileDescription = data.file.description; 1248 } 1249 var fileCategory = ''; 1250 if (data.file.category) { 1251 fileCategory = data.file.category; 1252 } 1253 var fileTags = ''; 1254 if (data.file.tags) { 1255 fileTags = data.file.tags; 1256 } 1257 1258 var tableString = ''; 1259 tableString += '<tr data-ppload-file-id="' + data.file.id + '" data-ppload-file-category="' + fileCategory + '" data-ppload-file-tags="' + fileTags + '">'; 1260 tableString += '<td><a href="' + pploadApiUri + 'files/download/'; 1261 tableString += 'id/' + data.file.id + '/' + data.file.name + '">' + data.file.name + '</a></td>'; 1262 if(data.file.md5sum != 'NULL' && data.file.md5sum != 'null' && data.file.md5sum != null) { 1263 tableString += '<td>' + data.file.md5sum + '</td>'; 1264 } else { 1265 tableString += '<td></td>'; 1266 } 1267 tableString += '<td>' + version + '</td>'; 1268 tableString += '<td><input data-ppload-file-description="" class="form-control input-sm"'; 1269 tableString += ' type="text" maxlength="140" placeholder="File description"'; 1270 tableString += ' value="' + fileDescription + '"></td>'; 1271 1272 var fileId = data.file.id; 1273 1274 1275 //get cat-tag-groups 1276 var tagGroups = null; 1277 var tagGroupsCount = 0; 1278 var catId = $('#project_category_id').val(); 1279 1280 $.ajax({ 1281 url: '/p/'+ProductForm.project_id+'/gettaggroupsforcatajax', 1282 type: 'GET', 1283 async: false, 1284 cache: false, 1285 timeout: 30000, 1286 data: {project_cat_id: catId}, 1287 dataType: 'json', 1288 success: function (data, textStatus, jqXHR) { 1289 tagGroups = data.tag_groups; 1290 tagGroupsCount = data.ResultSize; 1291 }, 1292 error: function (jqXHR, textStatus, errorThrown) { 1293 return; 1294 } 1295 }); 1296 1297 1298 1299 if(tagGroupsCount>0) { 1300 $.each(tagGroups, function() { 1301 tableString += '<td>'; 1302 1303 1304 //Tag-Group Multiselect? 1305 if(this.is_multi_select == 1) { 1306 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;">'; 1307 } else { 1308 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;">'; 1309 tableString +='<option value=""></option>'; 1310 } 1311 1312 //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;">'; 1313 //tableString += '<option value=\"\"></option>'; 1314 1315 for(key in this.tag_list) { 1316 tableString += '<option value=\"'+key+'\"'; 1317 if(null != this.selected_tags) { 1318 $.each(this.selected_tags, function() { 1319 if(key == this.tag_id) { 1320 tableString += ' selected="selected"'; 1321 } 1322 }) 1323 } 1324 1325 tableString += '>' + this.tag_list[key] + '</option>'; 1326 } 1327 1328 tableString += '</select>'; 1329 tableString += '</td>'; 1330 }); 1331 } else { 1332 tableString += '<td></td>'; 1333 } 1334 1335 tableString += '<td>' + data.file.created_timestamp + '</td>'; 1336 tableString += '<td style="text-align: right">' + humanFileSize(data.file.size) + '</td>'; 1337 tableString +='<td style="text-align: right">0</td>'; 1338 tableString += '<td><a href="#" class="btn btn-native btn-xs btn-file-dropzone" data-updatepploadfile-btn="">Update</a></td>'; 1339 tableString += '<td><a href="#" class="btn btn-native btn-xs btn-file-dropzone" data-deletepploadfile-btn=""><span class="glyphicon glyphicon-trash"></span></a></td>'; 1340 tableString += '</tr>'; 1341 $modalPpload.find('table[data-ppload-files] tbody').append(tableString); 1342 1343 $('.multi').multiselect({ 1344 includeSelectAllOption: true, 1345 buttonClass: 'btn btn-native btn-xs' 1346 }); 1347 1348 //UserTags.activateSelect(fileId, ''); 1349 1350 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 1351 startUploadPploadFiles(); 1352 }, 1353 error: function (jqXHR, textStatus, errorThrown) { 1354 alert("Error: " + textStatus + ", " + errorThrown); 1355 return; 1356 } 1357 }); 1358 } 1359 1360 function updatePploadFile(fileId, fileDescription, fileCategory, fileTags) { 1361 var url = ($modalPpload.attr('data-updatepploadfile-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1362 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1363 url = ($modalPpload.attr('data-updatepploadfile-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1364 } 1365 fileDescription = fileDescription.replace(/<\/?[^>]+(>|$)/g, ""); 1366 1367 1368 $.ajax({ 1369 url: url, 1370 type: 'POST', 1371 data: { 1372 file_id: fileId, 1373 file_description: fileDescription, 1374 file_category: fileCategory 1375 }, 1376 dataType: 'json', 1377 success: function (data, textStatus, jqXHR) { 1378 if (data.status != 'ok') { 1379 return; 1380 } 1381 1382 }, 1383 error: function (jqXHR, textStatus, errorThrown) { 1384 alert("Error: " + textStatus + ", " + errorThrown); 1385 return; 1386 } 1387 }); 1388 } 1389 1390 function updateFileTag(fileId, tagId, tagGroupId) { 1391 var url = ($modalPpload.attr('data-updatefiletag-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1392 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1393 url = ($modalPpload.attr('data-updatefiletag-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1394 } 1395 1396 $.ajax({ 1397 url: url, 1398 type: 'POST', 1399 data: { 1400 file_id: fileId, 1401 tag_id: tagId, 1402 tag_group_id: tagGroupId 1403 }, 1404 dataType: 'json', 1405 success: function (data, textStatus, jqXHR) { 1406 if (data.status != 'ok') { 1407 return; 1408 } 1409 1410 }, 1411 error: function (jqXHR, textStatus, errorThrown) { 1412 alert("Error: " + textStatus + ", " + errorThrown); 1413 return; 1414 } 1415 }); 1416 } 1417 1418 function deleteFileTag(fileId, tagId) { 1419 var url = ($modalPpload.attr('data-deletefiletag-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1420 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1421 url = ($modalPpload.attr('data-deletefiletag-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1422 } 1423 1424 $.ajax({ 1425 url: url, 1426 type: 'POST', 1427 data: { 1428 file_id: fileId, 1429 tag_id: tagId 1430 }, 1431 dataType: 'json', 1432 success: function (data, textStatus, jqXHR) { 1433 if (data.status == 'ok') { 1434 $('#file-tag-'+fileId+'-'+tagId).remove(); 1435 return true; 1436 } 1437 1438 }, 1439 error: function (jqXHR, textStatus, errorThrown) { 1440 alert("Error: " + textStatus + ", " + errorThrown); 1441 return false; 1442 } 1443 }); 1444 1445 } 1446 1447 function updatePploadFileVersion(fileId, version) { 1448 var url = ($modalPpload.attr('data-updatepploadfile-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1449 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1450 url = ($modalPpload.attr('data-updatepploadfile-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1451 } 1452 version = version.replace(/<\/?[^>]+(>|$)/g, ""); 1453 1454 $.ajax({ 1455 url: url, 1456 type: 'POST', 1457 data: { 1458 file_id: fileId, 1459 file_version: version 1460 }, 1461 dataType: 'json', 1462 success: function (data, textStatus, jqXHR) { 1463 if (data.status != 'ok') { 1464 return; 1465 } 1466 1467 }, 1468 error: function (jqXHR, textStatus, errorThrown) { 1469 alert("Error: " + textStatus + ", " + errorThrown); 1470 return; 1471 } 1472 }); 1473 } 1474 1475 function updatePploadFileTags(fileId, fileTags) { 1476 var url = ($modalPpload.attr('data-updatepploadfile-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1477 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1478 url = ($modalPpload.attr('data-updatepploadfile-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1479 } 1480 1481 $.ajax({ 1482 url: url, 1483 type: 'POST', 1484 data: { 1485 file_id: fileId, 1486 file_tags: fileTags 1487 }, 1488 dataType: 'json', 1489 success: function (data, textStatus, jqXHR) { 1490 if (data.status != 'ok') { 1491 return; 1492 } 1493 1494 }, 1495 error: function (jqXHR, textStatus, errorThrown) { 1496 alert("Error: " + textStatus + ", " + errorThrown); 1497 return; 1498 } 1499 }); 1500 } 1501 1502 function deletePploadFile(fileId) { 1503 var url = ($modalPpload.attr('data-deletepploadfile-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1504 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1505 url = ($modalPpload.attr('data-deletepploadfile-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1506 } 1507 1508 $.ajax({ 1509 url: url, 1510 type: 'POST', 1511 data: {file_id: fileId}, 1512 dataType: 'json', 1513 success: function (data, textStatus, jqXHR) { 1514 if (data.status != 'ok') { 1515 alert("Error: " + data.error_text); 1516 return; 1517 } 1518 $modalPpload.find('table[data-ppload-files] tbody').html(''); 1519 $modalPpload.find('table[data-file-upload] tbody').html(''); 1520 getPploadFiles(); 1521 /** 1522 $modalPpload.find('tr[data-ppload-file-id="' + fileId + '"]').remove(); 1523 if ($modalPpload.find('tr[data-ppload-file-id]').size() === 0) { 1524 $modalPpload.find('table[data-ppload-files] tbody').html(''); 1525 $modalPpload.find('table[data-file-upload] tbody').html(''); 1526 $modalPpload.find('p[data-file-upload-msg]').show(); 1527 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 1528 1529 if ($modalPpload.find('input[data-accept-checkbox]').is('checked')) { 1530 $modalPpload.find('button[data-addpploadfile-btn]').removeAttr('disabled'); 1531 } else { 1532 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 1533 } 1534 }**/ 1535 }, 1536 error: function (jqXHR, textStatus, errorThrown) { 1537 alert("Error: " + textStatus + ", " + errorThrown); 1538 return; 1539 } 1540 }); 1541 } 1542 1543 function deletePploadFiles() { 1544 var url = ($modalPpload.attr('data-deletepploadfiles-uri')).replace(/@@project_id@@/i, ProductForm.project_id); 1545 if (typeof ProductForm.project_id == 'undefined' || ProductForm.project_id == '' || ProductForm.project_id == '0') { 1546 url = ($modalPpload.attr('data-deletepploadfiles-uri')).replace(/@@project_id@@/i, <?= (isset($this->project_id))?$this->project_id:0 ?>); 1547 } 1548 $.ajax({ 1549 url: url, 1550 type: 'POST', 1551 data: {}, 1552 dataType: 'json', 1553 success: function (data, textStatus, jqXHR) { 1554 if (data.status != 'ok') { 1555 return; 1556 } 1557 $modalPpload.find('table[data-ppload-files] tbody').html(''); 1558 $modalPpload.find('table[data-file-upload] tbody').html(''); 1559 $modalPpload.find('p[data-file-upload-msg]').show(); 1560 1561 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 1562 1563 $modalPpload.find('input[data-accept-checkbox]').removeAttr('disabled'); 1564 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 1565 $modalPpload.find('#github_picker').attr('disabled', 'disabled'); 1566 }, 1567 error: function (jqXHR, textStatus, errorThrown) { 1568 alert("Error: " + textStatus + ", " + errorThrown); 1569 return; 1570 } 1571 }); 1572 } 1573 1574 function humanFileSize(bytes) { 1575 var size = ''; 1576 size = (bytes / 1048576).toFixed(2) + ' MB'; 1577 /* 1578 if (bytes >= 1073741824) { 1579 size = (bytes / 1073741824).toFixed(2) + 'GB'; 1580 } 1581 else if (bytes >= 1048576) { 1582 size = (bytes / 1048576).toFixed(2) + 'MB'; 1583 } 1584 else if (bytes >= 1024) { 1585 size = (bytes / 1024).toFixed(2) + 'KB'; 1586 } 1587 else { 1588 size = bytes + 'bytes'; 1589 }*/ 1590 return size; 1591 } 1592 1593 $modalPpload.attr('data-ppload-collection-id', $(this).attr('data-ppload-collection-id')); 1594 $modalPpload.attr('data-product-id', $(this).attr('data-product-id')); 1595 $modalPpload.attr('data-addpploadfile-uri', $(this).attr('data-addpploadfile-uri')); 1596 $modalPpload.attr('data-updatepploadfile-uri', $(this).attr('data-updatepploadfile-uri')); 1597 $modalPpload.attr('data-deletepploadfile-uri', $(this).attr('data-deletepploadfile-uri')); 1598 $modalPpload.find('div[data-file-upload]').css({ 1599 'min-height': '250px', 1600 'border-width': '5px', 1601 'border-style': 'dashed', 1602 'border-color': '#cccccc', 1603 'overflow': 'inherit' 1604 }); 1605 $modalPpload.find('table[data-ppload-files] tbody').html(''); 1606 $modalPpload.find('table[data-file-upload] tbody').html(''); 1607 $modalPpload.find('p[data-file-upload-msg]').show(); 1608 1609 $modalPpload.find('input[data-accept-checkbox]').removeAttr('disabled'); 1610 1611 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 1612 $modalPpload.find('#github_picker').attr('disabled', 'disabled'); 1613 $modalPpload.find('button[data-file-upload-cancel-btn]').attr('disabled', 'disabled'); 1614 1615 //if ($modalPpload.attr('data-ppload-collection-id')) { 1616 // getPploadFiles(); 1617 //} 1618 1619 if(<?= (isset($this->project_id))?$this->project_id:0 ?> != 0) { 1620 getUpdates(); 1621 } 1622 1623 $modalPpload.on('dragover', 'div[data-file-upload]', function (event) { 1624 event.preventDefault(); 1625 }); 1626 1627 $modalPpload.on('dragenter', 'div[data-file-upload]', function (event) { 1628 event.preventDefault(); 1629 $(this).css('border-color', '#00ccff'); 1630 }); 1631 1632 $modalPpload.on('dragleave', 'div[data-file-upload]', function (event) { 1633 event.preventDefault(); 1634 $(this).css('border-color', '#cccccc'); 1635 }); 1636 1637 $modalPpload.on('drop', 'div[data-file-upload]', function (event) { 1638 event.preventDefault(); 1639 $.each(event.originalEvent.dataTransfer.files, function () { 1640 addFileToPploadUploadQueue(null, this); 1641 }); 1642 startUploadPploadFiles(); 1643 $(this).css('border-color', '#cccccc'); 1644 }); 1645 1646 $modalPpload.on('change', 'input[data-file-upload]', function (event) { 1647 $.each(this.files, function () { 1648 addFileToPploadUploadQueue(null, this); 1649 }); 1650 startUploadPploadFiles(); 1651 }); 1652 1653 $modalPpload.on('click', 'button[data-addpploadfile-btn]', function (event) { 1654 event.preventDefault(); 1655 $modalPpload.find('input[data-file-upload]').click(); 1656 }); 1657 1658 $modalPpload.on('change', 'input[data-file-upload-update]', function (event) { 1659 if ($(this).attr('data-ppload-file-id')) { 1660 var fileId = $(this).attr('data-ppload-file-id'); 1661 $modalPpload.find('tr[data-ppload-file-id="' + fileId + '"]').hide(); 1662 addFileToPploadUploadQueue(fileId, this.files[0]); 1663 startUploadPploadFiles(); 1664 } 1665 }); 1666 1667 $modalPpload.on('click', 'tr[data-ppload-file-id] a[data-updatepploadfile-btn]', function (event) { 1668 event.preventDefault(); 1669 var $inputForm = $modalPpload.find('input[data-file-upload-update]'); 1670 $inputForm.attr('data-ppload-file-id', $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id')); 1671 $inputForm.click(); 1672 }); 1673 1674 $modalPpload.on('click', 'input[data-accept-checkbox]', function (event) { 1675 if ($modalPpload.find('input[data-accept-checkbox]').is(':checked')) { 1676 $modalPpload.find('button[data-addpploadfile-btn]').removeAttr('disabled'); 1677 $modalPpload.find('#github_picker').removeAttr('disabled'); 1678 } else { 1679 $modalPpload.find('button[data-addpploadfile-btn]').attr('disabled', 'disabled'); 1680 $modalPpload.find('#github_picker').attr('disabled', 'disabled'); 1681 } 1682 }); 1683 1684 $modalPpload.on('click', 'tr[data-ppload-file-id] a[data-deletepploadfile-btn]', function (event) { 1685 event.preventDefault(); 1686 deletePploadFile($(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id')); 1687 }); 1688 1689 $modalPpload.on('click', 'button[data-file-upload-cancel-btn]', function (event) { 1690 event.preventDefault(); 1691 pploadUploads.uploading.abort(); 1692 pploadUploads.queue = {}; 1693 $modalPpload.find('table[data-file-upload] tbody').html(''); 1694 }); 1695 1696 $modalPpload.on('click', 'tr[data-file-upload-id] a[data-file-upload-cancel-btn]', function (event) { 1697 event.preventDefault(); 1698 var uploadId = $(this).closest('tr[data-file-upload-id]').attr('data-file-upload-id'); 1699 if (uploadId == pploadUploads.currentUploadId) { 1700 pploadUploads.uploading.abort(); 1701 } 1702 else { 1703 delete pploadUploads.queue[uploadId]; 1704 $modalPpload.find('tr[data-file-upload-id="' + uploadId + '"]').remove(); 1705 } 1706 }); 1707 1708 $modalPpload.on('change', 'input[data-ppload-file-description]', function (event) { 1709 event.preventDefault(); 1710 var fileId = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id'); 1711 var fileDescription = $(this).closest('input[data-ppload-file-description]').val(); 1712 var fileCategory = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-category'); 1713 var fileTags = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-tags'); 1714 1715 $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-tags', fileTags); 1716 updatePploadFile(fileId, fileDescription, fileCategory, fileTags); 1717 }); 1718 1719 $modalPpload.on('change', 'input[data-ppload-file-version]', function (event) { 1720 event.preventDefault(); 1721 var fileId = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id'); 1722 var fileVersion = $(this).closest('input[data-ppload-file-version]').val(); 1723 updatePploadFileVersion(fileId, fileVersion); 1724 }); 1725 1726 $modalChanglog.on('click', 'button[data-add-update-btn]', function (event) { 1727 var update_id = $modalChanglog.find('#update-id').val(); 1728 var title = $modalChanglog.find('#update-title').val(); 1729 var text = $modalChanglog.find('#update-text').val(); 1730 var productId = <?= isset($this->project_id)?$this->project_id:0 ?>; 1731 event.preventDefault(); 1732 1733 $.ajax({ 1734 url: '<?=$helpProductUrl->buildProductUrl($this->project_id, 'saveupdateajax')?>', 1735 type: 'POST', 1736 data: {title: title, text: text, update_id: update_id}, 1737 dataType: 'json', 1738 success: function (data, textStatus, jqXHR) { 1739 if (data.status != 'success') { 1740 return; 1741 } 1742 $modalChanglog.find('#update-title').val(''); 1743 $modalChanglog.find('#update-text').val(''); 1744 $modalChanglog.find('#update-id').val(''); 1745 getUpdates(); 1746 }, 1747 error: function (jqXHR, textStatus, errorThrown) { 1748 return; 1749 } 1750 }); 1751 1752 }); 1753 1754 $modalChanglog.on('click', 'button[data-delete-update-btn]', function (event) { 1755 var updateId = $(this).attr('data-delete-update-btn'); 1756 var productId = <?= isset($this->project_id)?$this->project_id:0 ?>; 1757 event.preventDefault(); 1758 1759 $.ajax({ 1760 url: '<?=$helpProductUrl->buildProductUrl($this->project_id, 'deleteupdateajax')?>', 1761 type: 'POST', 1762 data: {update_id: updateId}, 1763 dataType: 'json', 1764 success: function (data, textStatus, jqXHR) { 1765 if (data.status != 'success') { 1766 alert('Update could not be deleted!'); 1767 return; 1768 } 1769 getUpdates(); 1770 }, 1771 error: function (jqXHR, textStatus, errorThrown) { 1772 return; 1773 } 1774 }); 1775 1776 }); 1777 1778 $modalChanglog.on('click', 'button[data-change-update-btn]', function (event) { 1779 var updateId = $(this).attr('data-change-update-btn'); 1780 //var title = $(this).attr('data-change-title'); 1781 //var text = $(this).attr('data-change-text'); 1782 var changelog = Changelog.getLogMsg(updateId); 1783 var title = changelog.msg_title; 1784 var text = changelog.msg_text; 1785 1786 $modalChanglog.find('#update-title').val(title); 1787 $modalChanglog.find('#update-text').val(text); 1788 $modalChanglog.find('#update-id').val(updateId); 1789 1790 $modalChanglog.find('#update-title').focus(); 1791 1792 event.preventDefault(); 1793 }); 1794 1795 1796 /* 1797 $modalPpload.on('change', 'select.chosen', function (event) { 1798 event.preventDefault(); 1799 var fileId = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id'); 1800 var currentTags = $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags'); 1801 var chosenTags = $(this).val(); 1802 1803 var newTags = UserTags.removeOldTags(currentTags); 1804 newTags = UserTags.setNewTags(newTags, chosenTags); 1805 1806 updatePploadFileTags(fileId, newTags); 1807 $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags',newTags); 1808 });*/ 1809 1810 $modalPpload.on('change', 'select[data-tag-group]', function(event) { 1811 event.preventDefault(); 1812 var fileId = $(this).closest('tr[data-ppload-file-id]').attr('data-ppload-file-id'); 1813 var fileTags = $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags'); 1814 var tagId = $(this).val(); 1815 var tagGroupId = $(this).attr('data-tag-group-id'); 1816 var tagGroupName = $(this).attr('data-tag-group'); 1817 1818 var newFileTags = ''; 1819 if (fileTags) { 1820 1821 $.each(fileTags.split(','), function () { 1822 // skip old entries 1823 if ((this.length == 0) || (this.indexOf(tagGroupName+'id-') == 0) || (this.indexOf(tagGroupName+'id##') == 0)) { 1824 return true; 1825 } 1826 newFileTags += ',' + this; 1827 }); 1828 1829 } 1830 newFileTags += ','+tagGroupName+'id-'+tagId; 1831 //updatePploadFileTags(fileId, newFileTags); 1832 //$(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags',newFileTags); 1833 updateFileTag(fileId, tagId, tagGroupId); 1834 }); 1835 1836 $modalPpload.on('click', 'span[data-file-tag-id]', function (event) { 1837 event.preventDefault(); 1838 1839 $tagId = $(this).attr('data-file-tag-id'); 1840 $fileId = $(this).attr('data-file-id'); 1841 var fileTags = $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags'); 1842 1843 /* 1844 var newFileTags = ''; 1845 if (fileTags) { 1846 1847 $.each(fileTags.split(','), function () { 1848 // skip old entries 1849 if ((this.length == 0) || (this.indexOf(tagGroupName+'id-') == 0) || (this.indexOf(tagGroupName+'id##') == 0)) { 1850 return true; 1851 } 1852 newFileTags += ',' + this; 1853 }); 1854 1855 } 1856 newFileTags += ','+tagGroupName+'id-'+tagId; 1857 updatePploadFileTags(fileId, newFileTags); 1858 1859 $(this).closest('tr[data-ppload-file-tags]').attr('data-ppload-file-tags',newFileTags); 1860 1861 */ 1862 deleteFileTag($fileId, $tagId); 1863 }); 1864 1865 1866 $('.multi').multiselect({ 1867 includeSelectAllOption: true 1868 }); 1869 1870 1871 }); 1872 1873 1874 1875 var LogCollection=function() 1876 { 1877 this.changelogs = {}; 1878 1879 this.setLogMsg = 1880 function(id, title, msg) { 1881 this.changelogs[id] = {msg_title:title, msg_text:msg}; 1882 }; 1883 1884 this.getLogMsg = 1885 function(id) { 1886 return this.changelogs[id]; 1887 } 1888 }; 1889 1890 var Changelog = new LogCollection(); 1891 </script> 1892 <script> 1893 $.fn.sortSelect = function() { 1894 var op = this.children("option"); 1895 op.sort(function(a, b) { 1896 return a.text > b.text ? 1 : -1; 1897 }) 1898 return this.empty().append(op); 1899 } 1900 1901 $.fn.sort_select_box = function(){ 1902 var my_options = $("option", $(this)); 1903 my_options.sort(function(a,b) { 1904 if (a.text > b.text) return 1; 1905 else if (a.text < b.text) return -1; 1906 else return 0 1907 }); 1908 $(this).empty().append(my_options); 1909 } 1910 1911 function setSourceNeededForCategoryInfo(element_id, cat_id) { 1912 $('.cat_source_info').remove(); 1913 jQuery.ajax({ 1914 data: {'cat_id': cat_id}, 1915 url: '/productcategory/fetchsourceneeded/', 1916 type: 'get', 1917 success: function (results) { 1918 var isSourceRequired = results.source_required; 1919 1920 if(isSourceRequired == 1) { 1921 $('#wrapper_cat_id').append('<div class="cat_source_info" id="' + element_id + '_cat_source_info">*for this category a Source-Code Repository is needed for plings</div>'); 1922 } 1923 } 1924 }); 1925 } 1926 1927 1928 ProductForm = { 1929 1930 mode: "<?=$this->mode?>", 1931 project_id: <?php echo ($this->mode == 'edit') ? $this->project_id : '$(\'#project_id\').val()'?>, 1932 errors: "", 1933 cat_id_data: <?=json_encode($categories)?>, 1934 cat_id_data_fallback: <?=json_encode($categoriesFallback)?>, 1935 cat_id_path: <?=json_encode($categoryPath)?>, 1936 store_cat_ids: <?=json_encode($storeCatIds)?>, 1937 value_cat_id: <?=json_encode($valueCatId)?>, 1938 1939 setup: function () { 1940 //20190508 ronald: laut CT sollen wieder alle Kategorien angezigt werden, nicht mehr nur die Store-Kats 1941 //this.setupCategorySelect(this.cat_id_data); 1942 this.setupCategorySelect(this.cat_id_data_fallback); 1943 1944 this.setupCategoryAjax(); 1945 this.setGitlabProjectNameSelect(); 1946 }, 1947 1948 setupCategorySelect: function(catList) { 1949 var level = 0; 1950 var hasNoRoot = true; 1951 1952 for (var form_elem_name in catList) { 1953 var nextElementName = form_elem_name.substring(0, form_elem_name.length - 1) + (level + 1); 1954 var new_html_element = '<select name="' + form_elem_name + '" id="' + form_elem_name + '" class="required form-control product_select_cat" data-target="'+nextElementName+'" data-level="'+level+'">'; 1955 new_html_element += '<option value=""> </option>'; 1956 1957 hasNoRoot = true; 1958 1959 for (var form_select_option in catList[form_elem_name]) { 1960 var attr_selected = ''; 1961 1962 if (form_select_option == this.cat_id_path[level] || form_select_option == this.value_cat_id) { 1963 attr_selected = ' selected="selected"'; 1964 hasNoRoot = false; 1965 } 1966 new_html_element += '<option value="' + form_select_option + '" ' + attr_selected + '>' + catList[form_elem_name][form_select_option] + '</option>'; 1967 } 1968 1969 /** 1970 if(hasNoRoot == true && this.cat_id_path != '0') { 1971 var url = "<?= $helpBaseUrl->buildMainBaserUrl().'p/'. $this->project_id . '/edit' ?>"; 1972 //alert("Redir: "+url); 1973 document.location.href = url; 1974 }*/ 1975 if(hasNoRoot == true && this.cat_id_path != '0') { 1976 this.setupCategorySelect(this.cat_id_data_fallback); 1977 return; 1978 } 1979 1980 new_html_element += '</select>'; 1981 $('#wrapper_cat_id').append(new_html_element); 1982 this.sortOptionByValue(form_elem_name); 1983 1984 var size = <?=count($categories)?>; 1985 if((size-1) == level) { 1986 this.setSourceNeededForCategoryInfo(form_elem_name, this.cat_id_path[level]); 1987 } 1988 1989 level++; 1990 } 1991 }, 1992 1993 setSourceNeededForCategoryInfo: function(element_id, cat_id) { 1994 1995 jQuery.ajax({ 1996 data: {'cat_id': cat_id}, 1997 url: '/productcategory/fetchsourceneeded/', 1998 type: 'get', 1999 success: function (results) { 2000 var isSourceRequired = results.source_required; 2001 if(isSourceRequired == 1) { 2002 $('#wrapper_cat_id').append('<div class="cat_source_info" id="' + element_id + '_cat_source_info">*for this category a Source-Code Repository is needed for plings</div>'); 2003 } 2004 } 2005 }); 2006 }, 2007 2008 setGitlabProjectNameSelect: function() { 2009 //project name is required if the checkbox is checked 2010 $('body').on('change', '#is_gitlab_project', function () { 2011 if(this.checked) { 2012 $('#gitlab_project_id').attr('class','required form-control gitlab_project_id'); 2013 $('#gitlab_project_id').prop('disabled', false); 2014 $('#show_gitlab_project_issues').prop('disabled', false); 2015 $('#use_gitlab_project_readme').prop('disabled', false); 2016 } else { 2017 //$('#gitlab_project_id').disable(); 2018 $('#gitlab_project_id').val([]); 2019 $('#gitlab_project_id').removeClass('required'); 2020 $('#gitlab_project_id').prop('disabled', true); 2021 $('#show_gitlab_project_issues').prop('disabled', true); 2022 $('#use_gitlab_project_readme').prop('disabled', true); 2023 } 2024 }); 2025 }, 2026 2027 sortOptionByValue: function(element_id) { 2028 var my_options = $("#"+element_id + " option"); 2029 var selected = $("#"+element_id).val(); 2030 2031 my_options.sort(function(a,b) { 2032 if (a.text > b.text) return 1; 2033 else if (a.text < b.text) return -1; 2034 else return 0; 2035 }) 2036 $("#"+element_id).empty().append( my_options ); 2037 $("#"+element_id).val(selected); 2038 }, 2039 2040 2041 setupCategoryAjax: function () { 2042 $('body').on('change', 'div#wrapper_cat_id select.product_select_cat', function () { 2043 2044 var cat_id = $(this).val(); 2045 var name_old_elem = $(this).attr('name'); 2046 var name_new_elem = $(this).data('target'); 2047 var level_elem = $(this).data('level') + 1; 2048 var level_new_elem = level_elem + 1; 2049 var name_new_target = name_new_elem.substring(0,name_new_elem.length - 1) + level_new_elem; 2050 2051 if (!cat_id) { 2052 $('#wrapper_form_cat input:hidden:first').val($('#wrapper_cat_id').find("[data-level]:lt(" + (level_elem - 1) + ")").val()); 2053 $('#wrapper_cat_id').find("[data-level]:gt(" + (level_elem - 1) + ")").remove(); 2054 $('.cat_source_info').remove(); 2055 return; 2056 } 2057 $('#wrapper_form_cat input:hidden:first').val(cat_id); 2058 2059 jQuery.ajax({ 2060 data: {'cat_id': cat_id}, 2061 url: '/productcategory/fetchchildren/', 2062 type: 'post', 2063 success: function (results) { 2064 $('#wrapper_cat_id').find("[data-level]:gt(" + (level_elem - 1) + ")").remove(); 2065 $('#' + (level_elem - 1) + '_cat_source_info').remove(); 2066 $('.cat_source_info').remove(); 2067 if (!$.isEmptyObject(results)) { 2068 var new_html_element = '<select name="' + name_new_elem + '" id="' + name_new_elem + '" class="required form-control product_select_cat" data-target="'+name_new_target+'" data-level="'+level_elem+'">'; 2069 new_html_element += '<option value=""> </option>'; 2070 for (var i in results) { 2071 new_html_element += '<option value="' + results[i].project_category_id + '">' + results[i].title + '</option>'; 2072 } 2073 new_html_element += '</select>'; 2074 2075 $('#wrapper_cat_id').append(new_html_element); 2076 } else { 2077 var name_elem = name_old_elem; 2078 setSourceNeededForCategoryInfo(name_elem, cat_id); 2079 } 2080 } 2081 }); 2082 }); 2083 }, 2084 2085 saveSection: function (sectionId) { 2086 var pid = <?php echo ($this->mode == 'edit') ? $this->project_id : '$(\'#project_id\').val()'?>; 2087 if (pid != '') { 2088 return; 2089 } 2090 2091 var url = '/p/save/'; 2092 var data = $('#' + sectionId + ' :input').serialize(); 2093 var result = false; 2094 2095 jQuery.ajax({ 2096 data: data, 2097 url: url, 2098 type: 'post', 2099 async: false 2100 }).done(function (data, textStatus, jqXHR) { 2101 if (data.project_id == undefined) { 2102 ProductForm.project_id = ''; 2103 } else { 2104 ProductForm.project_id = data.project_id; 2105 } 2106 if (data.status == 'error') { 2107 ProductForm.errors = data.messages; 2108 result = false; 2109 } else { 2110 result = true; 2111 } 2112 2113 }).fail(function (jqXHR, textStatus, errorThrown) { 2114 2115 }).always(function (data, textStatus, errorThrown) { 2116 2117 }); 2118 2119 return result; 2120 }, 2121 2122 showErrors: function () { 2123 $.each(this.errors, function (index, value) { 2124 $('[name=' + index + ']').append('<label id="title-error" class="error" for="title">' + value + '</label>'); 2125 }); 2126 } 2127 2128 }; 2129 2130 var ProductGallery = (function () { 2131 var maxImageCount = 5; 2132 2133 return { 2134 2135 setup: function () { 2136 $('body').on({ 2137 mouseenter: function () { 2138 $(this).find('.icon-check').hide(); 2139 $(this).find('.icon-cross').show(); 2140 }, 2141 mouseleave: function () { 2142 $(this).find('.icon-check').show(); 2143 $(this).find('.icon-cross').hide(); 2144 } 2145 }, '.product-image'); 2146 2147 if ($('.product-image').length>= 6) { 2148 $('.upload-image-container').hide(); 2149 } 2150 2151 $('body').on('click', '.icon-cross', function () { 2152 $(this).closest('.product-image').remove(); 2153 ProductGallery.incImageCount(); 2154 }); 2155 }, 2156 2157 previewImage: function (input) { 2158 2159 if (!input.files.length) { 2160 return; 2161 } 2162 2163 maxImageCount--; 2164 2165 var reader = new FileReader(); 2166 var image = new Image(); 2167 var file = input.files[0]; 2168 2169 reader.readAsDataURL(file); 2170 reader.onload = function (_image) { 2171 2172 $('#gallery-error').parent().parent().find('.bg-danger').removeClass('bg-danger'); 2173 $('#gallery-error').remove(); 2174 2175 $('.product-image').last().append('<div class="absolute icon-check"></div>' + 2176 '<div class="absolute icon-cross"></div>' + 2177 '<div class="image" style="background-image: url(' + _image.target.result + ');"></div>' 2178 ); 2179 2180 $('.product-image').last().after('<div class="product-image relative">' + 2181 '<input type="file" name="upload_picture[]" class="gallery-picture" onchange="ProductGallery.previewImage(this);"></div>' 2182 ); 2183 2184 if ($('.product-image').length>= 6) { 2185 $('.upload-image-container').hide(); 2186 } 2187 /* 2188 if (maxImageCount <= 0) { 2189 $('.upload-image-container').hide(); 2190 } 2191 */ 2192 2193 image.src = _image.target.result; // url.createObjectURL(file); 2194 image.onload = function () { 2195 var w = this.width, 2196 h = this.height, 2197 t = file.type, // ext only: // file.type.split('/')[1], 2198 n = file.name, 2199 s = ~~(file.size / 5120)// +'KB'; 2200 if (s > 5120) { 2201 $('.product-image').last().prev() 2202 .find('div.icon-check') 2203 .after('<div class="image-error">File too large</div>') 2204 .removeClass('icon-check') 2205 .addClass('icon-report') 2206 ; 2207 $('.product-image').last().prev() 2208 .find('input.gallery-picture').remove() 2209 .append('<input type="file" name="upload_picture[]" class="gallery-picture" onchange="ProductGallery.previewImage(this);"></div>') 2210 ; 2211 } 2212 }; 2213 ; 2214 image.onerror = function () { 2215 $('.product-image').last().prev().find('div.image').append('Invalid file type: ' + file.type); 2216 }; 2217 } 2218 }, 2219 thumbClick: function (element) { 2220 var index = $(element).attr('data-index'); 2221 $('.thumb').removeClass('thumb-active'); 2222 $(element).parent().addClass('thumb-active'); 2223 $('#gallery-carousel').find('.active').removeClass('active'); 2224 $('#gallery-carousel').find('.item[data-index="' + index + '"]').addClass('active'); 2225 2226 }, 2227 gallerySlide: function () { 2228 var index = $('#gallery-carousel').find('.active').attr('data-index'); 2229 $('.thumb-active').removeClass('thumb-active'); 2230 $('.thumb a[data-index="' + index + '"]').parent().addClass('thumb-active'); 2231 }, 2232 incImageCount: function () { 2233 if (maxImageCount < 5) { 2234 maxImageCount = maxImageCount + 1; 2235 } 2236 $('.upload-image-container').show(); 2237 } 2238 2239 }; 2240 })(); 2241 2242 </script> 2243 <?php $this->inlineScript()->appendScript( 2244 ' $(document).ready(function(){ 2245 ImagePreview.setup(); 2246 ProductForm.setup(); 2247 ProductGallery.setup(); 2248 Opendownloadfile.setup(); 2249 }); 2250 ');