File indexing completed on 2025-06-29 05:19:54

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->os = Zend_Registry::get('application_os');
0024 $this->tab = 'addcollection';
0025 $helperImage = new Default_View_Helper_Image();
0026 $helpMemberUrl = new Default_View_Helper_BuildMemberUrl();
0027 $helpCollectionUrl = new Default_View_Helper_BuildCollectionUrl();
0028 $helpBaseUrl = new Default_View_Helper_BuildBaseUrl();
0029 
0030 $modelCategory = new Default_Model_DbTable_ProjectCategory();
0031 $valueCatId = $this->form->project_category_id->getValue();
0032 //$valueCatId = 55;
0033 $storeCatIds = Zend_Registry::isRegistered('store_category_list') ? Zend_Registry::get('store_category_list') : null;
0034 
0035 //$categories = $modelCategory->fetchCategoriesForForm($valueCatId);
0036 $categoryAncestors = $modelCategory->fetchAncestorsAsId($valueCatId);
0037 
0038 $categories = $modelCategory->fetchCategoriesForFormNew($valueCatId);
0039 //$categories2 = array();
0040 
0041 
0042 if (count($categoryAncestors) > 0) {
0043     $categoryPath = explode(',',$categoryAncestors['ancestors']);
0044 }
0045 $categoryPath[] = $valueCatId;
0046 
0047 
0048 $this->headLink()->appendStylesheet('//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css');
0049 $this->headLink()->appendStylesheet('/theme/flatui/css/chosen.css');
0050 
0051 $this->inlineScript()->appendFile('/theme/flatui/js/lib/chosen.jquery.min.js');
0052 $this->inlineScript()->appendScript('
0053     $(document).ready(function(){
0054         $("select.chosen").chosen({
0055         width: "100%",
0056         max_selected_options: "5",
0057         disable_search: "false",
0058         disable_search_threshold: "5"
0059         });
0060     });
0061 ');
0062 
0063 ?>
0064 
0065     <style>
0066 
0067         .wizard, .tabcontrol {
0068             overflow: visible;
0069         }
0070 
0071         .wizard > .content {
0072             overflow: visible;
0073         }
0074 
0075         .wizard > .content > .body {
0076             position: relative;
0077         }
0078 
0079         input[type=checkbox] {
0080             /*display: none;*/
0081         }
0082 
0083         div.datafiledroparea{
0084             /*overflow-x: scroll !important;
0085             overflow-y: scroll !important;*/
0086         }
0087 
0088         /*
0089         - Style each label that is directly after the input
0090         - position: relative; will ensure that any position: absolute children will position themselves in relation to it
0091         */
0092         input[type=checkbox] + label {
0093             display: block;
0094             border-radius: 50%;
0095             position: relative;
0096             box-shadow: 0 0 1px #FFF; /* Soften the jagged edge */
0097             background: #2184be none repeat scroll 0 0;
0098             border: 3px solid #9dc8e2;
0099             color: white;
0100             height: 25px;
0101             transition: all 0.4s ease 0s;
0102             width: 25px;
0103         }
0104 
0105         /* Provide a border when hovered and when the checkbox before it is checked */
0106         input[type=checkbox] + label:hover,
0107         input[type=checkbox]:checked + label {
0108             border: 3px solid #9dc8e2;
0109             box-shadow: 0 0 1px #fff;
0110         }
0111 
0112         /*
0113         - Create a pseudo element :after when checked and provide a tick
0114         - Center the content
0115         */
0116         input[type=checkbox]:checked + label:after {
0117             content: '\2714'; /*content is required, though it can be empty - content: '';*/
0118             bottom: 2px;
0119             color: white;
0120             display: block;
0121             height: 1em;
0122             left: 3px;
0123             margin: auto;
0124             position: absolute;
0125             right: 0;
0126             top: -4px;
0127             width: 1em;
0128         }
0129 
0130         .add-product-page {
0131             padding-top: 15px;
0132         }
0133 
0134         section.body {
0135             width: 100% !important;
0136         }
0137 
0138         #is_original-element
0139         {
0140             width: 25px;
0141             float: left;
0142         }
0143         
0144         #is_gitlab_project
0145         {
0146             width: 25px;
0147             float: left;
0148         }
0149         
0150         #gitlab_project_name-element
0151         {
0152             width: 300px;
0153             float: left;
0154         }
0155         
0156         #gitlab_project_id
0157         {
0158             width: 300px;
0159             float: left;
0160         }
0161         
0162         #show_gitlab_project_issues
0163         {
0164             width: 25px;
0165             float: left;
0166         }
0167         
0168         #use_gitlab_project_readme
0169         {
0170             width: 25px;
0171             float: left;
0172         }
0173         
0174         .wizard > .content > .body ul.multiselect-container {
0175             list-style: none !important;
0176         }
0177         
0178         .wizard > .content > .body button.multiselect {
0179             padding-top: 3px;
0180             padding-bottom: 3px;
0181         }
0182         
0183         
0184         
0185         .tables_ui {
0186           display:inline-block;
0187           /*margin:2px 2%;
0188           border:2px solid #3333fe;*/
0189           border-spacing:0;
0190           border: 0;
0191         }
0192         .tables_ui ul li {
0193           min-width: 200px;
0194         }
0195         
0196         .dragging li.ui-state-hover {
0197           min-width: 240px;
0198         }
0199         .dragging .ui-state-hover a {
0200           color:green !important;
0201           font-weight: bold;
0202         }
0203         .tables_ui th,td {
0204           text-align: right;
0205           padding: 2px 4px;
0206         }
0207         .t_sortable tr, .ui-sortable-helper {
0208           cursor: move;
0209           border: 1px solid;
0210         }
0211         
0212         .t_sortable tr:first-child {
0213           cursor: default;
0214         }
0215         .ui-sortable-placeholder {
0216           background: yellow;
0217         }
0218         
0219         .cat_title {
0220             font-size: x-small;
0221             font-weight: bold;
0222         }
0223         
0224         .proj_remove {
0225             color: red;
0226             cursor: pointer;
0227         }
0228         
0229         .ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default, .ui-button, html .ui-button.ui-state-disabled:hover, html .ui-button.ui-state-disabled:active {
0230             border: 1px solid #c5c5c5;
0231             border-bottom-width: 1px;
0232             background: #f6f6f6;
0233             font-weight: normal;
0234             color: #454545;
0235         }
0236 
0237         .ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active, a.ui-button:active, .ui-button:active, .ui-button.ui-state-active:hover {
0238             border: 1px solid #c5c5c5;
0239             border-bottom-width: 1px;
0240             background: #ffffff;
0241             font-weight: normal;
0242             color: #454545;
0243         }
0244         
0245         .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited {
0246             color: #454545;
0247             text-decoration: none;
0248         }
0249         
0250     </style>
0251     
0252 
0253  
0254     
0255     <main class="user-admin-page">
0256 
0257         <?php echo $this->render('user/partials/userHeader_top.phtml'); ?>
0258 
0259         <section class="body-wrap">
0260 
0261             <section class="wrapper product-page">
0262 
0263                 <!-- PAGE BODY -->
0264 
0265                 <section class="my-products-page">
0266 
0267                     <!-- NAVIGATION -->
0268 
0269                     <?php echo $this->render('user/partials/userHeader.phtml'); ?>
0270                      <?php echo $this->render('product/partials/header.phtml'); ?>
0271 
0272                     <!-- /NAVIGATION -->
0273 
0274                     <!-- PAGE BODY -->
0275 
0276                     <section class="add-product-page">
0277 
0278                         <form enctype="multipart/form-data" role="application" class="wizard clearfix" action="" method="post" id="add-product-form">
0279                             <input type="hidden" name="type_id" value="3">
0280                             <input type="hidden" name="project_category_id" value="<?= $this->collection_cat_id ?>">
0281                             <?= $this->form->project_id ?>
0282                             <h3>Basics</h3>
0283                             <section id="required">
0284                                 <div class="form-group"><p class="col-sm-10">(*) Mandatory fields.</p></div>
0285                                 <div id="preview_img_msg" style="float: left;width: 100%;">
0286 
0287                                 </div>
0288                                 <?php // $this->form->title ?>
0289                                 <div class="form-group">
0290                                     <div class="col-sm-12 margin-top-15">
0291                                         <div class="small grey bold-font pull-left margin-right-5">*</div>
0292                                         <label class="form-label" for="title">Collection Name (4 letters min.)</label>
0293                                     </div>
0294                                     <div class="col-sm-12">
0295                                         <input id="title"
0296                                                class="required form-control valid"
0297                                                type="text"
0298                                                name="title"
0299                                                pattern="[^\x22]+"
0300                                                <?php //pattern="^[ .\-&_A-z0-9]{1,}$" ?>
0301                                                <?php //  pattern="^[^\\'\^;*!\u0022\$]{1,}$" ?>
0302                                                value="<?= $this->escape($this->form->title->getValue()) ?>"
0303                                                title="Please use only letters."
0304                                                maxlength="60"
0305                                                aria-required="true"
0306                                                aria-invalid="false"
0307                                                data-rule-minlength="4"
0308                                                data-rule-maxlength="60"
0309                                                data-msg-minlength="At least 4 chars"
0310                                                data-msg-maxlength="At most 60 chars">
0311                                         <?php if ($this->form->title->getMessages()) {
0312                                             $errorHtml = '';
0313                                             foreach ($this->form->title->getMessages() as $currentError) {
0314                                                 $errorHtml .= '<label id="<?=$this->escape($this->form->title->getName())?>-error" class="error" for="<?=$this->escape($this->form->title->getName())?>">' . $currentError . '</label>';
0315                                             }
0316                                             ?>
0317                                             <?php echo $errorHtml ?>
0318                                         <?php } ?>
0319                                     </div>
0320                                 </div>
0321                                 
0322                                 <?= $this->form->description ?>
0323                                 
0324                                 <?php /*
0325                                 <?= $this->form->project_category_id ?>
0326                                 <?= $this->form->project_subcategory_id ?>
0327                                 <?= $this->form->project_sub_subcategory_id ?>
0328                                  * <?= $this->form->user_category ?>
0329                                  * <?= $this->form->version ?>
0330                                  */?>
0331                                 
0332                                 
0333 
0334                                 <?php /*
0335                                 <?= $this->form->source_url ?>
0336                                 */?>
0337                                 
0338                                 <?php /*
0339 
0340                                 <div class="form-group">
0341                                 <div class="col-sm-12 margin-top-15">
0342                                  <?= $this->form->is_original ?>  Check this box, if this is your own original work and not based on something else      
0343                                 </div>
0344                                 </div>  
0345                                  * 
0346                                                              
0347                                 
0348                                 <?= $this->form->license_tag_id ?>
0349                                  <?php
0350                                     if($this->project_id)
0351                                     {
0352                                                 $tagmodel = new Default_Model_Tags();
0353                                                 $tagscat = $tagmodel->getTagsCategory($this->project_id, Default_Model_Tags::TAG_TYPE_PROJECT);
0354                                                 if(strlen($tagscat)>0)
0355                                                 {
0356                                         ?>
0357                                     <div class="form-group">
0358                                         <div class="col-sm-12 margin-top-15">
0359                                             <label class="form-label"> System Auto Tags</label>
0360                                         </div>
0361                                         <div class="col-sm-12">
0362                                           <?php echo $tagscat ; ?>
0363                                         </div>
0364                                     </div>
0365                                     <?php
0366                                         }
0367                                     }
0368                                 ?>
0369  
0370                                 
0371                                 */?>
0372                                 <?= $this->form->tagsuser ?>
0373                                 <?= $this->form->image_small ?>
0374                                 <?= $this->form->image_small_upload ?>
0375                                 <?php //$this->form->image_big ?>
0376                                 <?php //$this->form->image_big_upload ?>
0377                                 <?php /*
0378                                 <?= $this->form->gallery ?>
0379                                 <?= $this->form->embed_code ?>                               
0380 
0381                                 <?= $this->form->link_1 ?>
0382                                 <?= $this->form->facebook_code ?>
0383                                 <?= $this->form->twitter_code ?>
0384                                 <?= $this->form->google_code ?>
0385                                 */?>
0386 
0387                             </section>
0388                             
0389                             <h3>Products</h3>
0390                             <section id="products">
0391                                 
0392                                 
0393                                 
0394                                 <h3>Products</h3>
0395                                 
0396                                 <div id="div-collection-projects" style="width: 550px;float: left;margin-top: 35px;">
0397                                     
0398                                     <caption style="width: 100%;padding-top: 34px;"> <h4>Drop the Products here</h4> </caption>
0399                                     
0400                                     <table class="tables_ui" id="t_draggable1" data-collection-projects="" style="width: 500px;height: 600px; padding: 10px; overflow-x: auto;">
0401                                         <tbody class="t_sortable">
0402                                             <tr>
0403                                                 <th colspan="2" style="min-height: 50px;">Drop the Products here</th>
0404                                             </tr>
0405                                         </tbody>
0406                                     </table>
0407                                     
0408                                     
0409                                 </div> 
0410                                 
0411                                 <div id="div-projects" style="width: 550px;float: left;">
0412                                     Search (includes new products every 5 minutes)
0413                                     <input class="form-control" width="10" type="text" id="search_products" alt="" placeholder="Search (min 3 Chars)" autocomplete="off">
0414                                     
0415                                     <caption style="width: 100%;"><h4>Drag the Products from here (actively published)</h4></caption>
0416                                     
0417                                     
0418                                     <div id="tabs">
0419                                         <ul>
0420                                             <li>
0421                                                 <a href="#tabs-1" role="presentation" tabindex="-1" class="ui-tabs-anchor" id="ui-id-1">Own Products</a>
0422                                             </li>
0423                                             <li>
0424                                                 <a href="#tabs-2" role="presentation" tabindex="-1" class="ui-tabs-anchor" id="ui-id-2">All Products</a></li>
0425                                         </ul>
0426                                         <div id="tabs-1" style="padding: 0 !important;">
0427                                             <table class="tables_ui" id="t_draggableOwn" data-own-projects="" style="height: 600px; padding: 10px; overflow-x: auto;">
0428                                                 <tbody class="t_sortable">
0429                                                     <tr><td style='text-align: left; width: 440px; min-height: 50px;'>No Products found</td></tr>
0430                                                 </tbody>
0431                                             </table>
0432                                         </div>
0433                                         <div id="tabs-2" style="padding: 0 !important;">
0434                                             <table class="tables_ui" id="t_draggableAll" data-all-projects="" style="height: 600px; padding: 10px; overflow-x: auto;">
0435                                                 <tbody class="t_sortable">
0436                                                     <tr><td style='text-align: left; width: 440px; min-height: 50px;'>No Products found</td></tr>
0437                                                 </tbody>
0438                                             </table>
0439                                         </div>
0440                                       </div>
0441                                 </div> 
0442                                 <!-- products -->
0443                             </section>
0444                             
0445                             
0446                             
0447                         <?php if(isset($this->project_id)) { ?>
0448                             <h3>Changelog</h3>
0449                             <section id="changlog">
0450 
0451                                     <div id="modal-changlog" data-product-id="">
0452                                         <div class="row">
0453                                             <div class="modal-header">
0454                                                 <h3 id="modal-ppload-label"><?= $this->translate('Changelog') ?></h3>
0455                                             </div>
0456                                             <div class="modal-body" style="font-size: small;">
0457                                                 <div role="form" class="">
0458                                                     <input type="hidden" data-update-id="" id="update-id" value="">
0459                                                     <div class="form-group">
0460                                                       <label for="tile">Changelog Title:</label>
0461                                                       <input type="text" id="update-title" data-update-title="" class="form-control input-sm" placeholder="Enter Changelog Title">
0462                                                     </div>
0463                                                     <div class="form-group">
0464                                                       <label for="text">Changelog Text:</label>
0465                                                       <textarea id="update-text" data-update-text="" class="form-control input-sm" rows="3" placeholder="Enter Changelog Text"></textarea>
0466                                                     </div>
0467                                                     <button type="submit" class="btn btn-native" data-add-update-btn="">Save Changelog</button>
0468                                                 </div>
0469 
0470                                                 <h4 style="padding-top: 15px;"> Your Entries:</h4>
0471                                                 <article id="update-list">
0472 
0473                                                 </article>
0474                                             </div>
0475                                         </div>
0476                                     </div>
0477                                 <!-- changlog -->
0478                             </section>
0479                         <?php } ?>
0480 
0481 
0482                         </form>
0483 
0484                         <!-- /PAGE BODY -->
0485 
0486                     </section>
0487 
0488                     <!-- /PAGE BODY -->
0489 
0490                 </section>
0491 
0492             </section>
0493         </section>
0494     </main>
0495 
0496     <script>
0497         $(document).ready(function () {
0498             
0499             
0500             /*
0501             $('.multiple').multiselect({
0502                 includeSelectAllOption: true
0503             });
0504             */
0505            
0506             function wait(ms){
0507                 var start = new Date().getTime();
0508                 var end = start;
0509                 while(end < start + ms) {
0510                   end = new Date().getTime();
0511                 }
0512             }
0513            
0514             function scrolify(tblAsJQueryObject, height) {
0515                 var oTbl = tblAsJQueryObject;
0516 
0517                 // for very large tables you can remove the four lines below
0518                 // and wrap the table with <div> in the mark-up and assign
0519                 // height and overflow property  
0520                 var oTblDiv = $("<div/>");
0521                 oTblDiv.css('height', height);
0522                 oTblDiv.css('overflow', 'scroll');
0523                 oTbl.wrap(oTblDiv);
0524 
0525                 // save original width
0526                 oTbl.attr("data-item-original-width", oTbl.width());
0527                 oTbl.find('thead tr td').each(function() {
0528                   $(this).attr("data-item-original-width", $(this).width());
0529                 });
0530                 oTbl.find('tbody tr:eq(0) td').each(function() {
0531                   $(this).attr("data-item-original-width", $(this).width());
0532                 });
0533 
0534 
0535                 // clone the original table
0536                 var newTbl = oTbl.clone();
0537 
0538                 // remove table header from original table
0539                 oTbl.find('thead tr').remove();
0540                 // remove table body from new table
0541                 newTbl.find('tbody tr').remove();
0542 
0543                 oTbl.parent().parent().prepend(newTbl);
0544                 newTbl.wrap("<div/>");
0545 
0546                 // replace ORIGINAL COLUMN width        
0547                 newTbl.width(newTbl.attr('data-item-original-width'));
0548                 newTbl.find('thead tr td').each(function() {
0549                   $(this).width($(this).attr("data-item-original-width"));
0550                 });
0551                 oTbl.width(oTbl.attr('data-item-original-width'));
0552                 oTbl.find('tbody tr:eq(0) td').each(function() {
0553                   $(this).width($(this).attr("data-item-original-width"));
0554                 });
0555             }
0556 
0557             var formElement = $('#add-product-form');
0558             var validator = formElement.validate({
0559                 ignore: ":disabled,:hidden"
0560             });
0561             
0562             
0563     
0564             formElement.steps({
0565                 headerTag: "h3",
0566                 bodyTag: "section",
0567                 enableAllSteps: <?php echo ($this->mode == 'editcollection') ? "true" : "false"; ?>,
0568                 enableCancelButton: true,
0569                 showFinishButtonAlways: true,
0570                 transitionEffect: "slideLeft",
0571               /* Labels */
0572                 labels: {
0573                     cancel: "Cancel",
0574                     finish: "Save"
0575                 },
0576                 onStepChanging: function (event, currentIndex, newIndex) {
0577                     // Allways allow previous action even if the current form is not valid!
0578                     if (currentIndex > newIndex) {
0579                         return true;
0580                     }
0581                     // Needed in some cases if the user went back (clean up)
0582                     if (currentIndex < newIndex) {
0583                         // To remove error styles
0584                         formElement.find(".body:eq(" + newIndex + ") label.error").remove();
0585                         formElement.find(".body:eq(" + newIndex + ") .error").removeClass("error");
0586                     }
0587 
0588                     if (currentIndex == 0) {
0589                         if (ImagePreview.hasError) {
0590                             return false;
0591                         }
0592                         //logo OR preview pic mandatory!
0593                         var logoSrc = $('#product-picture-preview').attr('src');
0594                         var gallery = $('.product-gallery div:first-child');
0595                         var galleryPic = gallery.find('.image');
0596                         
0597                         getCollectionProjects();
0598 
0599                         if (!logoSrc) {
0600                             var msg = $('#preview_img_msg');
0601                             msg.text('');
0602                             msg.append('<label id="description-error" class="error" for="product-gallery">Please add a product logo!</label>');
0603 
0604                             return false;
0605                         }
0606 
0607                         if (formElement.valid()) {
0608                             if (ProductForm.mode == 'addcollection' && (ProductForm.project_id == '' || ProductForm.project_id == undefined)) {
0609                                 var result = ProductForm.saveSection(formElement.find('.body:eq(' + currentIndex + ')').attr('id'));
0610                                 if (result == false) {
0611                                     validator.showErrors(ProductForm.errors);
0612                                     return result;
0613                                 }
0614                                 formElement.find("#modal-changlog").attr('data-product-id', ProductForm.project_id);
0615                             }
0616                             getCollectionProjects();
0617                             getOwnProjects();
0618                             
0619                             initDragDrop();
0620                             
0621                             return true;
0622                         }
0623                         return false;
0624                     }
0625                     return formElement.valid();
0626                 },
0627 
0628                 onFinished: function (event, currentIndex) {
0629                     //logo OR preview pic mandatory!
0630                     var logoSrc = $('#product-picture-preview').attr('src');
0631                     var gallery = $('.product-gallery div:first-child');
0632                     var galleryPic = gallery.find('.image');
0633 
0634                     if (!logoSrc) {
0635                         var msg = $('#preview_img_msg');
0636                         msg.text('');
0637                         msg.append('<label id="description-error" class="error" for="product-gallery">Please add a product logo!</label>');
0638 
0639                         return false;
0640                     }
0641 
0642                     if (currentIndex == 0) {
0643                         if (ImagePreview.hasError) {
0644                             return false;
0645                         }
0646                         if (ProductForm.mode == 'addcollection' && (ProductForm.project_id == '' || ProductForm.project_id == undefined)) {
0647                             var result = ProductForm.saveSection(formElement.find('.body:eq(' + currentIndex + ')').attr('id'));
0648                             if (result == false) {
0649                                 validator.showErrors(ProductForm.errors);
0650                                 return result;
0651                             }
0652                             formElement.find("#modal-changlog").attr('data-product-id', ProductForm.project_id);
0653                         }
0654                     }
0655 
0656 
0657                     $('[name=project_id]').val(ProductForm.project_id);
0658                     formElement.submit();
0659                 },
0660 
0661                 onCanceled: function (event, currentIndex) {
0662                     window.location.href = "/member/<?php echo $this->member->member_id; ?>/collections/";
0663                 }
0664 
0665             });
0666             
0667             function throttle(f, delay){
0668                 var timer = null;
0669                 return function(){
0670                     var context = this, args = arguments;
0671                     clearTimeout(timer);
0672                     timer = window.setTimeout(function(){
0673                         f.apply(context, args);
0674                     },
0675                     delay || 700);
0676                 };
0677             }
0678             
0679             $('#search_products').bind('input', throttle(function(e) {
0680                 e.preventDefault();
0681                 $(this).next();
0682                 $val = $(this).val(); 
0683                 if($val.length>=3) {
0684                     getOwnProjects($val);
0685                     getAllProjects($val);
0686                 } else {
0687                     clearLists();
0688                 }
0689             }));
0690             
0691             $('#search_products').bind("enterKey",function(e){
0692                 //do stuff here
0693                 e.preventDefault();
0694                 return false;
0695             });
0696             $('#search_products').keyup(function(e){
0697                 e.preventDefault();
0698                 if(e.keyCode == 13)
0699                 {
0700                     return false;
0701                 }
0702             });
0703 
0704             $(window).keydown(function(event){
0705                 if(event.keyCode == 13) {
0706                   event.preventDefault();
0707                   return false;
0708                 }
0709             });
0710             
0711 
0712             $('body').on("click", "#github_picker", function (event) {
0713 
0714                 html = '<form id="get-url-form">' +
0715                     '<div class="form-group">' +
0716                     '<input type="url" class="form-control" id="get-url" placeholder="Enter a URL where the files can be downloaded" required="required">' +
0717                     '<span id="get-url-help" class="help-block small">e.g. https://github.com/mongodb/mongo/archive/r3.5.2.tar.gz</span></div>' +
0718                     '<span id="get-url-error" class="help-block small"></span></div>' +
0719                     '<button type="submit" class="btn btn-native btn-sm" id="get-url-submit">Submit</button>' +
0720                     '</form>';
0721 
0722                 var msgBox = $('#generic-dialog');
0723                 msgBox.modal('hide');
0724                 msgBox.find('.modal-header-text').empty().append('Enter a download URL:');
0725                 msgBox.find('.modal-body').empty().append(html);
0726                 setTimeout(function () {
0727                     msgBox.modal('show');
0728                 }, 900);
0729 
0730             });
0731 
0732 
0733                 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}}
0734                 $('button[rel="tooltip"]').tooltip();
0735 
0736                 var $divCollectionProjects = $('#div-collection-projects');
0737                 var $divProjects = $('#div-projects');
0738                 
0739                 var $modalChanglog = $('#modal-changlog');
0740 
0741                 function keysrt(key, asc) {
0742                     if(asc) {
0743                         return function(a,b){
0744                             if (a[key] > b[key]) return 1;
0745                             if (a[key] < b[key]) return -1;
0746                             return 0;
0747                         }
0748                     } else {
0749                         return function(a,b){
0750                             if (a[key] < b[key]) return 1;
0751                             if (a[key] > b[key]) return -1;
0752                             return 0;
0753                         }
0754                     }
0755                 }
0756                 
0757                 String.prototype.trunc = String.prototype.trunc ||
0758                     function(n){
0759                         return (this.length > n) ? this.substr(0, n-1) + '&hellip;' : this;
0760                     };
0761                 
0762                 function getCollectionProjects() {
0763                     
0764                     var prodId = ProductForm.project_id;
0765                     if(!prodId) {
0766                         prodId = 0;
0767                     }
0768                     
0769                     $.ajax({
0770                         url: '/c/'+prodId+'/getcollectionprojectsajax',
0771                         type: 'GET',
0772                         async: false,
0773                         cache: false,
0774                         timeout: 30000,
0775                         data: {},
0776                         dataType: 'json',
0777                         success: function (data, textStatus, jqXHR) {
0778                             if (data.status == 'success') {
0779                                 projects = data.projects;
0780                                 
0781                                 $divCollectionProjects.find('table[data-collection-projects] tbody').html('');
0782                                 
0783                                 tableString = "<tr><td style='align-content: center;text-align: center; width: 60px;'></td><td style='text-align: left; width: 440px; min-height: 50px;'></td></tr>";
0784                                 
0785                                 $i = 1;
0786                                 $.each(projects, function() {
0787                                     tableString += "<tr style='background-color: white;' data-project-id=" + this.project_id + ">";
0788                                     tableString += "<td style='align-content: left;text-align: left;'><span class='counter'>" + $i + ".</span></td>";
0789                                     tableString += "<td style='align-content: center;text-align: center; width: 10%;'><img style='height: 50px;width: 50px;' src='" + this.image_url + "'></td>";
0790                                     tableString += "<td style='text-align: left; width: 90%;'>" + this.title.trim().trunc(25) + "<p class='cat_title'>" + this.cat_title +"</p></td>";
0791                                     tableString += "<td style='align-content: center;text-align: center;'><span class='proj_action glyphicon glyphicon-remove proj_remove'></span></td>";
0792                                     tableString += "</tr>";
0793                                     
0794                                     $divCollectionProjects.append("<input type='hidden' class='collection_project_id_item' id='collection_project_id" + this.project_id + "' name='collection_project_id["+$i+"]' value='" + this.project_id + "'>");
0795                                     $i++;
0796                                     
0797                                 });
0798                                 
0799                                 $divCollectionProjects.find('table[data-collection-projects] tbody').append(tableString);
0800                             }
0801                         }
0802                     })
0803                     
0804                 }
0805                 
0806                 function clearLists() {
0807                     $divProjects.find('table[data-all-projects] tbody').html('');
0808                     $divProjects.find('table[data-own-projects] tbody').html('');
0809                 }
0810                 
0811                 function getOwnProjects(search) {
0812                     var prodId = ProductForm.project_id;
0813                     if(!prodId) {
0814                         prodId = 0;
0815                     }
0816                     
0817                     $divProjects.find('table[data-own-projects] tbody').html('<img src="/images/system/ajax-loader.gif">');
0818                     
0819                     $.ajax({
0820                         url: '/c/'+prodId+'/getprojectsajax',
0821                         type: 'GET',
0822                         async: false,
0823                         cache: false,
0824                         timeout: 30000,
0825                         data: {search: search, search_all: false},
0826                         dataType: 'json',
0827                         success: function (data, textStatus, jqXHR) {
0828                             if (data.status == 'success') {
0829                                 projects = data.projects;
0830                                 count = data.ResultSize;
0831                                 
0832                                 $divProjects.find('table[data-own-projects] tbody').html('');
0833                                 
0834                                 
0835                                 if(count == 0) {
0836                                     tableString = "<tr><td style='text-align: left; width: 440px; min-height: 50px;'>No Products found</td></tr>";
0837                                 } else {
0838                                     tableString = "<tr><td style='align-content: center;text-align: center; width: 60px;'></td><td style='text-align: left; width: 440px; min-height: 50px;'></td></tr>";
0839                                     $.each(projects, function() {
0840                                         tableString += "<tr style='background-color: white;' data-project-id=" + this.project_id + ">";
0841                                         tableString += "<td style='align-content: left;text-align: left;'><span class='counter'></span></td>";
0842                                         tableString += "<td style='align-content: center;text-align: center; width: 10%;'><img style='height: 50px;width: 50px;' src='" + this.image_url + "'></td>";
0843                                         tableString += "<td style='text-align: left; width: 90%;'>" + this.title.trim().trunc(25) + "<p class='cat_title'>" + this.cat_title +"</p></td>";
0844                                         tableString += "<td style='align-content: center;text-align: center;'><span class='proj_action'></span></td>";
0845                                         tableString += "</tr>";
0846                                     });
0847                                 }
0848                                 $divProjects.find('table[data-own-projects] tbody').append(tableString);
0849                             }
0850                         }
0851                     })
0852                 }
0853                 
0854                 function getAllProjects(search) {
0855                     var prodId = ProductForm.project_id;
0856                     if(!prodId) {
0857                         prodId = 0;
0858                     }
0859                     
0860                     $divProjects.find('table[data-all-projects] tbody').html('<img src="/images/system/ajax-loader.gif">');
0861                     
0862                     $.ajax({
0863                         url: '/c/'+prodId+'/getprojectsajax',
0864                         type: 'GET',
0865                         async: false,
0866                         cache: false,
0867                         timeout: 30000,
0868                         data: {search: search, search_all: true},
0869                         dataType: 'json',
0870                         success: function (data, textStatus, jqXHR) {
0871                             if (data.status == 'success') {
0872                                 projects = data.projects;
0873                                 count = data.ResultSize;
0874                                 
0875                                 $divProjects.find('table[data-all-projects] tbody').html('');
0876                                 
0877                                 
0878                                 if(count == 0) {
0879                                     tableString = "<tr><td style='text-align: left; width: 440px; min-height: 50px;'>No Products found</td></tr>";
0880                                 } else {
0881                                     tableString = "<tr><td style='align-content: center;text-align: center; width: 60px;'></td><td style='text-align: left; width: 440px; min-height: 50px;'></td></tr>";
0882                                     $.each(projects, function() {
0883                                         tableString += "<tr style='background-color: white;' data-project-id=" + this.project_id + ">";
0884                                         tableString += "<td style='align-content: left;text-align: left;'><span class='counter'></span></td>";
0885                                         tableString += "<td style='align-content: center;text-align: center; width: 10%;'><img style='height: 50px;width: 50px;' src='" + this.image_url + "'></td>";
0886                                         tableString += "<td style='text-align: left; width: 90%;'>";
0887                                         tableString += "<div style='float: left;'>"+this.title.trim().trunc(25)+"<p class='cat_title'>" + this.cat_title +"</p></div>";
0888                                         tableString += "<div style='float: right;'> by "+this.username+"</div>";
0889                                         
0890                                         tableString += "</td>";
0891                                         tableString += "<td style='align-content: center;text-align: center;'><span class='proj_action'></span></td>";
0892                                         tableString += "</tr>";
0893                                     });
0894                                 }
0895                                 
0896                                 $divProjects.find('table[data-all-projects] tbody').append(tableString);
0897                             }
0898                         }
0899                     })
0900                 }
0901                 
0902                 function updateCollectionProjects() {
0903                     $collection_project_ids = "";
0904                     $divCollectionProjects.find('table').find('tr').each(function() {
0905                         if(null != $(this).attr('data-project-id') && $(this).attr('data-project-id') != undefined) {
0906                             $collection_project_ids += $(this).attr('data-project-id') + ',';
0907                         }
0908                     });
0909                     
0910                     $collId = ProductForm.project_id;
0911                     
0912                     $.ajax({
0913                         url: '/c/'+ $collId + '/updatecollectionprojectsajax',
0914                         type: 'POST',
0915                         data: {collection_project_ids: $collection_project_ids},
0916                         dataType: 'json',
0917                         async: false,
0918                         success: function (data, textStatus, jqXHR) {
0919                             if (data.status != 'success') {
0920                                 return;
0921                             }
0922                         },
0923                         error: function (jqXHR, textStatus, errorThrown) {
0924                             return;
0925                         }
0926                     });
0927                 }
0928 
0929                 
0930                 function initDragDrop() {
0931                     $( "#tabs" ).tabs();
0932                     
0933                     var $tabsOwn = $('#t_draggableOwn');
0934                     $("tbody.t_sortable").sortable({
0935                       connectWith: ".t_sortable",
0936                       items: "> tr:not(:first)",
0937                       //appendTo: $tabsOwn,
0938                       helper:"clone",
0939                       zIndex: 999990,
0940                       update: function (event, ui) {
0941                         $('.collection_project_id_item').remove();
0942                         $index = -1;
0943                         $divCollectionProjects.find('table').find('tr').each(function() {
0944                             $index = $(this).index();
0945                             if(null != $(this).attr('data-project-id') && $(this).attr('data-project-id') != undefined) {
0946                                 $divCollectionProjects.append("<input class='collection_project_id_item' type='hidden' id='collection_project_id" + $(this).attr('data-project-id') + "' name='collection_project_id["+$index+"]' value='" + $(this).attr('data-project-id') + "'>");
0947                                 $(this).find('.counter').html($index+'.');
0948                             }
0949                         });
0950                         updateCollectionProjects();
0951                       }   
0952                     }).disableSelection();
0953                     
0954                     
0955                     var $tabsAll = $('#t_draggableAll');
0956                     $("tbody.t_sortable").sortable({
0957                       connectWith: ".t_sortable",
0958                       items: "> tr:not(:first)",
0959                       //appendTo: $tabsAll,
0960                       helper:"clone",
0961                       zIndex: 999999,
0962                       update: function (event, ui) {
0963                         $('.collection_project_id_item').remove();
0964                         $index = -1;
0965                         $divCollectionProjects.find('table').find('tr').each(function() {
0966                             $index = $(this).index();
0967                             if(null != $(this).attr('data-project-id') && $(this).attr('data-project-id') != undefined) {
0968                                 $divCollectionProjects.append("<input class='collection_project_id_item' type='hidden' id='collection_project_id" + $(this).attr('data-project-id') + "' name='collection_project_id["+$index+"]' value='" + $(this).attr('data-project-id') + "'>");
0969                                 $(this).find('.counter').html($index+'.');
0970                             }
0971                         });
0972                         updateCollectionProjects();
0973                       }   
0974                     }).disableSelection();
0975                     
0976 
0977 
0978 
0979 
0980 
0981                     //var $tab_items = $divCollectionProjects.find('table[data-collection-projects] tbody').droppable({
0982                     var $tab_items = $divCollectionProjects.find('table[data-collection-projects]').droppable({
0983                       accept: ".t_sortable tr",
0984                       hoverClass: "ui-state-hover",
0985                       drop: function( event, ui ) { 
0986                             $('.collection_project_id_item').remove();
0987                             $index = -1;
0988                             ui.draggable.find('.proj_action').removeClass('glyphicon glyphicon-remove proj_remove');
0989                             ui.draggable.find('.proj_action').addClass('glyphicon glyphicon-remove proj_remove');
0990                             $divCollectionProjects.find('table').find('tr').each(function() {
0991                                 $index = $(this).index();
0992                                 if(null != $(this).attr('data-project-id') && $(this).attr('data-project-id') != undefined) {
0993                                     $divCollectionProjects.append("<input class='collection_project_id_item' type='hidden' id='collection_project_id" + $(this).attr('data-project-id') + "' name='collection_project_id["+$index+"]' value='" + $(this).attr('data-project-id') + "'>");
0994                                     $(this).find('.counter').html($index+'.');
0995                                 }
0996                             });
0997                             
0998                             $('.proj_remove').on('click', function (event) {
0999                                 event.preventDefault();
1000 
1001                                 $(this).parent().parent().remove();
1002                                 $('.collection_project_id_item').remove();
1003                                 $index = -1;
1004                                 $divCollectionProjects.find('table').find('tr').each(function() {
1005                                     $index = $(this).index();
1006                                     if(null != $(this).attr('data-project-id') && $(this).attr('data-project-id') != undefined) {
1007                                         $divCollectionProjects.append("<input class='collection_project_id_item' type='hidden' id='collection_project_id" + $(this).attr('data-project-id') + "' name='collection_project_id["+$index+"]' value='" + $(this).attr('data-project-id') + "'>");
1008                                         $(this).find('.counter').html($index+'.');
1009                                     }
1010                                 });
1011                             });
1012                             
1013                             updateCollectionProjects();
1014                             
1015                             return false; 
1016                       },
1017                       out: function( event, ui ) { 
1018                           $divCollectionProjects.find('#collection_project_id' + ui.draggable.attr('data-project-id')).remove();
1019                           updateCollectionProjects();
1020                           return false; 
1021                       }
1022                     });
1023                     
1024                     //scrolify($('#t_draggable1'), 500); // 160 is height
1025                     //scrolify($('#t_draggable2'), 500); // 160 is height
1026                     
1027                     $('.proj_remove').on('click', function (event) {
1028                         event.preventDefault();
1029                         
1030                         $(this).parent().parent().remove();
1031                         $('.collection_project_id_item').remove();
1032                         $index = -1;
1033                         $divCollectionProjects.find('table').find('tr').each(function() {
1034                             $index = $(this).index();
1035                             if(null != $(this).attr('data-project-id') && $(this).attr('data-project-id') != undefined) {
1036                                 $divCollectionProjects.append("<input class='collection_project_id_item' type='hidden' id='collection_project_id" + $(this).attr('data-project-id') + "' name='collection_project_id["+$index+"]' value='" + $(this).attr('data-project-id') + "'>");
1037                                 $(this).find('.counter').html($index+'.');
1038                             }
1039                         });
1040                         updateCollectionProjects();
1041                     });
1042                     
1043                     
1044                 }
1045 
1046                 function getUpdates(page) {
1047 
1048                     $modalChanglog.find('#update-list').html('');
1049                     var productId = <?= isset($this->project_id)?$this->project_id:0 ?>;
1050                     $.ajax({
1051                         url: '<?=$helpCollectionUrl->buildProductUrl($this->project_id, 'getupdatesajax')?>',
1052                         type: 'GET',
1053                         data: {
1054                             format: 'json',
1055                             ignore_status_code: 1
1056                         },
1057                         dataType: 'json',
1058                         success: function (data, textStatus, jqXHR) {
1059                             if (data.status != 'success') {
1060                                 return;
1061                             }
1062                             $.each(data.updates, function () {
1063                                 var id = '';
1064                                 if (this.project_update_id) {
1065                                     id = this.project_update_id;
1066                                 }
1067                                 var title = '';
1068                                 if (this.title) {
1069                                     title = this.title;
1070                                 }
1071                                 var text = '';
1072                                 if (this.text) {
1073                                     text = this.text;
1074                                 }
1075                                 var date = '';
1076                                 if (this.created_at) {
1077                                     date = this.created_at;
1078                                 }
1079 
1080                                 Changelog.setLogMsg(id, this.raw_title, this.raw_text);
1081 
1082                                 var divEl = $('<div />');
1083                                 divEl.attr('data-update-id', id);
1084                                 divEl.append(
1085                                     '<a name="anker_'+id+'"></a>'
1086                                     + '<h4>'+title+'</h4>'
1087                                     + '<div class="small light lightgrey product-update-date">'+date+ '</div>'
1088                                     + text + '<br/><br/>'
1089                                 );
1090 
1091                                 var btnEdit = $('<button type="submit" class="btn btn-native btn-sm" style="line-height: 10px;margin: 5px;">Edit</button>');
1092                                 btnEdit.attr('data-change-update-btn',id);
1093                                 btnEdit.attr('data-change-title',title);
1094                                 btnEdit.attr('data-change-text',text);
1095 
1096 
1097                                 var btnDelete = $('<button type="submit" class="btn btn-native btn-sm" style="line-height: 10px;margin: 5px;">Delete</button>');
1098                                 btnDelete.attr('data-delete-update-btn',id);
1099 
1100                                 divEl.append(btnEdit);
1101                                 divEl.append(btnDelete);
1102                                 divEl.append('<br/><br/><br/><br/>');
1103 
1104                                 $modalChanglog.find('#update-list').append(divEl);
1105                             });
1106                         },
1107                         error: function (jqXHR, textStatus, errorThrown) {
1108                             return;
1109                         }
1110                     });
1111 
1112                 }
1113 
1114                 
1115                 function humanFileSize(bytes) {
1116                     var size = '';
1117                     size = (bytes / 1048576).toFixed(2) + ' MB';
1118                     /*
1119                      if (bytes >= 1073741824) {
1120                      size = (bytes / 1073741824).toFixed(2) + 'GB';
1121                      }
1122                      else if (bytes >= 1048576) {
1123                      size = (bytes / 1048576).toFixed(2) + 'MB';
1124                      }
1125                      else if (bytes >= 1024) {
1126                      size = (bytes / 1024).toFixed(2) + 'KB';
1127                      }
1128                      else {
1129                      size = bytes + 'bytes';
1130                      }*/
1131                     return size;
1132                 }
1133                 
1134                 $modalChanglog.on('click', 'button[data-add-update-btn]', function (event) {
1135                     var update_id = $modalChanglog.find('#update-id').val();
1136                     var title = $modalChanglog.find('#update-title').val();
1137                     var text = $modalChanglog.find('#update-text').val();
1138                     var productId = <?= isset($this->project_id)?$this->project_id:0 ?>;
1139                     event.preventDefault();
1140 
1141                     $.ajax({
1142                         url: '<?=$helpCollectionUrl->buildProductUrl($this->project_id, 'saveupdateajax')?>',
1143                         type: 'POST',
1144                         data: {title: title, text: text, update_id: update_id},
1145                         dataType: 'json',
1146                         success: function (data, textStatus, jqXHR) {
1147                             if (data.status != 'success') {
1148                                 return;
1149                             }
1150                             $modalChanglog.find('#update-title').val('');
1151                             $modalChanglog.find('#update-text').val('');
1152                             $modalChanglog.find('#update-id').val('');
1153                             getUpdates();
1154                         },
1155                         error: function (jqXHR, textStatus, errorThrown) {
1156                             return;
1157                         }
1158                     });
1159 
1160                 });
1161 
1162                 $modalChanglog.on('click', 'button[data-delete-update-btn]', function (event) {
1163                     var updateId = $(this).attr('data-delete-update-btn');
1164                     var productId = <?= isset($this->project_id)?$this->project_id:0 ?>;
1165                     event.preventDefault();
1166 
1167                     $.ajax({
1168                         url: '<?=$helpCollectionUrl->buildProductUrl($this->project_id, 'deleteupdateajax')?>',
1169                         type: 'POST',
1170                         data: {update_id: updateId},
1171                         dataType: 'json',
1172                         success: function (data, textStatus, jqXHR) {
1173                             if (data.status != 'success') {
1174                                 alert('Update could not be deleted!');
1175                                 return;
1176                             }
1177                             getUpdates();
1178                         },
1179                         error: function (jqXHR, textStatus, errorThrown) {
1180                             return;
1181                         }
1182                     });
1183 
1184                 });
1185 
1186                 $modalChanglog.on('click', 'button[data-change-update-btn]', function (event) {
1187                     var updateId = $(this).attr('data-change-update-btn');
1188                     //var title = $(this).attr('data-change-title');
1189                     //var text = $(this).attr('data-change-text');
1190                     var changelog = Changelog.getLogMsg(updateId);
1191                     var title = changelog.msg_title;
1192                     var text = changelog.msg_text;
1193 
1194                     $modalChanglog.find('#update-title').val(title);
1195                     $modalChanglog.find('#update-text').val(text);
1196                     $modalChanglog.find('#update-id').val(updateId);
1197 
1198                     $modalChanglog.find('#update-title').focus();
1199 
1200                     event.preventDefault();
1201                 });
1202         });
1203 
1204 
1205 
1206         var LogCollection=function()
1207         {
1208             this.changelogs = {};
1209 
1210             this.setLogMsg =
1211                 function(id, title, msg) {
1212                     this.changelogs[id] = {msg_title:title, msg_text:msg};
1213             };
1214 
1215             this.getLogMsg =
1216                 function(id) {
1217                     return this.changelogs[id];
1218                 }
1219         };
1220 
1221         var Changelog = new LogCollection();
1222     </script>
1223   <script>
1224           $.fn.sortSelect = function() {
1225               var op = this.children("option");
1226               op.sort(function(a, b) {
1227                   return a.text > b.text ? 1 : -1;
1228               })
1229               return this.empty().append(op);
1230           }
1231 
1232           $.fn.sort_select_box = function(){
1233               var my_options = $("option", $(this));
1234               my_options.sort(function(a,b) {
1235                   if (a.text > b.text) return 1;
1236                   else if (a.text < b.text) return -1;
1237                   else return 0
1238               });
1239               $(this).empty().append(my_options);
1240           }
1241 
1242           function setSourceNeededForCategoryInfo(element_id, cat_id) {
1243             $('.cat_source_info').remove();
1244             jQuery.ajax({
1245                 data: {'cat_id': cat_id},
1246                 url: '/productcategory/fetchsourceneeded/',
1247                 type: 'get',
1248                 success: function (results) {
1249                     var isSourceRequired = results.source_required;
1250 
1251                     if(isSourceRequired == 1) {
1252                         $('#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>');
1253                     }
1254                 }
1255             });
1256           }
1257           
1258           
1259           ProductForm = {
1260 
1261               mode: "<?=$this->mode?>",
1262               project_id: <?php echo ($this->mode == 'editcollection') ? $this->project_id : '$(\'#project_id\').val()'?>,
1263               errors: "",
1264               cat_id_data: <?=json_encode($categories)?>,
1265               cat_id_path: <?=json_encode($categoryPath)?>,
1266               store_cat_ids: <?=json_encode($storeCatIds)?>,
1267               value_cat_id: <?=json_encode($valueCatId)?>,
1268 
1269               setup: function () {
1270                   //this.setupCategorySelect();
1271                   //this.setupCategoryAjax();
1272                   //this.setGitlabProjectNameSelect();
1273               },
1274 
1275               setSourceNeededForCategoryInfo: function(element_id, cat_id) {
1276 
1277                 jQuery.ajax({
1278                     data: {'cat_id': cat_id},
1279                     url: '/productcategory/fetchsourceneeded/',
1280                     type: 'get',
1281                     success: function (results) {
1282                         var isSourceRequired = results.source_required;
1283                         if(isSourceRequired == 1) {
1284                             $('#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>');
1285                         }
1286                     }
1287                 });
1288               },
1289                   
1290               setGitlabProjectNameSelect: function() {
1291                 //project name is required if the checkbox is checked
1292                 $('body').on('change', '#is_gitlab_project', function () {
1293                     if(this.checked) {
1294                         $('#gitlab_project_id').attr('class','required form-control gitlab_project_id');
1295                         $('#gitlab_project_id').prop('disabled', false);
1296                         $('#show_gitlab_project_issues').prop('disabled', false);
1297                         $('#use_gitlab_project_readme').prop('disabled', false);
1298                     } else {
1299                         //$('#gitlab_project_id').disable();
1300                         $('#gitlab_project_id').val([]);
1301                         $('#gitlab_project_id').removeClass('required');
1302                         $('#gitlab_project_id').prop('disabled', true);
1303                         $('#show_gitlab_project_issues').prop('disabled', true);
1304                         $('#use_gitlab_project_readme').prop('disabled', true);
1305                     }
1306                 });
1307               },    
1308 
1309               sortOptionByValue: function(element_id) {
1310                   var my_options = $("#"+element_id + " option");
1311                   var selected = $("#"+element_id).val();
1312 
1313                   my_options.sort(function(a,b) {
1314                       if (a.text > b.text) return 1;
1315                       else if (a.text < b.text) return -1;
1316                       else return 0;
1317                   })
1318                   $("#"+element_id).empty().append( my_options );
1319                   $("#"+element_id).val(selected);
1320               },
1321 
1322 
1323               setupCategoryAjax: function () {
1324                   $('body').on('change', 'div#wrapper_cat_id select.product_select_cat', function () {
1325 
1326                       var cat_id = $(this).val();
1327                       var name_old_elem = $(this).attr('name');
1328                       var name_new_elem = $(this).data('target');
1329                       var level_elem = $(this).data('level') + 1;
1330                       var level_new_elem = level_elem + 1;
1331                       var name_new_target = name_new_elem.substring(0,name_new_elem.length - 1) + level_new_elem;
1332 
1333                       if (!cat_id) {
1334                           $('#wrapper_form_cat input:hidden:first').val($('#wrapper_cat_id').find("[data-level]:lt(" + (level_elem - 1) + ")").val());
1335                           $('#wrapper_cat_id').find("[data-level]:gt(" + (level_elem - 1) + ")").remove();
1336                           $('.cat_source_info').remove();
1337                           return;
1338                       }
1339                       $('#wrapper_form_cat input:hidden:first').val(cat_id);
1340 
1341                       jQuery.ajax({
1342                           data: {'cat_id': cat_id},
1343                           url: '/productcategory/fetchchildren/',
1344                           type: 'post',
1345                           success: function (results) {
1346                               $('#wrapper_cat_id').find("[data-level]:gt(" + (level_elem - 1) + ")").remove();
1347                               $('#' + (level_elem - 1) + '_cat_source_info').remove();
1348                               $('.cat_source_info').remove();
1349                               if (!$.isEmptyObject(results)) {
1350                                   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+'">';
1351                                   new_html_element += '<option value=""> </option>';
1352                                   for (var i in results) {
1353                                       new_html_element += '<option value="' + results[i].project_category_id + '">' + results[i].title + '</option>';
1354                                   }
1355                                   new_html_element += '</select>';
1356 
1357                                   $('#wrapper_cat_id').append(new_html_element);
1358                              } else {
1359                                 var name_elem = name_old_elem;
1360                                 setSourceNeededForCategoryInfo(name_elem, cat_id);
1361                              }
1362                         }
1363                       });
1364                   });
1365               },
1366 
1367               saveSection: function (sectionId) {
1368                   var pid = <?php echo ($this->mode == 'editcollection') ? $this->project_id : '$(\'#project_id\').val()'?>;
1369                   if (pid != '') {
1370                       return;
1371                   }
1372 
1373                   var url = '/c/save/';
1374                   var data = $('#' + sectionId + ' :input').serialize();
1375                   var result = false;
1376 
1377                   jQuery.ajax({
1378                       data: data,
1379                       url: url,
1380                       type: 'post',
1381                       async: false
1382                   }).done(function (data, textStatus, jqXHR) {
1383                       if (data.project_id == undefined) {
1384                           ProductForm.project_id = '';
1385                       } else {
1386                           ProductForm.project_id = data.project_id;
1387                       }
1388                       if (data.status == 'error') {
1389                           ProductForm.errors = data.messages;
1390                           result = false;
1391                       } else {
1392                           result = true;
1393                       }
1394 
1395                   }).fail(function (jqXHR, textStatus, errorThrown) {
1396 
1397                   }).always(function (data, textStatus, errorThrown) {
1398 
1399                   });
1400 
1401                   return result;
1402               },
1403 
1404               showErrors: function () {
1405                   $.each(this.errors, function (index, value) {
1406                       $('[name=' + index + ']').append('<label id="title-error" class="error" for="title">' + value + '</label>');
1407                   });
1408               }
1409 
1410           };
1411 
1412           var ProductGallery = (function () {
1413               var maxImageCount = 5;
1414 
1415               return {
1416 
1417                   setup: function () {
1418                       $('body').on({
1419                           mouseenter: function () {
1420                               $(this).find('.icon-check').hide();
1421                               $(this).find('.icon-cross').show();
1422                           },
1423                           mouseleave: function () {
1424                               $(this).find('.icon-check').show();
1425                               $(this).find('.icon-cross').hide();
1426                           }
1427                       }, '.product-image');
1428 
1429                       if ($('.product-image').length>= 6) {
1430                               $('.upload-image-container').hide();
1431                       }
1432 
1433                       $('body').on('click', '.icon-cross', function () {
1434                           $(this).closest('.product-image').remove();
1435                           ProductGallery.incImageCount();
1436                       });
1437                   },
1438 
1439                   previewImage: function (input) {
1440 
1441                       if (!input.files.length) {
1442                           return;
1443                       }
1444 
1445                       maxImageCount--;
1446 
1447                       var reader = new FileReader();
1448                       var image = new Image();
1449                       var file = input.files[0];
1450 
1451                       reader.readAsDataURL(file);
1452                       reader.onload = function (_image) {
1453 
1454                           $('#gallery-error').remove();
1455 
1456                           $('.product-image').last().append('<div class="absolute icon-check"></div>' +
1457                               '<div class="absolute icon-cross"></div>' +
1458                               '<div class="image" style="background-image: url(' + _image.target.result + ');"></div>'
1459                           );
1460                                    
1461                          $('.product-image').last().after('<div class="product-image relative">' +
1462                               '<input type="file" name="upload_picture[]" class="gallery-picture" onchange="ProductGallery.previewImage(this);"></div>'
1463                              );               
1464                          
1465                           if ($('.product-image').length>= 6) {
1466                                   $('.upload-image-container').hide();
1467                           }
1468                           /*
1469                           if (maxImageCount <= 0) {
1470                               $('.upload-image-container').hide();
1471                           }
1472                           */
1473 
1474                           image.src = _image.target.result;              // url.createObjectURL(file);
1475                           image.onload = function () {
1476                               var w = this.width,
1477                                   h = this.height,
1478                                   t = file.type,                           // ext only: // file.type.split('/')[1],
1479                                   n = file.name,
1480                                   s = ~~(file.size / 5120)// +'KB';
1481                               if (s > 5120) {
1482                                   $('.product-image').last().prev()
1483                                       .find('div.icon-check')
1484                                       .after('<div class="image-error">File too large</div>')
1485                                       .removeClass('icon-check')
1486                                       .addClass('icon-report')
1487                                   ;
1488                                   $('.product-image').last().prev()
1489                                       .find('input.gallery-picture').remove()
1490                                       .append('<input type="file" name="upload_picture[]" class="gallery-picture" onchange="ProductGallery.previewImage(this);"></div>')
1491                                   ;
1492                               }
1493                           };
1494                           ;
1495                           image.onerror = function () {
1496                               $('.product-image').last().prev().find('div.image').append('Invalid file type: ' + file.type);
1497                           };
1498                       }
1499                   },
1500                   thumbClick: function (element) {
1501                       var index = $(element).attr('data-index');
1502                       $('.thumb').removeClass('thumb-active');
1503                       $(element).parent().addClass('thumb-active');
1504                       $('#gallery-carousel').find('.active').removeClass('active');
1505                       $('#gallery-carousel').find('.item[data-index="' + index + '"]').addClass('active');
1506 
1507                   },
1508                   gallerySlide: function () {
1509                       var index = $('#gallery-carousel').find('.active').attr('data-index');
1510                       $('.thumb-active').removeClass('thumb-active');
1511                       $('.thumb a[data-index="' + index + '"]').parent().addClass('thumb-active');
1512                   },
1513                   incImageCount: function () {
1514                       if (maxImageCount < 5) {
1515                           maxImageCount = maxImageCount + 1;
1516                       }
1517                       $('.upload-image-container').show();
1518                   }
1519 
1520               };
1521           })();
1522 
1523   </script>
1524 <?php $this->inlineScript()->appendScript(
1525     '    $(document).ready(function(){
1526             ImagePreview.setup();
1527             ProductForm.setup();
1528             ProductGallery.setup();
1529             Opendownloadfile.setup();
1530         });
1531     ');