views/engine2.coffee in engine2-1.0.2 vs views/engine2.coffee in engine2-1.0.3
- old
+ new
@@ -3,14 +3,19 @@
angular.module('Engine2', ['ngRoute', 'ngSanitize', 'ngAnimate', 'ngCookies', 'mgcrea.ngStrap', 'ngFileUpload', 'ui.tree', 'LocalStorageModule']) # 'draggabilly'
.factory 'E2Snippets', ->
icon = (name) -> "<span class='glyphicon glyphicon-#{name}'></span>"
aicon = (name) -> "<i class='fa fa-#{name}'></i>"
+ ng_class_names = ['active', 'enabled', 'disabled']
icon: icon
aicon: aicon
boolean_true_value: icon('check')
boolean_false_value: icon('unchecked')
+ make_ng_class: (o) ->
+ out = []
+ _.each ng_class_names, (e) -> out.push(if e == 'enabled' then "'disabled': !(#{o[e]})" else "'#{e}': #{o[e]}") if o[e]?
+ if out.length > 0 then "ng-class=\"{#{out.join(',')}}\"" else ""
.config ($httpProvider, $routeProvider, $compileProvider, localStorageServiceProvider, $logProvider) ->
loaderOn = -> angular.element(document.querySelectorAll('.loader')).eq(-1).css("visibility", 'visible')
$httpProvider.interceptors.push 'e2HttpInterceptor'
$httpProvider.defaults.transformRequest.push (data, headersGetter) ->
@@ -59,20 +64,20 @@
else if _.isObject(v) && !_.isDate(v)
@clean(v)
else
# delete o[k]
o[k] = null
- merge: (o1, o2) ->
- for p of o2
- try # if o1 and no try ?
- if _.isObject(o2[p]) && !_.isArray(o2[p])
- o1[p] = @merge(o1[p] ? {}, o2[p])
+ merge: (dst, src) ->
+ for k, v of src
+ if _.isObject(v) && !_.isArray(v)
+ if k.slice(-1) == '!'
+ dst[k.slice(0, -1)] = v
else
- o1[p] = o2[p]
- catch
- o1[p] = o2[p]
- o1
+ dst[k] = @merge(dst[k] ? {}, v)
+ else
+ dst[k] = v
+ dst
transpose: (a) ->
_.keys(a[0]).map((c) -> a.map (r) -> r[c])
join_keys: (keys) -> keys.join('|')
@@ -105,20 +110,25 @@
fun(m)
process_menu: (action, menu_name) ->
processor = @menu_processors[menu_name]
@each_menu action.meta.menus[menu_name].entries, (m) ->
- menu_fun_name = "#{menu_name}_#{m.name}"
- menu_fun_invoke = "action['#{menu_fun_name}'](#{processor.arg_name})"
+ fun_name = "#{menu_name}_#{m.name}"
+ fun_invoke = "action['#{fun_name}'](#{processor.arg_name})"
+ fun_invoke = "(#{m.enabled}) && #{fun_invoke}" if m.enabled?
+ fun_invoke = "!(#{m.disabled}) && #{fun_invoke}" if m.disabled?
click = m.click
- m.click = menu_fun_invoke
- action[menu_fun_name] ?= (args...) ->
- processor.arg_fun(action, args...)
- if click
+ m.click = fun_invoke
+
+ if click
+ action[fun_name] = (args...) ->
+ processor.arg_fun(action, args...)
action.scope().$eval(click)
- else
+ else
+ action[fun_name] ?= (args...) ->
+ processor.arg_fun(action, args...)
action.invoke_action(m.name, processor.arg_ret(action))
if action.find_action_info(m.name, false)?
show = if m.show then " && " + m.show else ""
m.show = "action.find_action_info('#{m.name}').access" + show
@@ -136,12 +146,10 @@
arg_name: '$index'
arg_ret: (action) -> id: action.current_id
arg_fun: (action, index) ->
action.current_id = $injector.get('E2').id_for(action.entries[index], action.meta)
-
-
renderers:
boolean: (value, render) =>
switch value
when render.true_value then E2Snippets.boolean_true_value
when render.false_value then E2Snippets.boolean_false_value
@@ -402,11 +410,12 @@
elem.append($compile(out)(scope)) unless out.length == 0 # leak ?
.directive 'e2DropDown', ($parse, $dropdown, $timeout, E2Snippets) ->
event_num = 0
dropdown_sub_tmpl = _.template("<li class='dropdown-submenu'><a href=''> {{icon}}{{aicon}} {{loc}}</a>{{sub}}</li>")
- dropdown_tmpl = _.template("<li {{show}} {{hide}} {{disabled}} {{enabled}}> <a href='{{href}}' {{click}}> {{icon}}{{aicon}} {{loc}}</a></li>")
+ dropdown_tmpl = _.template("<li {{clazz}} {{show}} {{hide}}> <a href='{{href}}' {{click}}> {{icon}}{{aicon}} {{loc}}</a></li>")
+
render = (menu, level) ->
out = menu.map (m) ->
switch
when m.divider
"<li class='divider'></li>"
@@ -416,17 +425,15 @@
aicon: m.menu.aicon && E2Snippets.aicon(m.menu.aicon) || ''
loc: m.menu.loc
sub: render(m.menu.entries)
else
dropdown_tmpl
+ clazz: E2Snippets.make_ng_class(m)
show: m.show && "ng-show=\"#{m.show}\"" || ''
hide: m.hide && "ng-hide=\"#{m.hide}\"" || ''
- disabled: m.disabled && "ng-class=\"#{m.disabled} && 'disabled'\"" || ''
- enabled: m.enabled && "ng-class=\"#{m.enabled} || 'disabled'\"" || ''
- # active: m.active && "ng-class='#{m.active}' || \"active\"'" || ''
href: m.href || ''
- click: m.click && "ng-click=\"#{m.disabled && m.disabled + " ||" || ''} #{m.enabled && m.enabled + " &&" || ''} #{m.click}\""
+ click: m.click && "ng-click=\"#{m.click}\"" || ''
icon: m.icon && E2Snippets.icon(m.icon) || ''
aicon: m.aicon && E2Snippets.aicon(m.aicon) || ''
loc: m.loc
"<ul class='dropdown-menu'>#{out.join('')}</ul>"
@@ -453,16 +460,16 @@
elem.removeClass "active"
elem.on "mousedown", hook
.directive 'e2ButtonSet', ($parse, $compile, E2Snippets) ->
- button_set_tmpl = _.template("<div class='btn btn-default' {{clazz}} {{click}} {{show}} {{hide}} {{disabled}} {{enabled}} {{title}}> {{icon}}{{aicon}} {{loc}}</div>")
+ button_set_tmpl = _.template("<div class='btn btn-default' {{clazz}} {{click}} {{show}} {{hide}} {{title}}> {{icon}}{{aicon}} {{loc}}</div>")
button_set_arr_tmpl = _.template("<div class='btn btn-default' e2-drop-down='{{dropdown}}'>{{icon}}{{aicon}}<span class='caret'></span></div>")
scope: true # because $index
link: (scope, elem, attrs) ->
menu = $parse(attrs.e2ButtonSet)(scope)
- unless _.isEmpty(menu.entries)
+ if menu && menu.entries.length > 0
group_class = menu.properties.group_class || ''
brk = menu.properties.break
out = ""
for m, i in menu.entries
if i >= brk
@@ -473,16 +480,14 @@
icon: m.menu.icon && "#{E2Snippets.icon(m.menu.icon)} " || ''
aicon: m.menu.aicon && "#{E2Snippets.aicon(m.menu.aicon)} " || ''
else if m.divider
else
out += button_set_tmpl
- clazz: m.class && "ng-class=\"#{m.class}\"" || ''
+ clazz: E2Snippets.make_ng_class(m)
click: m.click && "ng-click=\"#{m.click}\"" || ''
show: m.show && "ng-show=\"#{m.show}\"" || ''
hide: m.hide && "ng-hide=\"#{m.hide}\"" || ''
- disabled: m.disabled && "ng-class=\"#{m.disabled} && 'disabled'\"" || ''
- enabled: m.enabled && "ng-class=\"#{m.enabled} || 'disabled'\"" || ''
icon: m.icon && E2Snippets.icon(m.icon) || ''
aicon: m.aicon && E2Snippets.aicon(m.aicon) || ''
loc: !(m.button_loc == false) && m.loc || ''
title: (m.button_loc == false) && "title=\"#{m.loc}\"" || ''
@@ -547,10 +552,10 @@
scope.$watch attr.ngModel, (model, o) -> if model != o
date = format(model, attr.e2ModelFormat)
if action.query
action.query.search[scope.f][mode] = date
- scope.action.search_live(scope.f) if date?
+ scope.action.search_field_change(scope.f) if date?
else
action.record[field] = date
.directive 'e2Integer', ->
require: 'ngModel'