diff options
-rw-r--r-- | modules-available/news/config.json | 3 | ||||
-rw-r--r-- | modules-available/news/page.inc.php | 35 | ||||
-rw-r--r-- | modules-available/news/templates/page-news.html | 41 |
3 files changed, 60 insertions, 19 deletions
diff --git a/modules-available/news/config.json b/modules-available/news/config.json index 23cd1443..2e090c1c 100644 --- a/modules-available/news/config.json +++ b/modules-available/news/config.json @@ -1,6 +1,7 @@ { "category": "main.content", "dependencies": [ - "js_stupidtable" + "js_stupidtable", + "bootstrap_datepicker" ] }
\ No newline at end of file diff --git a/modules-available/news/page.inc.php b/modules-available/news/page.inc.php index 8e2b4e7e..7a09d437 100644 --- a/modules-available/news/page.inc.php +++ b/modules-available/news/page.inc.php @@ -121,24 +121,24 @@ class Page_News extends Page $lines = array(); $res = Database::simpleQuery("SELECT newsid, dateline, expires, title, content FROM vmchooser_pages WHERE type = :type ORDER BY dateline DESC LIMIT 20", ['type' => $this->pageType]); + $foundActive = false; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $row['dateline_s'] = Util::prettyTime($row['dateline']); $row['expires_s'] = $this->formatExpires($row['expires']); + if ($row['newsid'] == $this->newsId) { + $row['active'] = true; + } if ($row['expires'] < $NOW) { $row['muted'] = 'text-muted'; + } elseif (!$foundActive) { + $row['live'] = 'active'; + $foundActive = true; } - if ($row['newsid'] == $this->newsId) { - $row['active'] = 'active'; - } $row['content'] = substr(strip_tags(str_replace('>', '> ', $row['content'])), 0, 160); $lines[] = $row; } - $validity = ceil(($this->newsExpires - $NOW) / 3600); - if ($this->newsExpires === false || $validity > 24 * 365 * 5) { - $validity = ''; - } $data = array( 'withTitle' => self::TYPES[$this->pageType]['headline'], 'newsTypeName' => Dictionary::translate('type_' . $this->pageType, true), @@ -147,10 +147,16 @@ class Page_News extends Page 'currentContent' => $this->newsContent, 'currentTitle' => $this->newsTitle, 'type' => $this->pageType, - 'validity' => $validity, 'list' => $lines, 'hasSummernote' => $this->hasSummernote, ); + $validity = ceil(($this->newsExpires - $NOW) / 3600); + if ($this->newsExpires === false || $validity > 24 * 365 * 5) { + $data['infinite_checked'] = 'checked'; + $this->newsExpires = strtotime('+7 days 00:00:00'); + } + $data['enddate'] = date('Y-m-d', $this->newsExpires); + $data['endtime'] = date('H:i', $this->newsExpires); if (!User::hasPermission($this->pageType . '.save')) { $data['save'] = [ 'readonly' => 'readonly', @@ -221,11 +227,12 @@ class Page_News extends Page // check if news content were set by the user $newsTitle = Request::post('news-title', '', 'string'); $newsContent = Request::post('news-content', false, 'string'); - $validity = Request::post('validity', false, 'string'); - if ($validity === false || $validity === '') { - $validity = 86400 * 3650; // 10 Years + $infinite = (Request::post('infinite', '', 'string') !== ''); + if ($infinite) { + $expires = strtotime('+10 years 0:00'); } else { - $validity *= 3600; // Hours to seconds + $expires = strtotime(Request::post('enddate', 'today', 'string') . ' ' + . Request::post('endtime', '23:59', 'string')); } if (!empty($newsContent)) { // we got title and content, save it to DB @@ -240,7 +247,7 @@ class Page_News extends Page WHERE newsid = :newsid LIMIT 1', [ 'newsid' => $row['newsid'], 'dateline' => time(), - 'expires' => time() + $validity, + 'expires' => $expires, 'title' => $newsTitle, ]); return true; @@ -249,7 +256,7 @@ class Page_News extends Page Database::exec("INSERT INTO vmchooser_pages (dateline, expires, title, content, type) VALUES (:dateline, :expires, :title, :content, :type)", array( 'dateline' => time(), - 'expires' => time() + $validity, + 'expires' => $expires, 'title' => $newsTitle, 'content' => $newsContent, 'type' => $pageType, diff --git a/modules-available/news/templates/page-news.html b/modules-available/news/templates/page-news.html index 0543a414..1c944cb8 100644 --- a/modules-available/news/templates/page-news.html +++ b/modules-available/news/templates/page-news.html @@ -14,9 +14,30 @@ <input type="text" name="news-title" id ="news-title-id" class="form-control" placeholder="{{lang_titlePh}}" value="{{currentTitle}}" {{save.readonly}}> </div> {{/withTitle}} - <div class="form-group"> - <label for="validity">{{lang_validityHours}}</label> ({{lang_leaveEmptyInfinite}}) - <input id="validity" type="text" name="validity" value="{{validity}}" class="form-control"> + <div class="form-group row"> + <div class="col-md-12"> + <label for="enddate">{{lang_expiryDate}}</label> + <div class="checkbox"> + <input id="infinite-checkbox" type="checkbox" name="infinite" {{infinite_checked}}> + <label for="infinite-checkbox">{{lang_infiniteDuration}}</label> + </div> + </div> + <div class="col-md-3 col-sm-6"> + <div class="input-group"> + <span class="input-group-addon"> + <span class="glyphicon glyphicon-calendar"></span> + </span> + <input id="enddate" type="text" name="enddate" value="{{enddate}}" class="form-control datepicker" {{save.readonly}}> + </div> + </div> + <div class="col-md-3 col-sm-6"> + <div class="input-group bootstrap-timepicker timepicker"> + <span class="input-group-addon"> + <span class="glyphicon glyphicon-time"></span> + </span> + <input id="endtime" type="time" name="endtime" value="{{endtime}}" class="form-control timepicker2" {{save.readonly}} pattern="[0-9]{1,2}:[0-9]{2}"> + </div> + </div> </div> <div class="form-group"> <label for="news-content-id">{{lang_content}}</label> @@ -49,6 +70,7 @@ <table class="table table-condensed stupidtable"> <thead> <tr> + <th></th> <th class="text-nowrap slx-smallcol" data-sort="int">{{lang_created}}</th> <th class="text-nowrap slx-smallcol" data-sort="int">{{lang_expires}}</th> <th class="text-nowrap" data-sort="string">{{lang_title}}</th> @@ -59,7 +81,8 @@ </thead> <tbody> {{#list}} - <tr class="{{active}} {{muted}}"> + <tr class="{{live}} {{muted}}"> + <td>{{#active}}<span class="glyphicon glyphicon-eye-open"></span>{{/active}}</td> <td class="text-left text-nowrap" data-sort-value={{dateline}}>{{dateline_s}}</td> <td class="text-left text-nowrap" data-sort-value={{expires}}>{{expires_s}}</td> <td><table class="slx-ellipsis"><tr><td>{{title}}</td></tr></table></td> @@ -96,5 +119,15 @@ document.addEventListener("DOMContentLoaded", function () { {{#hasSummernote}} $('.summernote[readonly]').each(function() { $(this).summernote('disable'); }); {{/hasSummernote}} + var dateSettings = { + format: 'yyyy-mm-dd', + todayHighlight: true, + }; + $('.datepicker').datepicker(dateSettings); + var chf = function() { + $('#enddate, #endtime').prop('disabled', $('#infinite-checkbox').is(':checked')); + }; + $('#infinite-checkbox').change(chf); + chf(); }, false); // --></script>
\ No newline at end of file |