首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SAP CRM Fiori应用My Note的OData调用设计

SAP CRM Fiori应用My Note的OData调用设计

作者头像
Jerry Wang
发布2019-05-31 09:51:41
4710
发布2019-05-31 09:51:41
举报

版权声明:本文为博主汪子熙原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1439490

Sent: Monday, December 22, 2014 4:14 PM

这里简单把现有的UI逻辑总结一下:

Notes Tab UI:

           <IconTabFilter id="tab_notes" icon="sap-icon://notes"
                key="Notes" text="{i18n>NOTES}" iconColor="Neutral">
                <FeedInput id="notesList" textMaxLength="1000" text="{json>Content}"
                     post="_handleAddNote" showIcon="true" icon="{json>icon}" maxLines="3">
                </FeedInput>
                <List id="listItem" showSeparators="Inner" growing="true"     growingThreshold="4" growingScrollToLoad="false"
                     items="{json>/OpportunityNotesSet}">
                     <FeedListItem sender="{path : 'json>Creator'}"     senderActive="false"
                          timestamp="{path:'json>CreatedAt' , formatter: 'cus.crm.opportunity.util.Formatter.notesDateFormatter'}"
                           text="{path : 'json>Content'}" />
                </List>
           </IconTabFilter>

标签表示Tab Bar上的一个Tab, 表示新输入Note的控件, 表示每一条需要显示的Note。

显示的每一条Note是绑定在listItem model的OpportunityNoteSet属性上,每次点击Note Tab的时候,会执行S3.controller.js中的notesTabSelected()方法:

notesTabSelected : function(){
               var oModel = this.getView().getModel();             
          this.byId("listItem").setNoDataText(sap.ca.scfld.md.app.Application.getImpl().getResourceBundle().getText('LOADING_TEXT'));
               this.byId('listItem').getModel('json').oData.OpportunityNotesSet = [];
               this.byId('listItem').getModel('json').updateBindings();       
               oModel.read(this.sPath, null, [ "$expand=Notes" ], true,
// 在这里发起OData的调用,http://localhost:8080/sap/opu/odata/sap/CRM_OPPORTUNITY/Opportunities(guid'0090FA0D-8D72-1ED3-98C7-DC2E25228BC4')?$expand=Notes
                          jQuery.proxy(function(odata, response) {
                               var tab = this.getView().byId("listItem");
                               var oJSONModel = tab.getModel("json");
                               var oData = oJSONModel.oData;
                               // 返回的结果绑定到listItem model的OpportunityNotesSet上
                               oData.OpportunityNotesSet = response.data.Notes.results;
                               if(oData.OpportunityNotesSet.length == 0){                                                                                                                this.byId("listItem").setNoDataText(sap.ca.scfld.md.app.Application.getImpl().getResourceBundle().getText('NONOTES'));
                               }
                               // 用新返回的数据刷新UI
                               oJSONModel.updateBindings();                          
                           },this),
                          jQuery.proxy(function(oError){
                               this.handleErrors(oError);
                          },this)
);
          },

每次添加一条Note的时候会调用FeedInput控件上绑定的post事件对应的_handleAddNote()方法:

                     <FeedInput id="notesList" textMaxLength="1000" text="{json>Content}"
                post="_handleAddNote" showIcon="true" icon="{json>icon}" maxLines="3">
           </FeedInput>
          _handleAddNote : function(oEvent) {
               // 获取输入的内容
               var sText = oEvent.getParameter("value");
               if (sText) {
                    var that = this;
                    var oModel = this.getView().getModel();                                   
                    var headerGuid = this.byId('info').getModel('json').getData().Guid;
                    var oEntry = {
                          HeaderGuid : headerGuid,
                          Content : sText
                    };

                    // 创建一条新的Note http://localhost:8080/sap/opu/odata/sap/CRM_OPPORTUNITY/OpportunityNotesSet                                
                    oModel.create('/OpportunityNotesSet',
                          oEntry,
                          null,
                          jQuery.proxy(function() {
                               var that = this;
                               // 创建新的Note成功之后的回调方法里面重新获取新的Note List, 然后绑定到model的OpportunityNotesSet上
                               oModel.read( that.sPath, null, [ "$expand=Notes" ],true,
function(odata,response){
 that.byId('listItem').setModel(new sap.ui.model.json.JSONModel({OpportunityNotesSet: odata.Notes.results}),"json");
                                     });                                                            
                               }, this),
                          function(oMessage) {
                               that.displayResponseErrorMessage(oMessage,
                          sap.ca.scfld.md.app.Application.getImpl().getResourceBundle().getText('SAVE_FAILED'));
                          }
);
               }
          },

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年02月03日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Sent: Monday, December 22, 2014 4:14 PM
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档