Skip to content

Commit a0fe0d0

Browse files
committed
Alerts added
1 parent a6eaac9 commit a0fe0d0

File tree

10 files changed

+69
-33
lines changed

10 files changed

+69
-33
lines changed

app/Http/Controllers/SettingController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ function AddDepartment(Request $request){
5151
return false;
5252
}
5353

54+
if($request->adddepartment == null){
55+
return json_encode(array('error' => 'Department field is empty'));
56+
}
57+
5458
DB::table('departments')->insert(
5559
['department' => $request->adddepartment]
5660
);
@@ -76,6 +80,10 @@ function uploadpath(Request $request){
7680
return false;
7781
}
7882

83+
if($request->uploadpath == null){
84+
return json_encode(array('error' => 'Upload path field is empty'));
85+
}
86+
7987
\Settings::set('uploadpath',$request->uploadpath);
8088

8189
ActivityLog::log()->save('Setting','You have set upload path to '.$request->uploadpath.'.');

public/js/kchat.js

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11

2+
gfunc = null;
3+
4+
$('#alert-ok').on('click', function() {
5+
gfunc();
6+
});
7+
8+
function kchat_alert(body,func){
9+
if(body == undefined){
10+
func();
11+
return true;
12+
}
13+
$("#alertbody").html(body);
14+
$("#alertmodel").click();
15+
gfunc = func;
16+
}
17+
218
if(localStorage.getItem('selected') == null){
319
localStorage.setItem('selected', "");
420
}
@@ -48,9 +64,23 @@ Ajax call
4864
---------------------------------------------------------------------
4965
*/
5066

