added email_digest UI
This commit is contained in:
parent
e4d3b19b24
commit
1ead1fcef1
0
setup/doctype/email_digest/__init__.py
Normal file
0
setup/doctype/email_digest/__init__.py
Normal file
71
setup/doctype/email_digest/email_digest.coffee
Normal file
71
setup/doctype/email_digest/email_digest.coffee
Normal file
@ -0,0 +1,71 @@
|
||||
content_items = ['Sales','Expenses','Bank Balance','Activity']
|
||||
freq = ['Daily', 'Weekly']
|
||||
|
||||
# make a grid with items and columns of checkboxes
|
||||
# Parameters:
|
||||
# label (main heading)
|
||||
# items = [] (rows)
|
||||
# columns = [] (columns of checks)
|
||||
|
||||
class CheckGrid
|
||||
constructor: (@parent, @label, @items, @columns) ->
|
||||
@tab = make_table @parent, @items.length + 1, @columns.length + 1, '80%'
|
||||
@checks = {}
|
||||
|
||||
# render heads
|
||||
for i in [0..@columns.length-1]
|
||||
$td(@tab, 0, i+1).innerHTML = @columns[i]
|
||||
|
||||
# render rows
|
||||
for i in [0..@items.length-1]
|
||||
$td(@tab, i+1, 0).innerHTML = @items[i]
|
||||
|
||||
# render checkboxes for this row
|
||||
@checks[@items[i]] = {}
|
||||
for c in [0..@columns.length-1]
|
||||
check = $a_input $td(@tab, i+1, c+1), 'checkbox'
|
||||
|
||||
# tag keys to checkbox
|
||||
check.item = @items[i]
|
||||
check.column = @columns[c]
|
||||
|
||||
# add in my checks
|
||||
@checks[@items[i]][@columns[c]] = check
|
||||
|
||||
# get the values of the checkbox in a double dict
|
||||
get: =>
|
||||
val = {}
|
||||
for item in keys @checks
|
||||
for column in keys @checks[item]
|
||||
check = @checks[item][column]
|
||||
if not val[check.item]
|
||||
val[check.item] = {}
|
||||
val[check.item][check.column] = if check.checked then 1 else 0
|
||||
val
|
||||
|
||||
# set the values of the grid
|
||||
set: (val) =>
|
||||
for item in keys @checks
|
||||
for column in keys @checks[item]
|
||||
check = @checks[item][column]
|
||||
check.checked = val[check.item][check.row]
|
||||
|
||||
# attach it to onload
|
||||
cx = cur_frm.cscript
|
||||
cx.onload = (doc, dt, dn) ->
|
||||
|
||||
# make the content grid
|
||||
cx.content_grid = new CheckGrid cur_frm.fields_dict.Body.wrapper, 'Email Settings',
|
||||
content_items, freq
|
||||
|
||||
# make the email grid
|
||||
cx.email_grid = new CheckGrid cur_frm.fields_dict.Body.wrapper, 'Send To',
|
||||
['test1@erpnext', 'test2@erpnext'], freq
|
||||
|
||||
# update the data before sending
|
||||
cx.validate = (doc, dt, dn) ->
|
||||
doc.content_config = JSON.stringify cx.content_grid.get()
|
||||
doc.email_config = JSON.stringify cx.email_grid.get()
|
||||
|
||||
|
||||
|
80
setup/doctype/email_digest/email_digest.js
Normal file
80
setup/doctype/email_digest/email_digest.js
Normal file
@ -0,0 +1,80 @@
|
||||
(function() {
|
||||
var CheckGrid, content_items, cx, freq;
|
||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||
content_items = ['Sales', 'Expenses', 'Bank Balance', 'Activity'];
|
||||
freq = ['Daily', 'Weekly'];
|
||||
CheckGrid = (function() {
|
||||
function CheckGrid(parent, label, items, columns) {
|
||||
var c, check, i, _ref, _ref2, _ref3;
|
||||
this.parent = parent;
|
||||
this.label = label;
|
||||
this.items = items;
|
||||
this.columns = columns;
|
||||
this.set = __bind(this.set, this);
|
||||
this.get = __bind(this.get, this);
|
||||
this.tab = make_table(this.parent, this.items.length + 1, this.columns.length + 1, '80%');
|
||||
this.checks = {};
|
||||
for (i = 0, _ref = this.columns.length - 1; 0 <= _ref ? i <= _ref : i >= _ref; 0 <= _ref ? i++ : i--) {
|
||||
$td(this.tab, 0, i + 1).innerHTML = this.columns[i];
|
||||
}
|
||||
for (i = 0, _ref2 = this.items.length - 1; 0 <= _ref2 ? i <= _ref2 : i >= _ref2; 0 <= _ref2 ? i++ : i--) {
|
||||
$td(this.tab, i + 1, 0).innerHTML = this.items[i];
|
||||
this.checks[this.items[i]] = {};
|
||||
for (c = 0, _ref3 = this.columns.length - 1; 0 <= _ref3 ? c <= _ref3 : c >= _ref3; 0 <= _ref3 ? c++ : c--) {
|
||||
check = $a_input($td(this.tab, i + 1, c + 1), 'checkbox');
|
||||
check.item = this.items[i];
|
||||
check.column = this.columns[c];
|
||||
this.checks[this.items[i]][this.columns[c]] = check;
|
||||
}
|
||||
}
|
||||
}
|
||||
CheckGrid.prototype.get = function() {
|
||||
var check, column, item, val, _i, _j, _len, _len2, _ref, _ref2;
|
||||
val = {};
|
||||
_ref = keys(this.checks);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
item = _ref[_i];
|
||||
_ref2 = keys(this.checks[item]);
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||
column = _ref2[_j];
|
||||
check = this.checks[item][column];
|
||||
if (!val[check.item]) {
|
||||
val[check.item] = {};
|
||||
}
|
||||
val[check.item][check.column] = check.checked ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
};
|
||||
CheckGrid.prototype.set = function(val) {
|
||||
var check, column, item, _i, _len, _ref, _results;
|
||||
_ref = keys(this.checks);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
item = _ref[_i];
|
||||
_results.push((function() {
|
||||
var _j, _len2, _ref2, _results2;
|
||||
_ref2 = keys(this.checks[item]);
|
||||
_results2 = [];
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||
column = _ref2[_j];
|
||||
check = this.checks[item][column];
|
||||
_results2.push(check.checked = val[check.item][check.row]);
|
||||
}
|
||||
return _results2;
|
||||
}).call(this));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
return CheckGrid;
|
||||
})();
|
||||
cx = cur_frm.cscript;
|
||||
cx.onload = function(doc, dt, dn) {
|
||||
cx.content_grid = new CheckGrid(cur_frm.fields_dict.Body.wrapper, 'Email Settings', content_items, freq);
|
||||
return cx.email_grid = new CheckGrid(cur_frm.fields_dict.Body.wrapper, 'Send To', ['test1@erpnext', 'test2@erpnext'], freq);
|
||||
};
|
||||
cx.validate = function(doc, dt, dn) {
|
||||
doc.content_config = JSON.stringify(cx.content_grid.get());
|
||||
return doc.email_config = JSON.stringify(cx.email_grid.get());
|
||||
};
|
||||
}).call(this);
|
87
setup/doctype/email_digest/email_digest.txt
Normal file
87
setup/doctype/email_digest/email_digest.txt
Normal file
@ -0,0 +1,87 @@
|
||||
# DocType, Email Digest
|
||||
[
|
||||
|
||||
# These values are common in all dictionaries
|
||||
{
|
||||
'creation': '2011-07-27 14:23:09',
|
||||
'docstatus': 0,
|
||||
'modified': '2011-07-27 15:22:11',
|
||||
'modified_by': 'Administrator',
|
||||
'owner': 'Administrator'
|
||||
},
|
||||
|
||||
# These values are common for all DocType
|
||||
{
|
||||
'_last_update': '1311759390',
|
||||
'colour': 'White:FFF',
|
||||
'doctype': 'DocType',
|
||||
'issingle': 1,
|
||||
'module': 'Setup',
|
||||
'name': '__common__',
|
||||
'section_style': 'Simple',
|
||||
'show_in_menu': 0,
|
||||
'version': 3
|
||||
},
|
||||
|
||||
# These values are common for all DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'name': '__common__',
|
||||
'parent': 'Email Digest',
|
||||
'parentfield': 'fields',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0
|
||||
},
|
||||
|
||||
# These values are common for all DocPerm
|
||||
{
|
||||
'create': 1,
|
||||
'doctype': 'DocPerm',
|
||||
'idx': 1,
|
||||
'name': '__common__',
|
||||
'parent': 'Email Digest',
|
||||
'parentfield': 'permissions',
|
||||
'parenttype': 'DocType',
|
||||
'permlevel': 0,
|
||||
'read': 1,
|
||||
'role': 'Administrator',
|
||||
'write': 1
|
||||
},
|
||||
|
||||
# DocType, Email Digest
|
||||
{
|
||||
'doctype': 'DocType',
|
||||
'name': 'Email Digest'
|
||||
},
|
||||
|
||||
# DocPerm
|
||||
{
|
||||
'doctype': 'DocPerm'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldtype': 'HTML',
|
||||
'idx': 1,
|
||||
'label': 'Body'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'content_config',
|
||||
'fieldtype': 'Text',
|
||||
'idx': 2,
|
||||
'label': 'Content Config'
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': 'DocField',
|
||||
'fieldname': 'email_config',
|
||||
'fieldtype': 'Text',
|
||||
'idx': 3,
|
||||
'label': 'Email Config'
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user