uniface lectures webinar - building responsive applications with uniface: development

31

Upload: uniface

Post on 06-Apr-2017

175 views

Category:

Software


11 download

TRANSCRIPT

Page 1: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development
Page 2: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Uniface Responsive Development (2 of 3)

David Akerman – Solution Consultant

Page 3: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

AgendaDynamic Server Page (DSP) Coding RecapUser Interface TechniquesDemo WebStart ApplicationCode Walkthrough

Page 4: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Coding DSP’s

Page 5: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Javascript API

Page 6: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Comparing ProcScript vs. JavaScriptServer <Detail> trigger- button clicked

trigger detailpublic web webmessage "Button clicked" return 0end; trigger

Also onFocus, onBlur etc. in Extended Triggers

Browser Extended trigger- editbox changedwebtrigger onChangejavascript

alert(this.getValue());endjavascriptend ; trigger

Page 7: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Comparing ProcScript vs. JavaScript OperationsServer Operations

operation Updatepublic webparams

string pOptions: INendparams ; ProcScript Code return 0end ; Update

Browser Operations

weboperation Updateparams

string pOptions: INendparamsjavascript

// JavaScript codeendjavascriptend ; Update

Page 8: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Activating OperationsCall weboperation from server (queued)

webactivate $instancename.save()

Call server operation from browser (asynchronous)this.getInstance().activate("save");

- use promises to control flow

Page 9: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

operation getLocationpublic webparams string address : in numeric latitude : inout numeric longitude: inoutendparams call CalcCoordinates(address, latitude, longitude)end ; getLocation

Promiseswebtrigger onClickjavascriptthis.getInstance().activate("getLocation",address,null,null) .then( function(out){

google.maps.locate(out.args[1], out.args[2]); }, function(e) { alert("Error getting the location !"); } );endjavascript

Get Location from GoogleJavaScript Activation Example

41

2

3

Browser

Server

Get Location Button

Page 10: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Scope

Controls data sent & received between browser & serverScoping operations block, prevent race conditions

output input

trigger detailpublic webscope input output operation AnotherDSP.showendscope activate "AnotherDSP".show() return 0end; trigger

Page 11: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Dynamic Scopeoperation storeDatapublic webscope input output operation myInstanceList().storeendscopevariables string vInstList, vInstNameendvariables vInstList = $replace(MODIFIED_INSTANCES, 1, ";", ";", -1) forlist vInstName in vInstList newinstance "SUB_DSP", vInstName activate vInstName.store() endfor end ; storeData

output input

weboperation myInstanceList() returns

JavaScript array of Instance Names

Page 12: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

HTML 5 widgets: bound error labels

Field validation error handling when the user tabs or clicks away from a field.Associate an error label via the ID attribute with prefix ‘uflderror:’

Page 13: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

ValidationUse JavaScript for non-declarative browser checks:

Always validate on server!

Page 14: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

CSS Classes

<input id="ufld:search.criteria.ui" type="text" class="form-control" placeholder="Search...">

$fieldproperties("SEARCH.CRITERIA") = "html:class=form-control"

$fieldproperties("SELECT.BUTTON") = "html:class=btn btn-primary btn-lg"

javascript fld.setProperty("html:class", "form-control");endjavascript

Modifying Properties

Page 15: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

CSS class:classname vs. html:class

putitem/id $FieldPropertes("select.buttons"), "class:btn-lg",

"true"

putitem $FieldPropertes("select.buttons"), "!class:btn-lg"

javascript

field.setProperty("!class:btn-lg");

endjavascript

putitem/id $OccProperties("order"), "class:selected", "true"

putitem/id $EntityProperties("order"), "class:empty", "true"

Use class:classname property instead of html:class to change individual classes:

Page 16: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

CSS Attributes

Add Attributeputitem/id $OccProperties("ORDER"),"html:data-selected", "true"

