Skip to content

Commit

Permalink
Announcements : Fix pin announcements, recipients selection (select2())
Browse files Browse the repository at this point in the history
  • Loading branch information
jexi committed Mar 23, 2018
1 parent 187151b commit d542aac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
37 changes: 20 additions & 17 deletions modules/announcements/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
$public_code = course_id_to_public_code($course_id);
$toolName = $langAnnouncements;

define_rss_link();

// STICKY ANNOUNCEMENT
if ($is_editor && isset($_POST['pin_announce'])) {
if (isset($_GET['pin']) && ($_GET['pin'] == 1)) {
$top_order = Database::get()->querySingle("SELECT MAX(`order`) as max from announcement WHERE course_id = ?d", $course_id)->max + 1;
Database::get()->query("UPDATE announcement SET `order` = ?d where id = ?d and course_id = ?d", $top_order, $_GET['pin_an_id'], $course_id);
} elseif (isset($_GET['pin']) && ($_GET['pin'] == 0)) {
Database::get()->query("UPDATE announcement SET `order` = 0 where id = ?d and course_id = ?d", $_GET['pin_an_id'], $course_id);
}
exit();
}

// Identifying ajax request
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
if (isset($_POST['action']) && $is_editor) {
Expand Down Expand Up @@ -184,18 +197,7 @@
exit();
}

// STICKY ANNOUNCEMENT
if ($is_editor && isset($_POST['pin_announce'])) {
if (isset($_GET['pin']) && ($_GET['pin'] == 1)) {
$top_order = Database::get()->querySingle("SELECT MAX(`order`) as max from announcement WHERE course_id = ?d", $course_id)->max + 1;
Database::get()->query("UPDATE announcement SET `order` = ?d where id = ?d and course_id = ?d", $top_order, $_GET['pin_an_id'], $course_id);
} elseif (isset($_GET['pin']) && ($_GET['pin'] == 0)) {
Database::get()->query("UPDATE announcement SET `order` = 0 where id = ?d and course_id = ?d", $_GET['pin_an_id'], $course_id);
}
exit();
}

define_rss_link();
ModalBoxHelper::loadModalBox();
add_units_navigation(TRUE);

Expand Down Expand Up @@ -262,12 +264,12 @@
if ($is_editor) {
$head_content .= "<script type='text/javascript'>
$(document).ready(function () {
var langEmptyGroupName = \"' . $langEmptyAnTitle . '\";
$('input[name=startdate_active]').prop('checked') ? $('input[name=startdate_active]').parents('.input-group').children('input').prop('disabled', false) : $('input[type=checkbox]').eq(0).parents('.input-group').children('input').prop('disabled', true);
$('input[name=enddate_active]').prop('checked') ? $('input[name=enddate_active]').parents('.input-group').children('input').prop('disabled', false) : $('input[name=enddate_active]').parents('.input-group').children('input').prop('disabled', true);
$('input[name=startdate_active]').on('click', function() {
if ($('input[name=startdate_active]').prop('checked')) {
$('input[name=enddate_active]').prop('disabled', false);
Expand All @@ -277,7 +279,7 @@
$('input[name=enddate_active]').parents('.input-group').children('input').prop('disabled', true);
}
});
$('.input-group-addon input[type=checkbox]').on('click', function(){
var prop = $(this).parents('.input-group').children('input').prop('disabled');
if(prop){
Expand All @@ -286,7 +288,7 @@
$(this).parents('.input-group').children('input').prop('disabled', true);
}
});
$('#select-recipients').select2();
$('#selectAll').click(function(e) {
e.preventDefault();
Expand Down Expand Up @@ -369,6 +371,7 @@
$data['startdate_error'] = Session::getError('startdate', "<span class='help-block'>:message</span>");
$data['enddate_error'] = Session::getError('enddate', "<span class='help-block'>:message</span>");

load_js('select2');
load_js('bootstrap-datetimepicker');
$head_content .= "
<script type='text/javascript'>
Expand Down Expand Up @@ -595,8 +598,8 @@
}
} else {
Session::Messages($langAnnAdd, 'alert-success');
redirect_to_home_page("modules/announcements/index.php?course=$course_code");
}
redirect_to_home_page("modules/announcements/index.php?course=$course_code");
} else {
Session::flashPost()->Messages($langFormErrors)->Errors($v->errors());
redirect_to_home_page("modules/announcements/index.php?course=$course_code&addAnnounce=1");
Expand Down
13 changes: 2 additions & 11 deletions resources/views/modules/announcements/create_edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
@extends('layouts.default')

@push('head_styles')
<link rel='stylesheet' type='text/css' href="/js/select2-3.5.1/select2.css" />
<link rel='stylesheet' type='text/css' href="/js/select2-3.5.1/select2-bootstrap.css" />
@endpush

@push('head_scripts')
<script src="/js/select2-3.5.1/select2.min.js"></script>
@endpush

@section('content')

{!! $action_bar !!}
Expand All @@ -32,10 +23,10 @@
<div class='form-group'><label for='Email' class='col-sm-offset-2 col-sm-10 control-panel'>{{ trans('langEmailOption') }}:</label></div>
<div class='form-group'>
<div class='col-sm-offset-2 col-sm-10'>
<select class='form-control' name='recipients[]' multiple id='select-recipients'>
<select class='form-control' name='recipients[]' multiple='multiple' id='select-recipients'>
<option value='-1' selected>{{ trans('langAllUsers') }}</option>
@foreach ($course_users as $cu)
<option value='{{ $cu->user_id }}'>{{$cu->name}} ({{$cu->email}})</option>
<option value='{{ $cu->user_id }}'>{{$cu->name}} ({{$cu->email}})</option>
@endforeach
</select>
<a href='#' id='selectAll'>{{ trans('langJQCheckAll') }}</a> | <a href='#' id='removeAll'>{{ trans('langJQUncheckAll') }}</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/modules/announcements/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class : 'form-control input-sm',
$(document).on( 'click','.delete_btn', function (e) {
e.preventDefault();
var row_id = $(this).data('id');
bootbox.confirm('".js_escape($langSureToDelAnnounce)."', function(result) {
bootbox.confirm('{{ js_escape(trans('langSureToDelAnnounce')) }}', function(result) {
if(result) {
$.ajax({
type: 'POST',
Expand Down

0 comments on commit d542aac

Please sign in to comment.