Skip to content

Commit

Permalink
acd rules dialogs and controllers in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mijkenator committed Jul 22, 2011
1 parent 08ca5e5 commit ef9e739
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 62 deletions.
Binary file modified erlang-web/Mnesia.test@localhost/DECISION_TAB.LOG
Binary file not shown.
Binary file modified erlang-web/Mnesia.test@localhost/LATEST.LOG
Binary file not shown.
Binary file modified erlang-web/Mnesia.test@localhost/acd_rules.DCD
Binary file not shown.
Binary file modified erlang-web/Mnesia.test@localhost/ids_tab.DCD
Binary file not shown.
6 changes: 5 additions & 1 deletion erlang-web/config/dispatch.conf
Expand Up @@ -50,6 +50,10 @@

{dynamic, "^/json/account/acd$", {controller_account_acd, handle}, [{cache, no_cache}]}.

{dynamic, "^/json/accounts/acd/rules$", {controller_acd_rules, handle}, [{cache, no_cache}]}.
{dynamic, "^/json/accounts/acd/rules/(?<id>[0-9]+)/add$", {controller_acd_rules, add}, [{cache, no_cache}]}.
{dynamic, "^/json/accounts/acd/rules/(?<id>[0-9]+)/delete$", {controller_acd_rules, delete}, [{cache, no_cache}]}.
{dynamic, "^/json/accounts/acd/rules/(?<id>[0-9]+)/update$", {controller_acd_rules, update}, [{cache, no_cache}]}.
{dynamic, "^/json/accounts/acd/rules/(?<id>[0-9]+)", {controller_acd_rules, get}, [{cache, no_cache}]}.


{dynamic, "^/json/accounts/acd/rule/numbers$", {controller_acd_rule_numbers, handle}, [{cache, no_cache}]}.
255 changes: 254 additions & 1 deletion erlang-web/docroot/lib/external/jquery.jqGrid.min.js 100755 → 100644

Large diffs are not rendered by default.

Expand Up @@ -176,29 +176,77 @@ function create_acdrule_grid(rule_id){
jQuery("#list6").jqGrid({
url:'/json/accounts/acd/rules/'+rule_id,
datatype: "json",
colNames:['ID', 'Order', 'Forward type', 'Number', 'Timeout', 'Active'],
colNames:['ID', 'Priority', 'Name', 'Time Period', 'Active'],
colModel:[
{name:'id',index:'id', width:50},
{name:'order',index:'order', width:50},
{name:'forward_type',index:'forward_type', width:210},
{name:'number',index:'number', width:210, align:"right"},
{name:'timeout',index:'timeout', width:60, align:"right"},
{name:'active',index:'active', width:60,align:"right"}
{name:'priority',index:'order', width:100, editable:true, editrules:{required:true, integer:true}},
{name:'name',index:'forward_type', width:230, editable:true, editrules:{required:true}},
{name:'time_period',index:'number', width:230, align:"right", editable:true, edittype:"select", editoptions:{ value: "* * * * *:Always" },editrules:{required:true}},
{name:'active',index:'active', width:60,align:"right", editable:true, edittype:"checkbox", editrules:{required:true}}
],
rowNum:10,
//rowList:[10,20,30],
rowList:[10,20,30],
pager: '#pager6',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
onSortCol: function(name,index){ alert("Column Name: "+name+" Column Index: "+index);},
ondblClickRow: function(id){ alert("You double click row with id: "+id);},
height: 350
onSelectRow: function(ids) {
if(ids == null) {
ids=0;
if(jQuery("#list10_d").jqGrid('getGridParam','records') >0 )
{
jQuery("#list10_d").jqGrid('setGridParam',{url:"/json/accounts/acd/rulenumbers/"+rule_id+"/"+ids,page:1});
jQuery("#list10_d").jqGrid('setCaption',"Invoice Detail: "+ids)
.trigger('reloadGrid');
}
} else {
jQuery("#list10_d").jqGrid('setGridParam',{url:"/json/accounts/acd/rulenumbers/"+rule_id+"/"+ids,page:1});
jQuery("#list10_d").jqGrid('setCaption',"Invoice Detail: "+ids)
.trigger('reloadGrid');
}
},
height: 150
});
jQuery("#list6").jqGrid('navGrid',"#pager6",{edit:false,add:false,del:false});



jQuery("#list6").jqGrid('navGrid',"#pager6",{edit:true,add:true,del:true},
{
zIndex:1234,
closeAfterEdit:true,
closeOnEscape:true,
url: '/json/accounts/acd/rules/'+rule_id+'/update'
},
{
closeAfterAdd:true,
saveData: "Data has been changed! Save changes?",
zIndex:1234,
url: '/json/accounts/acd/rules/'+rule_id+'/add',
closeOnEscape:true
},
{
closeOnEscape:true,
zIndex:1234,
url: '/json/accounts/acd/rules/'+rule_id+'/delete'
},
{},{});
jQuery("#list10_d").jqGrid({
height: 100,
datatype: "json",
colNames:['No','Item', 'Qty', 'Unit','Line Total'],
colModel:[
{name:'num',index:'num', width:55},
{name:'item',index:'item', width:180},
{name:'qty',index:'qty', width:80, align:"right"},
{name:'unit',index:'unit', width:80, align:"right"},
{name:'linetotal',index:'linetotal', width:80,align:"right", sortable:false, search:false}
],
rowNum:5,
rowList:[5,10,20],
pager: '#pager10_d',
sortname: 'item',
viewrecords: true,
sortorder: "asc",
multiselect: true
}).navGrid('#pager10_d',{add:false,edit:false,del:false});

}