HTML<table id="uent:ORDER.POS" class="table table-hover"> <tbody> <tr id="uocc:ORDER.POS" data-selected> <td><span id="ufld:CODE.ORDER.POS">Code</span></td> <td><span id="ufld:DESCR.ORDER.POS">Name</span></td> </tr> </tbody></table>

JavaScript Findvar elements = document.querySelectorAll('tr[data-selected]');jQuery: $('tr[data-selected]').each(…) or $('tr[data-selected]')[0];

Page 17: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

HTML 5 Widgets: Known Issueshttp://unifaceinfo.com/fixes-updates/

Bug #31084: HTML 5 control Reconnect failures ($procerror -259)Workaround: datatype=string in usys.ini webwidgets

[webwidgets]EditBox=htmlinput(html:type=text;detail=dblclick;datatype=string)DropDownList=htmlselect(html:size=1;datatype=string)ListBox=htmlselect(html:size=3;datatype=string)CheckBox=htmlinput(html:type=checkbox;datatype=string)

Bug #31422: Date display YYYY-MM-DDDatetime field empty after update occurrence

Workaround: datatype=string in field widget more properties

Page 18: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

UI Techniques

Page 19: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

User Interface TechniquesMessaging & Error handlingResponsivenessTabsModality & Overlays NavigationIcons Data Paging

Page 20: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Tabs

All content in one DSPe.g. BOOTTABSEach tab contained by div element• Hide with style display:none

Optional DspContainers

Page 21: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Modality - CSS“Lightbox” effect via CSS• Hidden dialog (html display:none)

• To show:• Unhide (display:block)• Change CSS z-index, position, background-color, opacity etc.

• CSS libraries typically provide CSS classes and JavaScript methodse.g. .modal() + .hide()

Page 22: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Modality – Sample ImplementationCreate a DSP to handle modal display• Show() method to load a DSP in container• Adds re-usable functionality (e.g. title, buttons, callback)

Paint a DSPContainer field on your main page• Set initial value to load above modal controller DSP

Call methods in other DSP’s (e.g. SAMPLE_MODAL)activate "<MODAL_DSP>".show(“Confirmation", vMessage, vInstanceName, "Yes,No", %\ $instancename, “confirmCallback")return 0

Page 23: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Data PagingUse DBMS driver read features:

offsetmaxhits

See:Help Topic:“Data Paging in Web Applications”Sample on unifaceinfo.com

Page 24: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Using Icon Fonts – Attributes Only

<html><head> <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /></head><body> <i id="ufld:btn_home.buttons.ui" class="fa fa-home fa-fw"></i></body></html>

Page 25: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Using Icon Fonts – Modelled ButtonsUniface button HTML

<input id="ufld:RET.BUTTONS.UI" type="button" class="btn btn-primary fa" value="Button" />

#defines; fa-refresh – see font-awesome cheatsheet#define B_BROWSE_ICON = &#xf021

Format trigger#if (<$componentType> = D)$format = $concat($string("<B_BROWSE_ICON>; "), "Retrieve")#endif

Page 26: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Considerations

Page 27: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

SecuritySensitive data – can it be tampered with?• URL, Cookie, Hidden Fields can be modified• If protection needed, hash encode and/or use server-side storage• Always validate on server• Use SSL

Uniface prevents modification of non-editable fields• Requires $SERVER_SECRET in .asn

Check user is authenticatedUse “public web” for browser activated operations onlyMore information in Help – see “Web Security Guidelines”

Page 28: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Code Performance TipsUse Javascript API to move logic to browserAttach & Detach operations• Clear data when removed from DspContainer?

Reduce data synchronisation• Only paint user interface entities• Business logic in services• DSP containers• Scoping

Reduce State ManagementCache!

Page 29: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Resources Uniface Help: Tutorials Uniface Training uniface.info - Samples, Forums, Blogs

youtube.com/uniface github.com/uniface- Frameworks & Tools

Page 30: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Walkthrough:WebStart App

Page 31: Uniface Lectures Webinar - Building Responsive Applications with Uniface: Development

Thank You& Questions