Advertisement
Guest User

MessageBox

a guest
Aug 27th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sx.ui.MessageBox = Ext.extend(
  2. Ext.panel.Panel, {
  3.     constructor: function (config) {
  4.         var searchParams = {
  5.             read: "all",
  6.             startTime: null,
  7.             stopTime: null,
  8.             deleteIds: null
  9.         };
  10.         searchParams.box = config.messageBox;
  11.         var myself = this;
  12.         this.fromText = Ext.create("Ext.form.field.Text", {
  13.             text: "",
  14.             fieldLabel: sx.label.messageFrom
  15.         });
  16.         this.toText = Ext.create("Ext.form.field.Text", {
  17.             text: "",
  18.             fieldLabel: sx.label.messageTo
  19.         });
  20.         this.timeText = Ext.create("Ext.form.field.Text", {
  21.             text: "",
  22.             fieldLabel: sx.label.messageTime
  23.         });
  24.         this.titleText = Ext.create("Ext.form.field.Text", {
  25.             text: "",
  26.             fieldLabel: sx.label.messageTopic
  27.         });
  28.         this.messageText = Ext.create(
  29.             "Ext.form.field.TextArea", {
  30.             hideLabel: true,
  31.             height: 420,
  32.             region: "south"
  33.         });
  34.         var allButton = Ext.create("Ext.button.Button", {
  35.             text: sx.label.messageAll,
  36.             pressed: true,
  37.             toggleGroup: "sx.ui.MessageInbox",
  38.             enableToggle: true,
  39.             handler: function (but) {
  40.                 if (but.pressed) {
  41.                     searchParams.read = "ALL";
  42.                     common.updateStore(myself.store,
  43.                     searchParams)
  44.                 }
  45.             }
  46.         });
  47.         var readButton = Ext.create("Ext.button.Button", {
  48.             text: sx.label.messageRead,
  49.             toggleGroup: "sx.ui.MessageInbox",
  50.             enableToggle: true,
  51.             handler: function (but) {
  52.                 if (but.pressed) {
  53.                     searchParams.read = "READ";
  54.                     common.updateStore(myself.store,
  55.                     searchParams)
  56.                 }
  57.             }
  58.         });
  59.         var unReadButton = Ext.create("Ext.button.Button", {
  60.             text: sx.label.messageUnread,
  61.             toggleGroup: "sx.ui.MessageInbox",
  62.             enableToggle: true,
  63.             handler: function (but) {
  64.                 if (but.pressed) {
  65.                     searchParams.read = "UNREAD";
  66.                     common.updateStore(myself.store,
  67.                     searchParams)
  68.                 }
  69.             }
  70.         });
  71.         var dateStart = Ext.create("Ext.form.field.Date", {
  72.             hideLabel: true,
  73.             editable: true,
  74.             enableKeyEvents: false,
  75.             size: 10,
  76.             width: 100,
  77.             listeners: {
  78.                 change: function (field, newValue, oldValue,
  79.                 eOpts) {
  80.                     searchParams.startTime = newValue;
  81.                     sx.server.updateStore(myself.store,
  82.                     searchParams)
  83.                 }
  84.             }
  85.         });
  86.         var dateStop = Ext.create("Ext.form.field.Date", {
  87.             hideLabel: true,
  88.             editable: true,
  89.             size: 10,
  90.             width: 100,
  91.             enableKeyEvents: false,
  92.             listeners: {
  93.                 change: function (field, newValue, oldValue,
  94.                 eOpts) {
  95.                     searchParams.stopTime = newValue;
  96.                     sx.server.updateStore(myself.store,
  97.                     searchParams)
  98.                 }
  99.             }
  100.         });
  101.         var searchButton = Ext.create("Ext.button.Button", {
  102.             text: sx.label.search,
  103.             handler: function () {
  104.                 myself.paging.moveFirst()
  105.             }
  106.         });
  107.         var deleteButton = Ext.create("Ext.button.Button", {
  108.             text: sx.label.messageDelete,
  109.             handler: function () {
  110.                 var records = myself.messageModel.getSelection();
  111.                 if (records.length <= 0) {
  112.                     return
  113.  
  114.                 }
  115.                 searchParams.deleteIds = [];
  116.                 for (var i = 0; i < records.length; i++) {
  117.                     searchParams.deleteIds[i] = records[i].get("id")
  118.                 }
  119.                 sx.server.updateStore(myself.store,
  120.                 searchParams);
  121.                 myself.paging.doRefresh();
  122.                 searchParams.deleteIds = null
  123.             }
  124.         });
  125.         this.msg = new sx.ui.MessagePanel({
  126.             border: false
  127.         });
  128.         this.msgWin = Ext.create("Ext.window.Window", {
  129.             closable: true,
  130.             closeAction: "hide",
  131.             modal: true,
  132.             width: 720,
  133.             height: 240,
  134.             items: this.msg,
  135.             buttons: [{
  136.                 text: sx.label.messageSend,
  137.                 handler: function () {
  138.                     myself.msg.sendMsg(myself.msgWin)
  139.                 }
  140.             }, {
  141.                 text: sx.label.cancel,
  142.                 handler: function () {
  143.                     myself.msgWin.close()
  144.                 }
  145.             }]
  146.         });
  147.         var topicsTBar = ["-"];
  148.         var buttons = [];
  149.         if (config.messageBox == "I") {
  150.             topicsTBar.push(allButton);
  151.             topicsTBar.push(readButton);
  152.             topicsTBar.push(unReadButton);
  153.             topicsTBar.push("-");
  154.             buttons.push({
  155.                 text: sx.label.messageReply,
  156.                 handler: function () {
  157.                     var record = myself.messageModel.getSelection();
  158.                     if (record.length > 0) {
  159.                         try {
  160.                             myself.msgWin.show();
  161.                             myself.msg.showContent({
  162.                                 id: record[0].data.fromId,
  163.                                 name: record[0].data.fromName
  164.                             });
  165.                             myself.msg.topicField.setValue(sx.label.messageReply + ': "' + common.digest(
  166.                             record[0].data.topic,
  167.                             25) + '" from ' + record[0].data.fromName + "\n");
  168.                             myself.msgWin.setTitle(sx.label.mgmtMemberActionSendMsg)
  169.                         } catch (e) {}
  170.                     } else {
  171.                         Ext.Msg.alert(
  172.                         sx.label.systemMessage,
  173.                         sx.label.messageSelectItem)
  174.                     }
  175.                 }
  176.             })
  177.         }
  178.         topicsTBar.push({
  179.             xtype: "label",
  180.             text: sx.label.messageTime + "   " + sx.label.from
  181.         });
  182.         topicsTBar.push(dateStart);
  183.         topicsTBar.push({
  184.             xtype: "label",
  185.             text: "    " + sx.label.to
  186.         });
  187.         topicsTBar.push(dateStop);
  188.         topicsTBar.push("-");
  189.         topicsTBar.push(searchButton);
  190.         topicsTBar.push("-");
  191.         topicsTBar.push("->");
  192.         topicsTBar.push("-");
  193.         topicsTBar.push(deleteButton);
  194.         topicsTBar.push("-");
  195.         this.backToMList = Ext.create("Ext.button.Button", {
  196.             text: sx.label.backToMsgList,
  197.             handler: function () {
  198.                 myself.mDetail.hide();
  199.                 myself.paging.moveFirst();
  200.                 myself.mList.show()
  201.             }
  202.         });
  203.         this.mDetail = Ext.create("Ext.panel.Panel", {
  204.             region: "south",
  205.             margins: "0 4 4 4",
  206.             layout: "border",
  207.             border: false,
  208.             height: 530,
  209.             padding: "0 5 0 5",
  210.             split: true,
  211.             buttons: buttons,
  212.             hidden: true,
  213.             fieldDefaults: {
  214.                 labelWidth: 55
  215.             },
  216.             items: [{
  217.                 xtype: "container",
  218.                 region: "north",
  219.                 border: false,
  220.                 height: 20,
  221.                 autoScroll: false,
  222.                 items: [this.backToMList]
  223.             }, {
  224.                 xtype: "container",
  225.                 region: "center",
  226.                 border: false,
  227.                 layout: "column",
  228.                 height: 56,
  229.                 autoScroll: false,
  230.                 items: [{
  231.                     xtype: "container",
  232.                     columnWidth: 2 / 4,
  233.                     items: [this.titleText, this.timeText]
  234.                 }, {
  235.                     xtype: "container",
  236.                     columnWidth: 2 / 4,
  237.                     items: [this.fromText, this.toText]
  238.                 }]
  239.             },
  240.             this.messageText]
  241.         });
  242.         this.store = sx.server.getMessageTopicsStore(searchParams);
  243.         this.store.pageSize = sx.data.member == undefined || sx.data.member.setting == undefined ? sx.server.pageSize : sx.data.member.setting.pageSize;
  244.         this.messageModel = Ext.create(
  245.             "Ext.selection.CheckboxModel", {
  246.             listeners: {
  247.                 select: function (model,
  248.                 record, index, eOpts) {
  249.                     var toMsgUserL = common.getLabel(
  250.                         "sx.label.msgUser",
  251.                     record.get("toName"));
  252.                     var fromMsgUserL = common.getLabel(
  253.                         "sx.label.msgUser",
  254.                     record.get("fromName"));
  255.                     if (!toMsgUserL || toMsgUserL == "unknown") {
  256.                         myself.toText.setValue(record.get("toName"))
  257.                     } else {
  258.                         myself.toText.setValue(toMsgUserL);
  259.                         record.set("toName",
  260.                         toMsgUserL)
  261.                     }
  262.                     if (!fromMsgUserL || fromMsgUserL == "unknown") {
  263.                         myself.fromText.setValue(record.get("fromName"))
  264.                     } else {
  265.                         myself.fromText.setValue(fromMsgUserL);
  266.                         record.set("fromName",
  267.                         fromMsgUserL)
  268.                     }
  269.                     myself.timeText.setValue(record.get("mTime"));
  270.                     myself.titleText.setValue(record.get("topic"));
  271.                     myself.messageText.setValue(record.get("message"));
  272.                     if (!record.get("read")) {
  273.                         sx.server.readMessage(
  274.                         record.get("id"),
  275.                         config.messageBox);
  276.                         record.set("read",
  277.                         true);
  278.                         record.commit()
  279.                     }
  280.                     myself.lockDetails();
  281.                     myself.mList.hide();
  282.                     myself.mDetail.show()
  283.                 },
  284.                 deselect: function () {
  285.                     myself.clearDetails()
  286.                 }
  287.             }
  288.         });
  289.         var sm = Ext.create("Ext.selection.CheckboxModel");
  290.         this.paging = Ext.create("Ext.PagingToolbar", {
  291.             beforePageText: "",
  292.             afterPageText: "/ {0} \u9875",
  293.             store: this.store,
  294.             displayInfo: true,
  295.             displayMsg: sx.label.messagePagingDisplay,
  296.             emptyMsg: sx.label.messagePagingEmpty
  297.         });
  298.         this.mList = Ext.create(
  299.             "Ext.grid.Panel", {
  300.             region: "center",
  301.             store: this.store,
  302.             selModel: this.messageModel,
  303.             margins: "4 4 0 4",
  304.             loadMask: true,
  305.             viewConfig: {
  306.                 stripeRows: true
  307.             },
  308.             columns: [{
  309.                 text: "",
  310.                 dataIndex: "read",
  311.                 width: 32,
  312.                 sortable: false,
  313.                 renderer: function (val) {
  314.                     var path = val ? "./image/outlook2003_icoRead.gif" : "./image/outlook2003_icoUnread.gif";
  315.                     return '<img src="' + path + '">'
  316.                 }
  317.             }, {
  318.                 text: sx.label.messageTopic,
  319.                 dataIndex: "topic",
  320.                 flex: 1,
  321.                 sortable: false,
  322.                 renderer: function (
  323.                 val, metaData,
  324.                 record) {
  325.                     if (record.get("read")) {
  326.                         return val
  327.                     } else {
  328.                         return "<b>" + val + "</b>"
  329.                     }
  330.                 }
  331.             }, {
  332.                 text: config.messageBox == "I" ? sx.label.messageFrom : sx.label.messageTo,
  333.                 dataIndex: config.messageBox == "I" ? "fromName" : "toName",
  334.                 width: 100,
  335.                 sortable: false,
  336.                 renderer: function (
  337.                 val, metaData,
  338.                 record) {
  339.                     if (!common.getLabel(
  340.                         "sx.label.msgUser",
  341.                     val) || common.getLabel(
  342.                         "sx.label.msgUser",
  343.                     val) == "unknown") {
  344.                         return val
  345.                     }
  346.                     return common.getLabel(
  347.                         "sx.label.msgUser",
  348.                     val)
  349.                 }
  350.             }, {
  351.                 text: sx.label.messageTime,
  352.                 dataIndex: "mTime",
  353.                 width: 120,
  354.                 align: "right",
  355.                 sortable: false
  356.             }],
  357.             tbar: topicsTBar,
  358.             bbar: this.paging
  359.         });
  360.         config.layout = "border", config.border = false;
  361.         config.items = [this.mList, this.mDetail];
  362.         config.itemId = "message-inbox";
  363.         sx.ui.MessageBox.superclass.constructor.apply(this, [config])
  364.     },
  365.     showContent: function () {
  366.         this.paging.moveFirst();
  367.         this.clearDetails()
  368.     },
  369.     clearDetails: function () {
  370.         this.fromText.setValue("");
  371.         this.toText.setValue("");
  372.         this.timeText.setValue("");
  373.         this.titleText.setValue("");
  374.         this.messageText.setValue("")
  375.     },
  376.     lockDetails: function () {
  377.         this.fromText.setReadOnly(true);
  378.         this.toText.setReadOnly(true);
  379.         this.timeText.setReadOnly(true);
  380.         this.titleText.setReadOnly(true);
  381.         this.messageText.setReadOnly(true)
  382.     }
  383. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement