<?php
/**
 * The search view file of my module of ZDOO.
 *
 * @copyright   Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     商业软件，非开源软件
 * @author      Gang Liu <liugang@cnezsoft.com>
 * @package     my 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<style>
#mainNavbar{z-index: 1001;}

#searchModal {top: 1px; right: 0px; width: 40%; display:none; position: fixed; z-index: 1050; background-color: rgb(255,255,255);}
#searchModal .panel .panel-body {overflow: scroll; padding: 10px;}
#searchModal .panel .panel-body .closeBtn {position: relative; right: 10px;}
#searchModal .panel .panel-footer .pager {margin: 0 10px 0 0;}
#searchModal .input-group .input-group-addon.fix-width {width: 0px;}
#searchModal .input-group #module {min-width: 80px; border-left-width: 0px; border-right-width: 0px;}
#searchModal .searchGroup{width: 60%; margin: 10px auto;}
#searchModal .execute-info{position:relative; }

#searchModal .list {color: #333; background-color: transparent; border-top: solid #DDD 1px; border-radius: 3px;}
#searchModal .list-condensed > .items > .item {padding: 10px 15px; border-bottom: 1px solid #e5e5e5; transition: all .5s cubic-bezier(.175,.885,.32,1);}
#searchModal .items {overflow-y: scroll;}
#searchModal .items .item .text-muted{color: #757575;}
#searchModal .items .item-heading h4{margin-top: 5px; font-size:14px; line-height:1.5; font-weight:normal}
#searchModal .item:hover{background-color:#f5f5f5}

#searchModal .table-footer .pager {margin-right: 20px;}
#searchModal .table-footer .pager span {margin-right: 10px;}
</style>

<div class='panel'>
  <div class='panel-body'>
    <div class='closeBtn'>
      <button type="button" class="close" aria-hidden="true">×</button>
    </div>
    <div class='input-group searchGroup'>
      <?php echo html::input('words', $words, "class='form-control'")?>
      <span class='input-group-addon fix-border fix-padding fix-width'></span>
      <?php echo html::select('module', $lang->searchObjects, $module, "class='form-control'");?>
      <span class='input-group-btn'><?php echo html::a('#', $lang->search->common, "class='btn btn-primary searchBtn'");?></span>
    </div>
    <div class='list list-condensed'>
      <section class='items items-hover'>
        <?php foreach($results as $object):?>
        <?php $misc = strpos(',todo,effort,', ",$object->objectType,") !== false ? "data-toggle='modal'" : '';?>
        <div class='item text-left'>
          <div class='item-heading'>
            <h4>
              <?php
              echo html::a($object->url, $object->title, "$misc title='" . strip_tags($object->title) . "'");
              echo "<small class=''>[{$lang->searchObjects[$object->objectType]} #{$object->objectID}]</small> ";
              ?>
            </h4>
          </div>
          <div class='item-content'>
            <div class='text text-muted pull-left'><?php echo $object->summary;?></div>
          </div>
        </div>
        <?php endforeach;?>
      </section>
    </div>
  </div>
  <div class='table-footer'>
    <div class='table-statistic'>
      <span><?php printf($lang->search->executeInfo, $pager->recTotal, $consumed);?></span> 
    </div>
    <?php if($results):?>
    <div style="float:right; clear:none;" class="pager form-inline">
      <?php
      $words = helper::safe64Encode(helper::jsonEncode($words));
      if($pager->pageID == 1) echo '<span>' . $this->lang->pager->pre . '</span>';
      if($pager->pageID >  1) echo '<span>' . html::a(inlink('search', "recTotal=$pager->recTotal&pageID=" . ($pager->pageID - 1) . "&words=$words"), $this->lang->pager->pre) . '</span>';
      if($pager->pageID == $pager->pageTotal) echo '<span>' . $this->lang->pager->next . '</span>';
      if($pager->pageID <  $pager->pageTotal) echo '<span>' . html::a(inlink('search', "recTotal=$pager->recTotal&pageID=" . ($pager->pageID + 1) . "&words=$words"), $this->lang->pager->next) . '</span>';
      ?>
    </div>
    <?php endif;?>
  </div>
</div>
<script>
$(function()
{
    $('.panel .closeBtn button').click(function(){$('#searchModal').hide();});

    $('.panel .panel-body .searchBtn').click(function()
    {
        var words  = $(this).parents('.input-group').find('#words').val();
        var module = $(this).parents('.input-group').find('#module').val();
            words  = $.trim(words);

        if(!words) return false;

        var link = createLink('sys.my', 'search') + (config.requestType == 'GET' ? '&' : '?') + 'words=' + window.btoa(encodeURI(words)) + '&module=' + module;
        $('#searchModal').load(link, function(){fixSearchPanel();});
        return false;
    });

    $('.panel .table-footer .pager a').click(function()
    {
        $('#searchModal').load($(this).prop('href'), function(){fixSearchPanel();});
        return false;        
    });

    $('.list .item a').click(function()
    {
        var href = $(this).prop('href');
        if($(this).data('toggle') == 'modal')
        {
            $.zui.modalTrigger.show({width: '70%', url: href, backdrop: 'static'});
            return false;
        }

        var app  = '';
        if(href.indexOf('/crm/') != -1)   app = 'crm';
        if(href.indexOf('/proj/') != -1)  app = 'proj';
        if(href.indexOf('/doc/') != -1)   app = 'doc';
        if(href.indexOf('/oa/') != -1)    app = 'oa';
        if(href.indexOf('/cash/') != -1)  app = 'cash';
        if(href.indexOf('/team/') != -1)  app = 'team';
        if(href.indexOf('/sys/') != -1)   app = 'superadmin';
        if(href.indexOf('/sys/my') != -1 || href.indexOf('/sys/index.php?' + config.moduleVar + '=my&' + config.methodVar) != -1) app = 'dashboard';
        if(href.indexOf('/sys/todo') != -1 || href.indexOf('/sys/index.php?' + config.moduleVar + '=todo&' + config.methodVar) != -1) app = 'dashboard';
        if(href.indexOf('/sys/effort') != -1 || href.indexOf('/sys/index.php?' + config.moduleVar + '=effort&' + config.methodVar) != -1) app = 'dashboard';

        if(app != '')
        {
            $.openEntry(app, href);
            return false;
        }
    });
});
