-
Notifications
You must be signed in to change notification settings - Fork 0
/
spark.kfunctions.php
70 lines (54 loc) · 2.73 KB
/
spark.kfunctions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly
//require_once( K_COUCH_DIR.'addons/cart/cart.php' );
//require_once( K_COUCH_DIR.'addons/inline/inline.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-folders.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-comments.php' );
require_once( K_COUCH_DIR.'addons/extended/extended-users.php' );
require_once( K_COUCH_DIR.'addons/routes/routes.php' );
//require_once( K_COUCH_DIR.'addons/jcropthumb/jcropthumb.php' );
//require_once( K_COUCH_DIR.'addons/page-builder/page-builder.php' );
//require_once( K_COUCH_DIR.'addons/sub-templates/sub-templates.php' );
// Save and back buttons
if( defined('K_ADMIN') ){ // if admin-panel being displayed ..
// 1. Add a 'Save and back' button to form view
$my_target_action = 'page'; // available targets on the form are - toolbar, filter, page and extended
$FUNCS->add_event_listener( 'alter_pages_form_'.$my_target_action.'_actions', 'my_add_button' );
function my_add_button( &$arr_actions, &$obj ){
global $FUNCS, $PAGE;
$route = $FUNCS->current_route;
if( is_object($route) && $route->module=='pages' ){
if( $PAGE->tpl_is_clonable ){ // if template is clonable, add the new button to form
$arr_actions['btn_save_and_back'] =
array(
'title'=>'Save and go back',
'onclick'=>array(
"$('#btn_submit').trigger('my_submit');",
"var form = $('#".$obj->form_name."');",
"form.find('#k_custom_action').val('save_and_back');",
"form.submit();",
"return false;",
),
'icon'=>'collapse-left',
'weight'=>15,
);
}
}
}
// 2. When the button above submits the form, take custom action (go back to list-view in this case)
$FUNCS->add_event_listener( 'pages_form_custom_action', 'my_add_button_action' );
function my_add_button_action( $custom_action, &$redirect_dest, &$pg, $_mode ){
global $FUNCS, $PAGE;
$route = $FUNCS->current_route;
if( is_object($route) && $route->module=='pages' ){
if( $custom_action === 'save_and_back' ){
// set the new redirect destination (the list view with all querystring parameters) ..
if( $PAGE->tpl_is_clonable ){
$link = $FUNCS->generate_route( $PAGE->tpl_name, 'list_view' );
$link = $FUNCS->get_qs_link( $link );
$redirect_dest = $link;
}
}
}
}
}