67+
tmp = {};
68+
69+
tmp.set = function(param){
70+
tmp.value = param;
71+
}
72+
73+
tmp.get = function(){
74+
return tmp.value;
75+
}
76+
5177
$( "[ajax_post]" ).on( "click", function () {
5278

53-
form = $(this).attr('form');
79+
tmp.set($(this));
80+
81+
kchat_alert(tmp.get().attr('data-msg'),(function(){
82+
83+
form = tmp.get().attr('form');
5484

5585
row = $('.' + form).get();
5686

@@ -70,12 +100,17 @@ $( "[ajax_post]" ).on( "click", function () {
70100

71101
$.ajax({
72102
type: "POST",
73-
url: $(this).attr('action'),
103+
url: tmp.get().attr('action'),
74104
data: Data,
75105
processData: false,
76106
contentType: false,
77107
success: function(result){
78-
location.reload();
108+
result = $.parseJSON(result);
109+
if(result['error'] == undefined){
110+
location.reload();
111+
}else{
112+
kchat_alert(result['error'],(function(){}));
113+
}
79114
},
80115
error: function(result){
81116
alert_msg = [];
@@ -86,7 +121,7 @@ $( "[ajax_post]" ).on( "click", function () {
86121
$('#' + form + '-error').html(alert_msg.join("<br>")).css("display", "block");
87122
}
88123
});
89-
124+
}));
90125
});
91126

92127
/*
@@ -273,7 +308,12 @@ function __post(url,posts){
273308
url: url,
274309
data: Data,
275310
success: function(result){
276-
location.reload();
311+
result = $.parseJSON(result);
312+
if(result['error'] == undefined){
313+
location.reload();
314+
}else{
315+
kchat_alert(result['error'],(function(){}));
316+
}
277317
}
278318
});
279319
}
@@ -337,16 +377,4 @@ function setSelectedCount(){
337377
}
338378
}
339379

340-
setSelectedCount();
341-
342-
gfunc = null;
343-
344-
$('#alert-ok').on('click', function() {
345-
gfunc();
346-
});
347-
348-
function kchat_alert(body,func){
349-
$("#alertbody").html(body);
350-
$("#alertmodel").click();
351-
gfunc = func;
352-
}
380+
setSelectedCount();

resources/views/admin/activities.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</button>
5252
<div class="dropdown-menu dropdown-menu-right">
5353
<input type="hidden" class="act{{ $info->id }}" id="id" value="{{ $info->id }}" />
54-
<button class="dropdown-item" type="button" ajax_post action="/activity/delete" form="act{{ $info->id }}" ><i class="mdi mdi-delete"></i> Delete</button>
54+
<button class="dropdown-item" type="button" ajax_post data-msg="Are you sure you want to delete activities?" action="/activity/delete" form="act{{ $info->id }}" ><i class="mdi mdi-delete"></i> Delete</button>
5555
</div>
5656
</div>
5757
<br />
@@ -67,7 +67,7 @@
6767
@section('script')
6868
<script>
6969
function delete_activity(){
70-
__post('/activity/delete',getSelectedID());
70+
kchat_alert("Are you sure you want to delete <strong>Activities</strong>?",(function(){__post('/activity/delete',getSelectedID());}));
7171
}
7272
</script>
7373
@endsection

resources/views/admin/notifications.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</button>
5252
<div class="dropdown-menu dropdown-menu-right">
5353
<input type="hidden" class="not{{ $info->id }}" id="id" value="{{ $info->id }}" />
54-
<button class="dropdown-item" type="button" ajax_post action="/notification/delete" form="not{{ $info->id }}"><i class="mdi mdi-delete"></i> Delete</button>
54+
<button class="dropdown-item" type="button" ajax_post data-msg="Are you sure you want to delete notifications?" action="/notification/delete" form="not{{ $info->id }}"><i class="mdi mdi-delete"></i> Delete</button>
5555
</div>
5656
</div>
5757
<br />
@@ -67,7 +67,7 @@
6767
@section('script')
6868
<script>
6969
function delete_notificatios(){
70-
__post('/notification/delete',getSelectedID());
70+
kchat_alert("Are you sure you want to delete <strong>Notifications</strong>?",(function(){__post('/notification/delete',getSelectedID());}));
7171
}
7272
</script>
7373
@endsection

resources/views/admin/profile.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
</div>
9595
</div>
9696
<div class="row">
97-
<div class="col d-flex justify-content-end"> <button class="btn btn-primary" type="submit" ajax_post action="/profile" form="profile" >Save Changes</button></div>
97+
<div class="col d-flex justify-content-end"> <button class="btn btn-primary" type="submit" ajax_post data-msg="Are you sure you want to update your profile?" action="/profile" form="profile" >Save Changes</button></div>
9898
</div>
9999
</div>
100100
</div>

resources/views/admin/settings.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
<p>Add and Delete Department</p>
2020
<div class="mt-3"> <label class="small mb-1" for="twoFactorSMS">Add Department</label>
2121
<input class="form-control savedpt" id="adddepartment" placeholder="Department" >
22-
<button class="btn btn-primary mt-3" type="button" ajax_post action="/setting/savedpt" form="savedpt" >Add Department</button>
22+
<button class="btn btn-primary mt-3" type="button" ajax_post data-msg="Are you sure you want to add department?" action="/setting/savedpt" form="savedpt" >Add Department</button>
2323
</div>
2424
<div class="mt-3"> <label class="small mb-1" for="twoFactorSMS">Delete Department</label>
2525
<select class="form-control deletedpt" type="text" id="deletedepartment" >
2626
@foreach($departments as $department)
2727
<option value="{{ $department->department }}">{{ $department->department }}</option>
2828
@endforeach
2929
</select>
30-
<button class="btn btn-danger mt-3" type="button" ajax_post action="/setting/deletedpt" form="deletedpt" >Delete Department</button>
30+
<button class="btn btn-danger mt-3" type="button" ajax_post data-msg="Are you sure you want to delete department?" action="/setting/deletedpt" form="deletedpt" >Delete Department</button>
3131
</div>
3232
</div>
3333
</div>
@@ -40,7 +40,7 @@
4040
<option value="{{ $tz }}" @if($tz == $settings['Timezone']) selected @endif>{{ $tz }}</option>
4141
@endforeach
4242
</select>
43-
<button class="btn btn-primary mt-3" type="button" ajax_post action="/setting/timezone" form="timezone" >Update Timezone</button>
43+
<button class="btn btn-primary mt-3" type="button" ajax_post data-msg="Are you sure you want to update timezone?" action="/setting/timezone" form="timezone" >Update Timezone</button>
4444
</div>
4545
</div>
4646
</div>
@@ -49,7 +49,7 @@
4949
<div class="card-body">
5050
<p class="small text-muted">Place it outside the webroot means that the files will not be publicly exposed.</p>
5151
<input class="form-control uploadpath" id="uploadpath" placeholder="/home/user/files" value="{{ $settings['uploadpath'] }}" >
52-
<button class="btn btn-primary mt-3" type="button" ajax_post action="/setting/uploadpath" form="uploadpath" >Update Timezone</button>
52+
<button class="btn btn-primary mt-3" type="button" ajax_post data-msg="Are you sure you want to update upload path?" action="/setting/uploadpath" form="uploadpath" >Update Timezone</button>
5353
</div>
5454
</div>
5555
<!--div class="card mb-4">

resources/views/common/msg.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
</div>
8787
<div class="modal-footer">
8888
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
89-
<button type="button" class="btn btn-primary" ajax_post action="/messages/update" form="updategroup" >Update Group</button>
89+
<button type="button" class="btn btn-primary" ajax_post data-msg="Are you sure you want to update group profile?" action="/messages/update" form="updategroup" >Update Group</button>
9090
</div>
9191
</div>
9292
</div>

resources/views/user/activities.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</button>
5252
<div class="dropdown-menu dropdown-menu-right">
5353
<input type="hidden" class="act{{ $info->id }}" id="id" value="{{ $info->id }}" />
54-
<button class="dropdown-item" type="button" ajax_post action="/activity/delete" form="act{{ $info->id }}" ><i class="mdi mdi-delete"></i> Delete</button>
54+
<button class="dropdown-item" type="button" ajax_post data-msg="Are you sure you want to delete activities?" action="/activity/delete" form="act{{ $info->id }}" ><i class="mdi mdi-delete"></i> Delete</button>
5555
</div>
5656
</div>
5757
<br />
@@ -67,7 +67,7 @@
6767
@section('script')
6868
<script>
6969
function delete_activity(){
70-
__post('/activity/delete',getSelectedID());
70+
kchat_alert("Are you sure you want to delete <strong>Activities</strong>?",(function(){__post('/activity/delete',getSelectedID());}));
7171
}
7272
</script>
7373
@endsection

resources/views/user/notifications.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</button>
5252
<div class="dropdown-menu dropdown-menu-right">
5353
<input type="hidden" class="not{{ $info->id }}" id="id" value="{{ $info->id }}" />
54-
<button class="dropdown-item" type="button" ajax_post action="/notification/delete" form="not{{ $info->id }}"><i class="mdi mdi-delete"></i> Delete</button>
54+
<button class="dropdown-item" type="button" ajax_post data-msg="Are you sure you want to delete notifications?" action="/notification/delete" form="not{{ $info->id }}"><i class="mdi mdi-delete"></i> Delete</button>
5555
</div>
5656
</div>
5757
<br />
@@ -67,7 +67,7 @@
6767
@section('script')
6868
<script>
6969
function delete_notificatios(){
70-
__post('/notification/delete',getSelectedID());
70+
kchat_alert("Are you sure you want to delete <strong>Notifications</strong>?",(function(){__post('/notification/delete',getSelectedID());}));
7171
}
7272
</script>
7373
@endsection

resources/views/user/profile.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</div>
8989
</div>
9090
<div class="row">
91-
<div class="col d-flex justify-content-end"> <button class="btn btn-primary" type="submit" ajax_post action="/profile" form="profile" >Save Changes</button></div>
91+
<div class="col d-flex justify-content-end"> <button class="btn btn-primary" type="submit" ajax_post data-msg="Are you sure you want to update profile?" action="/profile" form="profile" >Save Changes</button></div>
9292
</div>
9393
</div>
9494
</div>

0 commit comments

Comments
 (0)