def generate_view(self, viewname, commands): """ Actually generates a named view of the viewname, The baseview for this Widget, the space that has been set to be the target in the baseview and the set of commands provided in the dictionary commands """ module = self.get_module() try: setting = module.get_config_entry("generate_views", self.get_id()) except ConfigurationException: setting = "False" if setting == "True": newview = View.get_from_id(self.get_baseview_id()).derive() viewname = sluggify(viewname) extcount = 0 while True: try: viewmanager.get_from_name(viewname) except ViewException: break else: extcount +=1 viewname = viewname[:-int(1+(math.ceil(math.log(extcount,10))))]+str(extcount) newview.set_name(viewname) newview.get_space_widget_mapping()[self.get_baseview_space_id()] = self.get_id() newview.get_widget_param_mapping()[self.get_id()] = commands newview.store()
def removeWidgetFromSpace(self, params): view_id = int(params[0]) space_id = int(params[1]) view = View.get_from_id(view_id) view.remove_widget_from_space(space_id) view.store()
def generate_link_from_actionlist(self, actionlist): """ Generates an ajaxlink from an actionlist. ajaxlinks look like: javascript:SkdAjax.load_link([{'w':<widget_id>,'p':{params}}, ... ]) the corresponding js on clientside should generate something like: /ajax/{'w':<widget_id>,'p':{params}} """ link = "javascript:window.SkdAJAX.execute_action(%s);" linkjson = [] for action in actionlist.get_actions(): if action.get_url() is not None: return action.get_url() elif action.get_view_id() is not None: view = View.get_from_id(action.get_view_id()) name = view.get_name() return "/web/"+quote(name) elif action.get_space() is not None and action.get_widget_id() is not None: page = Page.get_page(self.get_page()) space_names = page.get_space_names() space_name = space_names[action.get_space()] linkjson.append({"w":action.get_widget_id(), "s":space_name, "p":{}}) encoder = JSONEncoder() ajaxdata = encoder.encode(linkjson) ajaxdata = ajaxdata.replace('"',"'") return link%ajaxdata
def generate_link_from_actionlist(self, actionlist): """ returns a link that describes a call to a view that results of the actionlist """ target = {} target['s'] = self.get_page() target['v'] = deepcopy(self.get_space_widget_mapping()) target['b'] = deepcopy(self.get_box_mapping()) target['c'] = deepcopy(self.get_widget_param_mapping()) for action in actionlist.get_actions(): if action.get_url() is not None: return action.get_url() elif action.get_view_id() is not None: view = View.get_from_id(action.get_view_id()) name = view.get_name() return "/web/"+quote(name) elif action.get_space() is not None and action.get_widget_id() is not None: target['v'][action.get_space()] = action.get_widget_id() #delete any parameters of this widget. otherwise link will only #load current state of that widget again if target['c'].has_key(action.get_widget_id()): del(target['c'][action.get_widget_id()]) #AJAX-rendermode regarded here: ↓ encoder = JSONEncoder() viewjsonstring = quote(encoder.encode(target)) checkview = View.get_from_json(viewjsonstring) existing_name = checkview.check_has_name() if existing_name == False: return "/web/?"+viewjsonstring else: return "/web/"+existing_name
def setWidgetParamMapping(self, params): view_id = int(params[0]) widget_id = int(params[1]) mapping = int(params[2]) view = View.get_from_id(view_id) view.set_params_for_widget(widget_id, mapping) view.store(onlyWidgetParamMapping=True)
def setBoxMapping(self, params): view_id = int(params[0]) mapping = dict(params[1]) view = View.get_from_id(view_id) view.set_box_mapping(mapping) view.store(onlyBoxMapping=True) return True
def setSpaceWidgetMapping(self, params): view_id = int(params[0]) mapping = dict(params[1]) view = View.get_from_id(view_id) view.set_space_widget_mapping(mapping) view.store(onlySpaceWidgetMapping=True) return True
def assignWidgetToSpace(self,params): view_id = int(params[0]) space_id = int(params[1]) widget_id = int(params[2]) view = View.get_from_id(view_id) view.place_widget_in_space(space_id, widget_id) view.store()
def widgetActivateViewGeneration(self, params): widget_id = int(params[0]) view_id = int(params[1]) space_id = int(params[2]) view = View.get_from_id(view_id) widget = ModuleManager.get_widget(widget_id) widget.activate_viewgeneration(view, space_id) return
def getView(self, params): view_id = int(params[0]) view = View.get_from_id(view_id) ret = { 'id' : view.get_id(), 'name' : view.get_name(), 'site' : view.get_page(), 'default' : view.get_default(), 'space_widget_mapping' : view.get_space_widget_mapping(), 'box_mapping': view.get_box_mapping(), 'widget_param_mapping' : view.get_widget_param_mapping() } return ret
def create_action(cls, actionlist=None, view_id=None, url=None, widget_id = None, space_id = None): """ This method creates a new Action and returns it. You can create an action based on either: 1. A Page Id 2. An URL 3. A widgetId combined with a SpaceId (Both applies to the site the menu is showed in) If the combination is not valid this function will return null and not do anything in db The action will be inserted with the lowest order (execution priority) """ if actionlist is None: return None action = Action() action.set_action_list_id(actionlist.get_id()) if view_id is not None: view = View.get_from_id(view_id) if view is not None: action.set_view_id(view_id) else: return None elif url is not None: action.set_url(str(url),True) elif widget_id is not None and space_id is not None: widget = ModuleManager.get_widget(widget_id) if widget is not None: action.set_widget_space_constellation(widget_id,space_id,True) else: return None action.set_name("new action",True) db = Database() new_id = db.get_seq_next("ACT_GEN") stmnt = "SELECT MAX(ACT_ORDER) AS MAXORDER FROM ACTIONS WHERE ACT_ATL_ID = ? ;" cur = db.query(stmnt, (action.get_action_list_id(),)) row = cur.fetchonemap() if row["MAXORDER"] is not None: new_order = row["MAXORDER"]+1 else: new_order = 0 action.set_id(new_id) action.set_order(new_order) stmnt = "INSERT INTO ACTIONS (ACT_ID, ACT_NAME, ACT_ATL_ID, \ ACT_VIE_ID, ACT_SPA_ID, ACT_WGT_ID, ACT_URL, ACT_ORDER) \ VALUES (?,?,?,?,?,?,?,?) ;" db.query(stmnt, (action.get_id(), action.get_name(), action.get_action_list_id(), action.get_view_id(), action.get_space(), action.get_widget_id(), action.get_url(), action.get_order()),commit=True) PokeManager.add_activity(ActivityType.MENU) return action
def set_view_id(self, view_id, ignore_db = False): """ Make this a View-Link that links to another Skarphed-View Resets Widget/Page- and URL-Linkattributes """ if View.get_from_id(view_id) is not None: self._view_id = int(view_id) self._widget_id = None self._space_id = None self._url = None else: return if not ignore_db: db = Database() stmnt = "UPDATE ACTIONS SET ACT_URL = NULL, ACT_VIE_ID = ?, \ ACT_WGT_ID = NULL, ACT_SPA_ID = NULL WHERE ACT_ID = ? ;" db.query(stmnt,(self.get_view_id(),self.get_id()),commit=True) PokeManager.add_activity(ActivityType.MENU)