174 changes: 130 additions & 44 deletions erlang-web/lib/gtkiller-0.1/src/controller_acd_rules.erl
Expand Up @@ -3,10 +3,11 @@
-extends(controller_crud).

-export([
create/0,
update/0,
delete/0,
select/0
handle/1,
get/1,
add/1,
delete/1,
update/1
]).

-include("account.hrl").
Expand All @@ -16,43 +17,128 @@
-include("constants.hrl").
-include("utils_controller_annotations.hrl").

%%%
%%% Controller JSON-actions.
%%%

%%
%%
?PREPARE_DATA({}).
?VALIDATE_DATA({}).
create() -> ?BASE_MODULE:create().

%%
%%
?AUTHORIZE(json).
?CHECK_EXISTENCE({}).
?PREPARE_DATA({}).
update() ->
console:log(["Action executed MT1:", {?MODULE, update}], 'DEBUG'),
console:log(["update, BASE_MODULE:", ?BASE_MODULE], 'DEBUG'),
?BASE_MODULE:update().

%%
%%
?AUTHORIZE(json).
?CHECK_EXISTENCE({}).
delete() -> ?BASE_MODULE:delete().

?AUTHORIZE(json).
select() ->
console:log(["Action executed:", {?MODULE, select}], 'DEBUG'),
Command = wpart:fget(?KEY_COMMAND_JSON),
RawFields = jsonutils:get_attribute(Command, ?TO_JSON_NAME(fields)),
Fields = case RawFields of
undefined -> {exclude, []};
Value -> {fields, Value}
end,

Rows = ?BASE_MODULE:get_rows(),
FormattedRows = utils:format(acd_rules, Rows, Fields),

?BASE_MODULE:process_selected_rows(FormattedRows).
?PROCESS_RESPONSE({}).
?AUTHORIZE(json).
handle(_Args) ->
RequestJSON = jsonutils:decode(wpart:fget("post:request")),
[Command|_] = jsonutils:get_attribute(RequestJSON, ?JSON_COMMANDS),
Response = {struct, [{?JSON_COMMANDS, action(jsonutils:get_attribute(Command, <<"type">>))}]},
wpart:fset(?KEY_RESPONSE, Response).

action(A) ->
{struct,[
{?JSON_TYPE, utils:to_binary(A)},
{<<"error">>, <<"unexpected action">>}]}.

?AUTHORIZE(json).
get(_Args) ->
console:log(["ACD RULES GET"]),
AcdtId = utils:to_list(proplists:get_value(id, _Args)),
console:log(["ACD RULES GET: ", AcdtId]),

