1
Diff [61a8e523876209ca1c3ec5fe73d84631f13210dd:5f22008fa0679fa1385ef77603d81f7b7923fb7a] for / – MultiMag

Changes in / [61a8e52:5f22008]


Ignore:
Files:
7 added
6 edited

Legend:

Unmodified
Added
Removed
  • web/core.php

    r61a8e52 r5f22008  
    192192        if(isset($_REQUEST[$varname]))  return $_REQUEST[$varname];
    193193        return $def;
     194}
     195
     196/// Проверяет был ли получен запрос через ajax
     197/// @return boolean
     198function isAjaxRequest()
     199{
     200        return isset($_SERVER['HTTP_X_REQUESTED_WITH'])
     201                && !empty($_SERVER['HTTP_X_REQUESTED_WITH'])
     202                && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
    194203}
    195204
  • web/css/comm.js

    r61a8e52 r5f22008  
    379379    httpRequest.onreadystatechange = function() { popupReqWin(httpRequest,popup); };
    380380    httpRequest.open('GET', url, true);
     381        httpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
    381382    httpRequest.send(null);
    382383    return false;
     
    405406                //popup.innerHTML="Обработка...";
    406407        }
    407         else popup.innerHTML="state "+httpRequest.readyState;
    408408}
    409409
  • web/include/models/ldo/doclist.php

    r61a8e52 r5f22008  
    8888        }
    8989        return $filter;
     90    }
     91
     92
     93        /**
     94         * Сформировать order из запроса
     95         * @return string
     96         */
     97        protected function getOrder()
     98        {
     99                $orderFields = [
     100                        'sum' => '`doc_list`.`sum`',
     101                        'date' => '`doc_list`.`date`',
     102                        'asc' => 'ASC',
     103                        'desc' => 'DESC'
     104                ];
     105                if(!empty($this->options['order'])) {
     106                        foreach (json_decode($this->options['order'], true) as $item) {
     107                                if(!empty($orderFields[$item['field']]) && !empty($orderFields[$item['order']])) {
     108                                        $orders[] = $orderFields[$item['field']] . ' ' . $orderFields[$item['order']];
     109                                }
     110                        }
     111                }
     112                if(!empty($orders)) {
     113                        return 'ORDER BY '.implode(', ', $orders);
     114                }
     115                return 'ORDER by `doc_list`.`date` DESC';
    90116    }
    91117
     
    203229            $sql_join
    204230            WHERE 1 $sql_filter
    205             ORDER by `doc_list`.`date` DESC
     231            {$this->getOrder()}
    206232            LIMIT $start,{$this->limit}";
    207233        $result = array();
  • web/js/doc_journal.js

    r61a8e52 r5f22008  
    132132    var httpRequest = new XMLHttpRequest();
    133133
     134    let sortableFields = [];
     135    let fieldsWithCnt = [
     136        {
     137            attributes: {
     138                width: 55
     139            },
     140            html: 'a.№'
     141        },
     142            {
     143                    attributes: {
     144                            width: 20
     145                    },
     146                    html: ''
     147            },
     148            {
     149                    attributes: {
     150                            width: 20
     151                    },
     152                    html: ''
     153            },
     154            {
     155                    html: 'Тип'
     156            },
     157            {
     158                    html: 'Участник 1'
     159            },
     160            {
     161                    html: 'Участник 2'
     162            },
     163            {
     164                    html: 'Кол-во'
     165            },
     166            {
     167                    html: 'Цена'
     168            },
     169            {
     170                    attributes: {
     171                        class: 'js-order-filter'
     172                    },
     173            field: 'sum',
     174            order: 'asc',
     175                    html: 'Сумма'
     176            },
     177            {
     178                    attributes: {
     179                            class: 'js-order-filter'
     180                    },
     181                    field: 'date',
     182                    order: 'asc',
     183                    html: 'Дата'
     184            },
     185            {
     186                    html: 'Автор'
     187            },
     188            {
     189                    html: 'id'
     190            },
     191    ];
     192
     193        let fields = [
     194                {
     195                        attributes: {
     196                                width: 55
     197                        },
     198                        html: 'a.№'
     199                },
     200                {
     201                        attributes: {
     202                                width: 20
     203                        },
     204                        html: ''
     205                },
     206                {
     207                        attributes: {
     208                                width: 20
     209                        },
     210                        html: ''
     211                },
     212                {
     213                        html: 'Тип'
     214                },
     215                {
     216                        html: 'Участник 1'
     217                },
     218                {
     219                        html: 'Участник 2'
     220                },
     221                {
     222                        attributes: {
     223                                class: 'js-order-filter'
     224                        },
     225                        field: 'sum',
     226                        order: 'asc',
     227                        html: 'Сумма'
     228                },
     229                {
     230                        attributes: {
     231                                class: 'js-order-filter'
     232                        },
     233                        field: 'date',
     234                        order: 'asc',
     235                        html: 'Дата'
     236                },
     237                {
     238                        html: 'Автор'
     239                },
     240                {
     241                        html: 'id'
     242                },
     243        ];
     244
     245
    134246    var deffer_timer;
    135247    var docj_list_body = document.getElementById('docj_list_body');
     
    218330        if (okfilter_id.value != '0')
    219331            filter_request += '&doclist[ok]=' + encodeURIComponent(okfilter_id.value);
     332
     333        if(sortableFields) {
     334            let orderQuery = [];
     335            sortableFields.forEach(function(item){
     336               if(item.hasOwnProperty('order') && item.hasOwnProperty('field')) {
     337                   orderQuery.push({
     338                       'field': item.field,
     339                       'order': item.order
     340                   });
     341               }
     342            });
     343                filter_request += '&doclist[order]=' + encodeURIComponent(JSON.stringify(orderQuery));
     344        }
    220345    }
    221346
     
    558683    }
    559684
     685    function buldHeaderFields(data) {
     686        let tr = document.createElement("tr");
     687        data.forEach(function (item, i) {
     688                let th = document.createElement("th");
     689                th.innerText = item.html;
     690                if(item.hasOwnProperty('attributes')) {
     691                    if(item.attributes.hasOwnProperty('class')){
     692                            th.classList = item.attributes.class ? item.attributes.class : '';
     693                }
     694            }
     695                if(item.hasOwnProperty('order')) {
     696                        th.style = 'background: url(/img/i_orderarrows.png) 100% '
     697                    +(item.order === 'asc' ? '' : '10')
     698                    +'0% no-repeat transparent; background-color: #6488DC; cursor: pointer';
     699                }
     700                if(item.hasOwnProperty('field')) {
     701                        th.dataset.field = item.field;
     702                }
     703                th.dataset.fieldId = i;
     704                tr.appendChild(th);
     705        });
     706            return tr.innerHTML;
     707    }
     708
     709
    560710    function initTableHead() {
    561711        var head = document.getElementById('doc_list_head');
    562712        if (show_count_column) {
    563             head.innerHTML = "<tr><th width='55'>a.№</th><th width='20'>&nbsp;</th><th width='20'>&nbsp;</th><th>Тип</th><th>Участник 1</th><th>Участник 2</th><th>Кол-во</th><th>Цена</th><th>Сумма</th><th>Дата</th><th>Автор</th><th width='45'>id</th></tr>";
     713            head.innerHTML = buldHeaderFields(fieldsWithCnt);
    564714        }
    565715        else {
    566             head.innerHTML = "<tr><th width='55'>a.№</th><th width='20'>&nbsp;</th><th width='20'>&nbsp;</th><th>Тип</th><th>Участник 1</th><th>Участник 2</th><th>Сумма</th><th>Дата</th><th>Автор</th><th width='45'>id</th></tr>";
    567         }
     716            head.innerHTML = buldHeaderFields(fields);
     717        }
     718            let orderFilter = function(e) {
     719            let data = show_count_column ? fieldsWithCnt : fields;
     720            let self = this;
     721                    sortableFields = sortableFields.filter(function(val){
     722                            return val.field !== data[self.dataset.fieldId].field;
     723                    });
     724                    sortableFields.unshift({
     725                            field: data[this.dataset.fieldId].field,
     726                            order: data[this.dataset.fieldId].order === 'asc' ? 'desc' : 'asc',
     727            });
     728                    data[this.dataset.fieldId].order = data[this.dataset.fieldId].order === 'asc' ? 'desc' : 'asc';
     729                    beginDefferedRequest();
     730            };
     731            document.querySelectorAll("th.js-order-filter").forEach(box => { box.addEventListener('click', orderFilter, false); });
    568732    }
    569733
  • web/skins/default/basic.css

    r61a8e52 r5f22008  
    193193div.notify
    194194{
    195     width: 97%;
    196195    BORDER: #999900 1px solid;
    197196    FONT-SIZE: 14px;
  • web/vitrina.php

    r61a8e52 r5f22008  
    194194                }
    195195            } else {
    196                 if (getenv("HTTP_REFERER")) {
    197                     redirect(getenv("HTTP_REFERER"));
    198                 }
    199                 $tmpl->msg("Товар добавлен в корзину!", "info", "<a class='urllink' href='/vitrina.php?mode=basket'>Ваша корзина</a>");
     196                    if(isAjaxRequest()) {
     197                            $tmpl->msg("Товар добавлен в корзину!", "info", "<a class='urllink' href='/vitrina.php?mode=basket'>Ваша корзина</a>");
     198                    } else {
     199                            if (getenv("HTTP_REFERER")) {
     200                                    redirect(getenv("HTTP_REFERER"));
     201                            }
     202                    }
    200203            }
    201204        } else {
Note: See TracChangeset for help on using the changeset viewer.