/** * @fileName : DeviceUc.java * @description : * @version : 1.0 * @date: 26-Feb-2015 @Author tumbalam @Reviewer: */ public class DeviceUc extends Composite { private static DeviceUcUiBinder uiBinder = GWT.create(DeviceUcUiBinder.class); @UiField HTMLPanel ipadSectiondiv, androidSectiondiv; @UiField HTMLPanel msgPanel, msglinkPanel, gooruPanel, ednovoPanel, appstorePanel; @UiField com.google.gwt.user.client.ui.Image closeIpadBtn, closeAndriodBtn; SimplePanel wrapperPanel = null; HeaderUc headerUc = null; @UiField Anchor viewAnchor; MessageProperties i18n = GWT.create(MessageProperties.class); interface DeviceUcUiBinder extends UiBinder<Widget, DeviceUc> {} Boolean isIpad = !!Navigator.getUserAgent().matches("(.*)iPad(.*)"); Boolean isAndriod = !!Navigator.getUserAgent().matches("(.*)Android(.*)"); Boolean isWinDskp = !!Navigator.getUserAgent().matches("(.*)NT(.*)"); public DeviceUc(SimplePanel wrapperPanel, HeaderUc headerUc) { initWidget(uiBinder.createAndBindUi(this)); this.headerUc = headerUc; this.wrapperPanel = wrapperPanel; androidSectiondiv.getElement().setId("pnlAndroidSectiondiv"); ipadSectiondiv.getElement().setId("pnlIpadSectiondiv"); msglinkPanel.getElement().setId("pnlMsglinkPanel"); msgPanel.getElement().setId("pnlMsgPanel"); closeAndriodBtn.getElement().setId("imgCloseAndriodBtn"); closeIpadBtn.getElement().setId("imgCloseIpadBtn"); gooruPanel.getElement().setId("pnlGooruPanel"); ednovoPanel.getElement().setId("pnlEdnovoPanel"); appstorePanel.getElement().setId("pnlAppstorePanel"); viewAnchor.getElement().setId("lnkViewAnchor"); setUiText(); if (isIpad && !StringUtil.IPAD_MESSAGE_Close_Click) { ipadSectiondiv.setVisible(true); androidSectiondiv.setVisible(false); ipadSectiondiv.getElement().setAttribute("style", "margin-top:-20px;"); wrapperPanel.getElement().setAttribute("style", "margin-top:0px;"); headerUc.getElement().getFirstChildElement().setAttribute("style", "position:relative;"); } else if (isAndriod && !StringUtil.IPAD_MESSAGE_Close_Click) { ipadSectiondiv.setVisible(false); androidSectiondiv.setVisible(true); androidSectiondiv.getElement().setAttribute("style", "margin-top:-20px;"); wrapperPanel.getElement().setAttribute("style", "margin-top:0px;"); headerUc.getElement().getFirstChildElement().setAttribute("style", "position:relative;"); } } @UiHandler("closeIpadBtn") public void onIpadCloseClick(ClickEvent clickEvent) { ipadSectiondiv.setVisible(false); StringUtil.IPAD_MESSAGE_Close_Click = true; androidSectiondiv.setVisible(false); wrapperPanel.getElement().setAttribute("style", "margin-top:36px;"); headerUc.getElement().getFirstChildElement().setAttribute("style", "position:fixed;"); LibraryView.onClosingAndriodorIpaddiv(); ShelfListView.onClosingAndriodorIpaddiv(); ShelfView.onClosingAndriodorIpaddiv(); DiscoverToolTip.onclickOfAndriodorIpadcloseDiv(); } @UiHandler("closeAndriodBtn") public void onAndriodCloseClick(ClickEvent clickEvent) { ipadSectiondiv.setVisible(false); StringUtil.IPAD_MESSAGE_Close_Click = true; androidSectiondiv.setVisible(false); wrapperPanel.getElement().setAttribute("style", "margin-top:36px;"); headerUc.getElement().getFirstChildElement().setAttribute("style", "position:fixed;"); LibraryView.onClosingAndriodorIpaddiv(); ShelfListView.onClosingAndriodorIpaddiv(); ShelfView.onClosingAndriodorIpaddiv(); DiscoverToolTip.onclickOfAndriodorIpadcloseDiv(); } /** * @function setUiText * @created_date : 26-Feb-2015 * @description * @parm(s) : * @return : void * @throws : <Mentioned if any exceptions> */ public void setUiText() { msgPanel.getElement().setInnerHTML(i18n.GL1983()); msgPanel.getElement().setAttribute("alt", i18n.GL1983()); msgPanel.getElement().setAttribute("title", i18n.GL1983()); msglinkPanel.getElement().setInnerHTML(i18n.GL1984()); msglinkPanel.getElement().setAttribute("alt", i18n.GL1984()); msglinkPanel.getElement().setAttribute("title", i18n.GL1984()); gooruPanel.getElement().setInnerHTML(i18n.GL0733()); gooruPanel.getElement().setAttribute("alt", i18n.GL0733()); gooruPanel.getElement().setAttribute("title", i18n.GL0733()); ednovoPanel.getElement().setInnerHTML(i18n.GL1985()); ednovoPanel.getElement().setAttribute("alt", i18n.GL1985()); ednovoPanel.getElement().setAttribute("title", i18n.GL1985()); appstorePanel.getElement().setInnerHTML(i18n.GL1986()); appstorePanel.getElement().setAttribute("alt", i18n.GL1986()); appstorePanel.getElement().setAttribute("title", i18n.GL1986()); viewAnchor.setText(i18n.GL1428()); viewAnchor.getElement().setAttribute("alt", i18n.GL1428()); viewAnchor.getElement().setAttribute("title", i18n.GL1428()); } }
/** This is the entry point method. */ public void onModuleLoad() { // Pointer to CSS manager. It has to go first! GWT.<Resources>create(Resources.class).css().ensureInjected(); // Log messages logger.fine("Loading eMarkingWeb interface"); logger.fine(Navigator.getPlatform()); logger.fine(Navigator.getUserAgent()); logger.fine(Navigator.getAppName()); logger.fine(Navigator.getAppCodeName()); logger.fine(Navigator.getAppVersion()); // List of errors after trying to initialize ArrayList<String> errors = new ArrayList<String>(); // Get id for eMarkingWeb's DIV tag final String eMarkingDivId = "emarking"; if (RootPanel.get(eMarkingDivId) == null) { errors.add("Can not initalize. eMarkingWeb requires an existing DIV tag with id: emarking."); return; } RootPanel.get(eMarkingDivId).add(new Label("Loading")); int draftId = 0; int preferredWidth = 860; boolean showRubric = true; boolean showColors = false; try { // First, if there's a URL parameter, replace the value if (Window.Location.getParameter("id") != null) { draftId = Integer.parseInt(Window.Location.getParameter("id")); } // Validate that the submission id is a positive integer if (draftId <= 0) { errors.add("Submission id must be a non negative integer."); } String cookie_width = Cookies.getCookie("emarking_width"); if (cookie_width != null) { preferredWidth = Integer.parseInt(cookie_width); } // Validate that the preferredWidth is a positive integer greater than 10 if (preferredWidth <= 10) { errors.add("Preferred width should be a positive integer greater than 10."); } // Validate that the preferredWidth is a positive integer greater than 10 if (preferredWidth <= 10) { errors.add("Preferred width should be a positive integer greater than 10."); } String cookie_showrubric = Cookies.getCookie("emarking_showrubric"); if (cookie_showrubric != null) { showRubric = Integer.parseInt(cookie_showrubric) == 1; } String cookie_showcolors = Cookies.getCookie("emarking_showcolors"); if (cookie_showcolors != null) { showColors = Integer.parseInt(cookie_showcolors) == 1; } logger.fine( "ShowRubric: " + showRubric + " Show colors:" + showColors + " Preferred width:" + preferredWidth); } catch (Exception e) { logger.severe(e.getMessage()); errors.add( "Error in HTML for eMarkingWeb can not initalize. Invalid submissionId value (must be integer)."); } // Read div attribute for readonly String moodleurl = null; if (RootPanel.get(eMarkingDivId).getElement().getAttribute("moodleurl") != null) moodleurl = RootPanel.get(eMarkingDivId).getElement().getAttribute("moodleurl"); logger.fine("Moodle ajax url: " + moodleurl); if (moodleurl == null) errors.add("Invalid Moodle ajax url"); // If there are errors die with a configuration message if (errors.size() > 0) { Label errorsLabel = new Label(); String text = ""; for (int i = 0; i < errors.size(); i++) { text += "\n" + errors.get(i); } errorsLabel.setText(text); errorsLabel.setTitle("Fatal error while initializing eMarking-Web"); RootPanel.get(eMarkingDivId).clear(); RootPanel.get(eMarkingDivId).add(errorsLabel); } else { // Set eMarking's main interface submission id according to HTML MarkingInterface.setDraftId(draftId); EMarkingConfiguration.setShowRubricOnLoad(showRubric); EMarkingConfiguration.setColoredRubric(showColors); // Ajax URL in moodle AjaxRequest.moodleUrl = moodleurl; // Automagically resize popup to use most of the window int width = screenWidth(); int height = screenHeight(); // Preferred width can not be bigger than the screen if (width < preferredWidth) { preferredWidth = width; } // Resize the popup window and move it to the top left corner Window.resizeTo(preferredWidth, height); Window.moveTo(0, 0); // Initialize eMarking's interface markingInterface = new MarkingInterface(); markingInterfacetwo = new MarkingInterface(); // Add eMarking to the browser RootPanel.get(eMarkingDivId).clear(); RootPanel.get(eMarkingDivId).add(markingInterface); RootPanel.getBodyElement().focus(); } }