[calendar] Created basic OBCalendarWidget Superclass and definition
authorDavid Baz Fayos <david.baz@openbravo.com>
Fri, 11 Jan 2013 00:59:06 +0100
changeset 19506 3c91850c93e5
parent 19505 c64e1099f893
child 19507 6b36d3051829
[calendar] Created basic OBCalendarWidget Superclass and definition
modules/org.openbravo.client.myob/src-db/database/sourcedata/OBKMO_WIDGET_CLASS.xml
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/CalendarWidgetProvider.java
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponentProvider.java
modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-calendar-widget.js
--- a/modules/org.openbravo.client.myob/src-db/database/sourcedata/OBKMO_WIDGET_CLASS.xml	Fri Jan 11 00:58:29 2013 +0100
+++ b/modules/org.openbravo.client.myob/src-db/database/sourcedata/OBKMO_WIDGET_CLASS.xml	Fri Jan 11 00:59:06 2013 +0100
@@ -63,6 +63,21 @@
 <!--E9DA175470B747268E09DEF5174FDD3A-->  <ACCESSLEVEL><![CDATA[3]]></ACCESSLEVEL>
 <!--E9DA175470B747268E09DEF5174FDD3A--></OBKMO_WIDGET_CLASS>
 
+<!--F41E327965084556BCF7EC7B271603AA--><OBKMO_WIDGET_CLASS>
+<!--F41E327965084556BCF7EC7B271603AA-->  <OBKMO_WIDGET_CLASS_ID><![CDATA[F41E327965084556BCF7EC7B271603AA]]></OBKMO_WIDGET_CLASS_ID>
+<!--F41E327965084556BCF7EC7B271603AA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F41E327965084556BCF7EC7B271603AA-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F41E327965084556BCF7EC7B271603AA-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F41E327965084556BCF7EC7B271603AA-->  <AD_MODULE_ID><![CDATA[2758CD25B2704AF6BBAD10365FC82C06]]></AD_MODULE_ID>
+<!--F41E327965084556BCF7EC7B271603AA-->  <TITLE><![CDATA[Calendar Widget]]></TITLE>
+<!--F41E327965084556BCF7EC7B271603AA-->  <JAVACLASS><![CDATA[org.openbravo.client.myob.CalendarWidgetProvider]]></JAVACLASS>
+<!--F41E327965084556BCF7EC7B271603AA-->  <HEIGHT><![CDATA[500]]></HEIGHT>
+<!--F41E327965084556BCF7EC7B271603AA-->  <ALLOW_ANONYMOUS_ACCESS><![CDATA[N]]></ALLOW_ANONYMOUS_ACCESS>
+<!--F41E327965084556BCF7EC7B271603AA-->  <ISSUPERCLASS><![CDATA[Y]]></ISSUPERCLASS>
+<!--F41E327965084556BCF7EC7B271603AA-->  <CAN_MAXIMIZE><![CDATA[Y]]></CAN_MAXIMIZE>
+<!--F41E327965084556BCF7EC7B271603AA-->  <ACCESSLEVEL><![CDATA[3]]></ACCESSLEVEL>
+<!--F41E327965084556BCF7EC7B271603AA--></OBKMO_WIDGET_CLASS>
+
 <!--FF8080812E144FAE012E1455F6020009--><OBKMO_WIDGET_CLASS>
 <!--FF8080812E144FAE012E1455F6020009-->  <OBKMO_WIDGET_CLASS_ID><![CDATA[FF8080812E144FAE012E1455F6020009]]></OBKMO_WIDGET_CLASS_ID>
 <!--FF8080812E144FAE012E1455F6020009-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/CalendarWidgetProvider.java	Fri Jan 11 00:59:06 2013 +0100
