File indexing completed on 2025-05-04 05:29:03

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 $catListHelper = new Backend_View_Helper_RealCategory();
0024 $catList = $catListHelper->getList();
0025 
0026 ?>
0027 <link rel="stylesheet" href="//cdn.jsdelivr.net/jquery.validationengine/2.6.4/css/template.css">
0028 <link rel="stylesheet" href="//cdn.jsdelivr.net/jquery.validationengine/2.6.4/css/validationEngine.jquery.css">
0029 <script src="//cdn.jsdelivr.net/jquery.validationengine/2.6.4/js/jquery.validationEngine.min.js"></script>
0030 <script src="//cdn.jsdelivr.net/jquery.validationengine/2.6.4/languages/jquery.validationEngine-en.js"></script>
0031 <style>
0032     .highlight {
0033         background-color: #fefff3;
0034     }
0035 </style>
0036 <div class="messages">
0037     <?php foreach (Zend_Controller_Action_HelperBroker::getStaticHelper('flashMessenger')
0038                        ->getCurrentMessages() as $message) : ?>
0039         <p><?php echo $this->escape($message); ?></p>
0040     <?php endforeach; ?>
0041 
0042     <div class="alert alert-danger alert-dismissible fade in"
0043          role="alert"
0044          style="width: 95%; display: none;">
0045         <button aria-label="Close" class="close" type="button"><span aria-hidden="true">×</span></button>
0046         <div class="alert-body">
0047             <span class='error'>Operation not possible.</span>
0048         </div>
0049     </div>
0050 
0051     <div class="alert alert-success alert-dismissible fade in"
0052          role="alert"
0053          style="width: 95%; display: none;">
0054         <button aria-label="Close" class="close" type="button"><span aria-hidden="true">×</span></button>
0055         <div class="alert-body">
0056             <span class='success'>Operation successfully completed.</span>
0057         </div>
0058     </div>
0059 
0060 </div>
0061 
0062 <div class="filtering">
0063     <form>
0064         <span style="margin-right: 0.9em;">hide deleted records: <input type="checkbox" name="filter_deleted"
0065                                                                         id="filter_deleted" value="1" checked="checked"/></span>
0066         <div style="display:inline-block; text-align: right;width: 95%;">
0067             <button type="submit" id="LoadRecordsButton"><?= $this->translate('Load records'); ?></button>
0068             <button type="reset" id="RemoveFilterButton"><?= $this->translate('Remove filter'); ?></button>
0069         </div>
0070     </form>
0071 </div>
0072 
0073 <div id="TableContainer"></div>
0074 
0075 <div id="dialog-form" title="Create new Subcategory">
0076     <p class="validateTips">All form fields are required.</p>
0077 
0078     <form id="add-subcat-form" class="jtable-dialog-form jtable-create-form">
0079         <div class="jtable-input-field-container">
0080             <div class="jtable-input-label">Title</div>
0081             <div class="jtable-input jtable-textarea-input">
0082                 <input class="validate[required]" id="subcat-title" name="title"/>
0083             </div>
0084         </div>
0085         
0086         <div class="jtable-input-field-container">
0087             <div class="jtable-input-label">Real Cat Id</div>
0088             <div class="jtable-input jtable-textarea-input">
0089                 <select id="subcat-project_category_id" name="project_category_id">
0090                     <?php 
0091                         foreach ($catList as $value) {
0092                             echo('<option value="' . $value['Value'] . '">'. $value['DisplayText'] . '</option>');
0093                         }
0094                     ?>
0095                 </select>
0096             </div>
0097         </div>
0098     </form>
0099 </div>
0100 
0101 <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
0102 <script type="text/javascript">
0103     $(document).ready(function () {
0104 
0105         // Prevent jQuery UI dialog from blocking focusin
0106         $(document).on('focusin', function(e) {
0107             if ($(e.target).closest(".mce-window, .moxman-window").length) {
0108                 e.stopImmediatePropagation();
0109             }
0110         });
0111 
0112         tinymce.init({
0113             selector: "#text-cat-about",
0114             width: '100%',
0115             height: 400,
0116             autoresize_min_height: 400,
0117             autoresize_max_height: 600,
0118             menubar: false,
0119             plugins: [
0120                 'autoresize advlist autolink lists link image charmap print preview anchor textcolor',
0121                 'searchreplace visualblocks code fullscreen',
0122                 'insertdatetime media table contextmenu paste code help wordcount'
0123             ],
0124             toolbar: 'insert | undo redo |  formatselect | bold italic backcolor  | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help',
0125             content_css: [
0126                 '//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
0127                 '//www.tinymce.com/css/codepen.min.css']
0128         });
0129 
0130         $('.alert .close').on('click', function (e) {
0131             $(this).parent().hide();
0132         });
0133 
0134         var title = $("#subcat-title"),
0135             allFields = $([]).add(title),
0136             tips = $(".validateTips");
0137 
0138         $("#dialog-form").dialog({
0139             autoOpen: false,
0140             //height: 350,
0141             width: 350,
0142             modal: true,
0143             open: function (event, ui) {
0144                 $("#add-subcat-form").validationEngine('attach');
0145             },
0146             buttons: {
0147                 Cancel: function () {
0148                     $(this).dialog("close");
0149                 },
0150                 Save: function () {
0151                     if (false == $("#add-subcat-form").validationEngine('validate')) {
0152                         return;
0153                     }
0154 
0155                     sendPostId = $(this).data('record').v_category_id;
0156 
0157                     $('#TableContainer').jtable('addRecord', {
0158                         record: {
0159                             "title": $("#subcat-title").val(),
0160                             "project_category_id": $("#subcat-project_category_id").val(),
0161                             "v_category_id": sendPostId,
0162                             "v_parent_id": $(this).data('record').v_parent_id
0163                         }
0164                     });
0165                     $(this).dialog("close");
0166                 }
0167             },
0168             close: function () {
0169                 allFields.val("").removeClass("ui-state-error");
0170                 $("#add-subcat-form").validationEngine('hide');
0171                 $("#add-subcat-form").validationEngine('detach');
0172             }
0173         });
0174 
0175         $('body').on("submit", '#add-subcat-form', function (event) {
0176             event.preventDefault();
0177             event.stopImmediatePropagation();
0178 
0179             jQuery.ajax({
0180                 data: $(this).serialize(),
0181                 url: this.action,
0182                 type: this.method,
0183                 error: function (jqXHR, textStatus, errorThrown) {
0184                     $(".alert-danger .alert-body").empty().html('<span class="error">Operation not possible.</span>');
0185                     $(".alert-danger").alert().fadeIn('slow');
0186                     return false;
0187                 },
0188                 success: function (data, textStatus, jqXHR) {
0189                     return false;
0190                 }
0191             });
0192 
0193             return false;
0194         });
0195 
0196         $('body').on("click", 'button.move-category', function (event) {
0197             event.preventDefault();
0198             event.stopImmediatePropagation();
0199 
0200             var direction = $(this).attr("data-direction");
0201             var elementRecord = $(this).data("record");
0202 
0203             jQuery.ajax({
0204                 data: {'direction': direction, 'record': elementRecord},
0205                 url: '/backend/vcategories/moveelement/',
0206                 type: 'post',
0207                 error: function (jqXHR, textStatus, errorThrown) {
0208                     $(".alert-danger .alert-body").empty().html('<span class="error">Operation not possible.</span>');
0209                     $(".alert-danger").alert().fadeIn('slow');
0210                     return false;
0211                 },
0212                 success: function (data, textStatus, jqXHR) {
0213                     $('#TableContainer').jtable('reload');
0214                     return false;
0215                 },
0216                 complete: function (data, textStatus, errorThrown) {
0217                     return false;
0218                 }
0219             });
0220 
0221             return false;
0222         });
0223 
0224         $('#TableContainer').jtable({
0225             jqueryuiTheme: true,
0226             paging: true,
0227             title: 'Table of Categories',
0228             actions: {
0229                 listAction: '/backend/vcategories/list',
0230                 createAction: '/backend/vcategories/create',
0231                 updateAction: '/backend/vcategories/update',
0232                 updateAction: function (postData) {
0233 //                console.log("updating from custom function...");
0234                     return $.Deferred(function ($dfd) {
0235                         $.ajax({
0236                             url: '/backend/vcategories/update',
0237                             type: 'POST',
0238                             dataType: 'json',
0239                             data: postData,
0240                             success: function (data) {
0241                                 $dfd.resolve(data);
0242                                 $('#TableContainer').jtable('reload');
0243                             },
0244                             error: function () {
0245                                 $dfd.reject();
0246                             }
0247                         });
0248                     });
0249                 }
0250                 //,deleteAction: '/backend/vcategories/delete'
0251             },
0252             fields: {
0253                 v_parent_id_show: {
0254                     title: 'V Parent Cat ID',
0255                     key: true,
0256                     create: false,
0257                     edit: false,
0258                     list: true,
0259                     width: '2%'
0260                 },
0261                 v_parent_id: {
0262                     title: 'V Parent Cat ID',
0263                     key: true,
0264                     create: false,
0265                     edit: false,
0266                     list: false,
0267                     width: '1%',
0268                     options: function (data) {
0269                         data.clearCache();
0270                         if (data.source == 'edit') {
0271                             return '/backend/vcategories/tree?c=' + data.record.v_parent_id;
0272                         }
0273                         return '/backend/vcategories/tree?c=0';
0274                     }
0275                 },
0276                 v_category_id: {
0277                     title: 'V Cat ID',
0278                     key: true,
0279                     create: false,
0280                     edit: false,
0281                     width: '2%'
0282                 },
0283                 title_show: {
0284                     title: 'Virtual Title',
0285                     create: false,
0286                     edit: false,
0287                     list: true,
0288                     width: '10%'
0289                 },
0290                 title: {
0291                     title: 'Virtual Title',
0292                     create: true,
0293                     edit: true,
0294                     list: false
0295                 },
0296                 title_real: {
0297                     title: 'Real Title',
0298                     create: false,
0299                     edit: false,
0300                     list: true
0301                 },
0302                 project_category_id_show: {
0303                     title: 'Real Cat ID',
0304                     create: false,
0305                     edit: false,
0306                     list: true,
0307                     width: '2%'
0308                 },
0309                 project_category_id: {
0310                     title: 'Real Cat ID',
0311                     create: true,
0312                     edit: true,
0313                     list: false,
0314                     width: '1%',
0315                     options: function (data) {
0316                         data.clearCache();
0317                         if (data.source == 'edit') {
0318                             return '/backend/vcategories/treereal?c=' + data.record.project_category_id;
0319                         }
0320                         return '/backend/vcategories/treereal?c=0';
0321                     }
0322                 },
0323                 created_at: {
0324                     title: 'Created',
0325                     width: '10%',
0326                     type: 'date',
0327                     create: false,
0328                     edit: false,
0329                     list: false
0330                 },
0331                 changed_at: {
0332                     title: 'Changed',
0333                     width: '10%',
0334                     type: 'date',
0335                     create: false,
0336                     edit: false,
0337                     list: false
0338                 },
0339                 addSubCat: {
0340                     title: '',
0341                     width: '1%',
0342                     sorting: false,
0343                     create: false,
0344                     edit: false,
0345                     list: true,
0346                     display: function (data) {
0347                         if (data.record) {
0348                             return '<button title="Add Subcategory" class="jtable-command-button" style="  width: 15px;height: 15px;background: url(/theme/flatui/img/icon-plus.png);" onclick="$( \'#dialog-form\' ).data(\'record\',{v_category_id: ' + data.record.v_category_id + '}).dialog( \'open\' );"><span>add subcat</span></button>';
0349                         }
0350                     }
0351                 }
0352             },
0353 
0354             //Initialize validation logic when a form is created
0355             formCreated: function (event, data) {
0356                 data.form.validationEngine();
0357                 $('#jtable-create-form').attr('style', 'padding:5%');
0358             },
0359             //Validate form when it is being submitted
0360             formSubmitting: function (event, data) {
0361                 return data.form.validationEngine('validate');
0362             },
0363             //Dispose validation logic when form is closed
0364             formClosed: function (event, data) {
0365                 data.form.validationEngine('hide');
0366                 data.form.validationEngine('detach');
0367             },
0368             recordsLoaded: function () {
0369                 $(".jtable").attr('style', 'position:inherit;'); // corrects the position for dragged element.
0370                 $(".jtable tbody").sortable({
0371                     cursor: 'move',
0372                     opacity: 0.9,
0373                     axis: 'y',
0374                     containment: 'parent',
0375                     start: function (event, ui) {
0376                         ui.item.startPos = ui.item.index() + 1;
0377                         ui.item.lft = $('.jtable tbody tr:nth-child(' + (ui.item.startPos) + ') td:nth-child(2)').text();
0378                         ui.item.rgt = $('.jtable tbody tr:nth-child(' + (ui.item.startPos) + ') td:nth-child(3)').text();
0379                     },
0380                     stop: function (event, ui) {
0381                         lft = $('.jtable tbody tr:nth-child(' + (ui.item.index() + 2) + ') td:nth-child(2)').text();
0382                         rgt = $('.jtable tbody tr:nth-child(' + (ui.item.index() + 2) + ') td:nth-child(3)').text();
0383                         newPosition = ui.item.lft;
0384                         if (parseInt(lft) > 0) {
0385                             newPosition = parseInt(lft);
0386                         }
0387 
0388                         jQuery.ajax({
0389                             data: {'data': {'lft': ui.item.lft, 'rgt': ui.item.rgt}, 'newPosition': newPosition},
0390                             url: '/backend/vcategories/dragdrop/',
0391                             type: 'post',
0392                             error: function (jqXHR, textStatus, errorThrown) {
0393                                 $(".alert").alert().fadeIn('slow');
0394                                 return false;
0395                             },
0396                             success: function (data, textStatus, jqXHR) {
0397                                 $('#TableContainer').jtable('reload');
0398                                 return false;
0399                             }
0400                         });
0401 
0402                     }
0403 
0404                 }).disableSelection();
0405                 $('tr.jtable-data-row').hover(function () {
0406                     $(this).addClass('highlight');
0407                 }, function () {
0408                     $(this).removeClass('highlight');
0409                 });
0410 
0411             }
0412         });
0413 
0414         $('#TableContainer').jtable('load', {
0415             filter_deleted: $('#filter_deleted').is(':checked') ? $('#filter_deleted').val() : 0
0416         });
0417 
0418         //Re-load records when user click 'load records' button.
0419         $('#LoadRecordsButton').click(function (e) {
0420             e.preventDefault();
0421             $('#TableContainer').jtable('load', {
0422                 filter_deleted: $('#filter_deleted').is(':checked') ? $('#filter_deleted').val() : 0
0423             });
0424         });
0425 
0426         //Re-load records when user click 'remove filter' button.
0427         $('#RemoveFilterButton').click(function (e) {
0428             e.preventDefault();
0429             $('#TableContainer').jtable('load', {
0430                 filter_deleted: 0,
0431             });
0432         });
0433 
0434     });
0435 </script>