import m from "mithril" import stream from "mithril/stream" import { Card, ListTile, Icon, Search, Shadow, IconButton } from "polythene-mithril" import menuList from "./menuList" import Dept from "../../models/beta/Dept" import User from "../../models/beta/User" const angleDownIcon = "" const searchIcon = "" const clearIcon = "" export const userList = { view: function(vnode) { Dept.current = _.find(Dept.list, function(d) {return d.id == vnode.attrs.id}) Dept.current.users = _.filter(User.list, function(u) {return u.dept == Dept.current.id}) return [ m(menuList, {title: Dept.current.name, list: Dept.list}), m(".wrapper-body", { style: { display: "flex", flexFlow: "row wrap", margin: "0 auto", paddingTop: "64px" } }, _.filter(Dept.current.users, function(u) {return u.super}).map(function(user) { return m(superList, {user}) })) ] } } export const userAll = { oninit: function(vnode) { var show = stream(false) var search = "" vnode.state = {show, search} }, view: function(vnode) { var state = vnode.state var show = state.show() var search = state.search return [ m(menuList, {title: "User List", list: Dept.list}), m(".wrapper-body", { style: { display: "flex", flexFlow: "row wrap", margin: "0 auto", paddingTop: "64px" } }, [ m(Search, { style: { margin: "1em" }, textfield: { label: "Search", value: state.search, onChange: function({value}) { state.search = value } }, before: m(Shadow), buttons: { none: { before: m(IconButton, { icon: {svg: m.trust(searchIcon)}, inactive: true }), after: m(IconButton, { icon: {svg: m.trust(clearIcon)}, events: { onclick: function() { state.search = "" } } }) }, focus: { before: m(IconButton, { icon: {svg: m.trust(searchIcon)}, inactive: true }), after: m(IconButton, { icon: {svg: m.trust(clearIcon)}, events: { onclick: function() { state.search = "" } } }) }, dirty: { before: m(IconButton, { icon: {svg: m.trust(searchIcon)}, inactive: true }), after: m(IconButton, { icon: {svg: m.trust(clearIcon)}, events: { onclick: function() { state.search = "" } } }) }, focus_dirty: { before: m(IconButton, { icon: {svg: m.trust(searchIcon)}, inactive: true }), after: m(IconButton, { icon: {svg: m.trust(clearIcon)}, events: { onclick: function() { state.search = "" } } }) } } }), User.list.map(function(user) { return m(superList, {user}) }) ]) ] } } const superList = { oninit: function(vnode) { var show = stream(false) vnode.state = {show} }, view: function(vnode) { var state = vnode.state var show = state.show() var user = vnode.attrs.user return m(Card, { style: { flexBasis: "100%", webkitTransition: "all .2s cubic-bezier(0, 0, .6, 1)", mozTransition: "all .2s cubic-bezier(0, 0, .6, 1)", oTransition: "all .2s cubic-bezier(0, 0, .6, 1)", transition: "all .2s cubic-bezier(0, 0, .6, 1)", }, content: [{ text: { content: [ m(ListTile, { front: m(Icon, { avatar: true, size: "large", src: "../../img/yayasan.png" }), title: user.name, subContent: show ? m("div", { style: {fontSize: "smaller", marginTop: "1em"} }, [ m("div", [ "Alamat: ", user.address ]), m("div", [ "TTL: ", user.birth ]), m("div", [ "Telp.: ", user.phone ]), m("div", [ "Email: ", user.mail ]), m("div", [ "Tgl. Masuk: ", user.workEntry ]), m("div", [ "Lama Kerja: ", user.workPeriod ]), m("div", [ "Pendidikan: ", user.education ]) ]) : null }), m("div", { style: {textAlign: "center"} }, m(Icon, { element: "a", svg: {content: m.trust(angleDownIcon), style: {color: "rgb(0, 145, 234)"}}, style: { // opacity: ".5", cursor: "pointer", borderRadius: "50%", transform: show ? "rotateX(180deg)" : "rotateX(0)", webkitTransition: "all .25s linear", mozTransition: "all .25s linear", oTransition: "all .25s linear", transition: "all .25s linear" }, events: { onclick: function() { state.show(!state.show()) } } })), show ? _.filter( Dept.current.users, function(u) {return !u.super} ).map(function(staff) {return m(staffList, {staff})}) : null ] } }] }) } } const staffList = { oninit: function(vnode) { var peek = stream(false) vnode.state = {peek} }, view: function(vnode) { var state = vnode.state var peek = state.peek() var staff = vnode.attrs.staff return m(Card, { style: { width: "100%", webkitTransition: "all .1s cubic-bezier(0, 0, .6, 1)", mozTransition: "all .1s cubic-bezier(0, 0, .6, 1)", oTransition: "all .1s cubic-bezier(0, 0, .6, 1)", transition: "all .1s cubic-bezier(0, 0, .6, 1)", }, content: [{ text: { content: [ m(ListTile, { front: m(Icon, { avatar: true, size: "large", src: "../../img/yayasan.png" }), title: staff.name, subContent: peek ? m("div", { style: {fontSize: "smaller", marginTop: "1em"} }, [ m("div", [ "Alamat: ", staff.address ]), m("div", [ "TTL: ", staff.birth ]), m("div", [ "Telp.: ", staff.phone ]), m("div", [ "Email: ", staff.mail ]), m("div", [ "Tgl. Masuk: ", staff.workEntry ]), m("div", [ "Lama Kerja: ", staff.workPeriod ]), m("div", [ "Pendidikan: ", staff.education ]) ]) : null }), m("div", { style: {textAlign: "center"} }, m(Icon, { element: "a", svg: {content: m.trust(SVGAngleDown)}, style: { opacity: ".5", cursor: "pointer", borderRadius: "50%", transform: peek ? "rotateX(180deg)" : "rotateX(0)", webkitTransition: "all .25s linear", mozTransition: "all .25s linear", oTransition: "all .25s linear", transition: "all .25s linear" }, events: { onclick: function() { state.peek(!state.peek()) } } })) ] } }] }) } }