@@ -0,0 +1,48 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2013 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.myob;
+
+import org.apache.log4j.Logger;
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.client.kernel.KernelConstants;
+import org.openbravo.dal.service.OBDao;
+
+/**
+ * Responsible for creating the Calendar Widget.
+ * 
+ * @author dbaz
+ */
+public class CalendarWidgetProvider extends WidgetProvider {
+
+  public static final String WIDGETCLASS_PARAMETER = "WIDGET_CLASS";
+
+  private static final Logger log = Logger.getLogger(CalendarWidgetProvider.class);
+
+  @Override
+  public String generate() {
+    final WidgetURL widgetURL = (WidgetURL) OBDao.getFilteredCriteria(WidgetURL.class,
+        Restrictions.eq(WidgetURL.PROPERTY_WIDGETCLASS, getWidgetClass())).uniqueResult();
+    String url = widgetURL.getURL();
+    final String result = "isc.defineClass('" + KernelConstants.ID_PREFIX
+        + getWidgetClass().getId() + "', isc.OBCalendarWidget).addProperties({widgetId: '"
+        + getWidgetClass().getId() + "', calendarProps: " + url + "});";
+    return result;
+  }
+
+}
--- a/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponentProvider.java	Fri Jan 11 00:58:29 2013 +0100
+++ b/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoComponentProvider.java	Fri Jan 11 00:59:06 2013 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010-2012 Openbravo SLU
+ * All portions are Copyright (C) 2010-2013 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -71,6 +71,8 @@
         "web/org.openbravo.client.myob/js/ob-showparameter-widget.js", false));
     globalResources.add(createStaticResource(
         "web/org.openbravo.client.myob/js/ob-community-branding-widget.js", false));
+    globalResources.add(createStaticResource(
+        "web/org.openbravo.client.myob/js/ob-calendar-widget.js", false));
     globalResources.add(createStaticResource("web/org.openbravo.client.myob/js/ob-about-popup.js",
         false));
     globalResources.add(createStaticResource(
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-calendar-widget.js	Fri Jan 11 00:59:06 2013 +0100
@@ -0,0 +1,115 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2013 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+isc.ClassFactory.defineClass('OBCalendarWidget', isc.OBWidget);
+
+isc.OBCalendarWidget.addProperties({
+  widgetId: null,
+  widgetInstanceId: null,
+
+  createWindowContents: function () {
+    var layout, calendarProps = this.calendarProps;
+
+    if (!calendarProps) {
+      return isc.VStack.create({
+        members: [
+        isc.Label.create({
+          contents: 'This widget must have an associated URL pointing to the object with the calendar properties'
+        })]
+      });
+    }
+
+    if (this.viewMode === 'maximized' && calendarProps.maximizedDefaultViewName) {
+      calendarProps.defaultViewName = calendarProps.maximizedDefaultViewName;
+    } else if (calendarProps.restoredDefaultViewName) {
+      calendarProps.defaultViewName = calendarProps.restoredDefaultViewName;
+    }
+
+    layout = isc.VStack.create({
+      height: '100%',
+      width: '100%',
+      styleName: ''
+    });
+
+    if (calendarProps.isMultiCalendar) {
+      layout.addMember(isc.OBMultiCalendar.create({
+        calendarProps: calendarProps
+      }));
+    } else {
+      layout.addMember(isc.OBMultiCalendarCalendar.create(isc.addProperties(calendarProps, {})));
+    }
+
+    return layout;
+  },
+
+  refresh: function () {
+    this.members[1].members[0].members[0].initComponents();
+  },
+
+  maximize: function () {
+    OB.Layout.ViewManager.openView('OBCalendarWidgetView', {
+      tabTitle: this.title,
+      widgetInstanceId: this.dbInstanceId,
+      widgetId: this.widgetId,
+      parameters: this.parameters,
+      menuItems: this.menuItems
+    });
+  }
+});
+
+isc.ClassFactory.defineClass('OBCalendarWidgetView', isc.PortalLayout);
+
+isc.OBCalendarWidgetView.addProperties({
+  //Set PortalLayout common parameters
+  numColumns: 1,
+  showColumnMenus: false,
+  canDropComponents: false,
+
+  initWidget: function (args) {
+    var widgetInstance, i;
+    this.Super('initWidget', arguments);
+
+    if (isc['_' + this.widgetId]) {
+      widgetInstance = isc['_' + this.widgetId].create(isc.addProperties({
+        viewMode: 'maximized',
+        title: this.tabTitle,
+        widgetInstanceId: this.widgetInstanceId,
+        widgetId: this.widgetId,
+        dbInstanceId: this.widgetInstanceId,
+        parameters: this.parameters,
+        menuItems: this.menuItems,
+        canDelete: false
+      }));
+      this.addPortlet(widgetInstance);
+    } else {
+      //If the instance doesn't exist, just close the tab
+      for (i = 0; i < OB.MainView.TabSet.tabs.length; i++) {
+        if (OB.MainView.TabSet.tabs[i].title === 'OBCalendarWidgetView') {
+          OB.MainView.TabSet.removeTabs(i);
+          break;
+        }
+      }
+    }
+
+  },
+
+  isSameTab: function (viewName, params) {
+    return this.widgetInstanceId === params.widgetInstanceId;
+  }
+});
\ No newline at end of file