Records = db:select(acd_rules, fun(#acd_rules{acd_id=ACDID}) when ACDID=:=AcdtId->true;(_)->false end),

console:log(["ACD RULES GET: Records: ", Records]),

FR = {struct,[
{<<"page">>,1},
{<<"total">>,1},
{<<"records">>,length(Records)},
{<<"rows">>, [ {struct, [{<<"id">>,ID},
{<<"cell">>, [ID, utils:to_binary(P), utils:to_binary(Name), utils:to_binary(TP), utils:to_binary(A)]}]}
|| {_, ID, _, Name, TP, P, A} <- Records]}
]},

{content, text, mochijson2:encode(FR)}.

?AUTHORIZE(json).
add(_Args) ->
console:log(["ACD RULES ADD"]),
AcdtId = proplists:get_value(id, _Args),
Active = wpart:fget("post:active"),
Name = wpart:fget("post:name"),
Priority = wpart:fget("post:priority"),
TimePeriod = wpart:fget("post:time_period"),

ACDR = wtype_acd_rules:create(#acd_rules{
acd_id = AcdtId,
name = Name,
time_period = TimePeriod,
priority = Priority,
active = Active
}),

console:log(["NEW ACDR: ", ACDR]),

Records = db:select(acd_rules, fun(#acd_rules{acd_id=ACDID}) when ACDID=:=AcdtId->true;(_)->false end),

console:log(["ACD RULES GET: Records: ", Records]),

FR = {struct,[
{<<"page">>,1},
{<<"total">>,1},
{<<"records">>,length(Records)},
{<<"rows">>, [ {struct, [{<<"id">>,ID},
{<<"cell">>, [ID, utils:to_binary(P), utils:to_binary(Name), utils:to_binary(TP), utils:to_binary(A)]}]}
|| {_, ID, _, Name, TP, P, A} <- Records]}
]},

{content, text, mochijson2:encode(FR)}.

?AUTHORIZE(json).
delete(_Args) ->
console:log(["ACD RULES ADD"]),
AcdtId = proplists:get_value(id, _Args),
ID = wpart:fget("post:id"),

wtype_acd_rules:delete(utils:to_integer(ID)),

Records = db:select(acd_rules, fun(#acd_rules{acd_id=ACDID}) when ACDID=:=AcdtId->true;(_)->false end),

console:log(["ACD RULES GET: Records: ", Records]),

FR = {struct,[
{<<"page">>,1},
{<<"total">>,1},
{<<"records">>,length(Records)},
{<<"rows">>, [ {struct, [{<<"id">>,ID},
{<<"cell">>, [ID, utils:to_binary(P), utils:to_binary(Name), utils:to_binary(TP), utils:to_binary(A)]}]}
|| {_, ID, _, Name, TP, P, A} <- Records]}
]},

{content, text, mochijson2:encode(FR)}.


?AUTHORIZE(json).
update(_Args) ->
console:log(["ACD RULES ADD"]),
AcdtId = proplists:get_value(id, _Args),
ID = wpart:fget("post:id"),
Active = wpart:fget("post:active"),
Name = wpart:fget("post:name"),
Priority = wpart:fget("post:priority"),
TimePeriod = wpart:fget("post:time_period"),

ACDR = wtype_acd_rules:update(#acd_rules{
id = utils:to_integer(ID),
acd_id = AcdtId,
name = Name,
time_period = TimePeriod,
priority = Priority,
active = Active
}),

Records = db:select(acd_rules, fun(#acd_rules{acd_id=ACDID}) when ACDID=:=AcdtId->true;(_)->false end),

console:log(["ACD RULES GET: Records: ", Records]),

FR = {struct,[
{<<"page">>,1},
{<<"total">>,1},
{<<"records">>,length(Records)},
{<<"rows">>, [ {struct, [{<<"id">>,ID},
{<<"cell">>, [ID, utils:to_binary(P), utils:to_binary(Name), utils:to_binary(TP), utils:to_binary(A)]}]}
|| {_, ID, _, Name, TP, P, A} <- Records]}
]},

{content, text, mochijson2:encode(FR)}.
7 changes: 5 additions & 2 deletions erlang-web/templates/pages/admin/acdrules/acdrules.html
Expand Up @@ -5,8 +5,11 @@
</div>


<table id="list6"> </table>
<div id="pager6"> </div>
<table id="list6"></table>
<div id="pager6"></div>

<table id="list10_d"></table>
<div id="pager10_d"></div>

</div>

Expand Down

0 comments on commit ef9e739

Please sign in to comment.