def js_add_properties(self, properties, world): if world.is_mod(self.page_user): key = "_properties-%s-global" % world.key.id() else: key = "_properties-%s-%s" % (world.key.id(), self.page_user.user.user_id()) js = memcache.get(key) if js is not None: return js world_properties = properties.get_result() js = "" values_list = "" properties_select = "<p id=\"prop_change\"><select id=\"prop_name\" name=\"prop_name\" class=\"prop_name\">" first_property_input = world_properties[0].get_input_type() for w_p in world_properties: properties_select += "<option value=\"%i\">%s</option>" % ( w_p.key.id(), w_p.name) if w_p.discrete and w_p.valid_values != "|text|" and w_p.valid_values != "|num|": #split, sort, rejoin and append raw_vals = w_p.valid_values.split("|") sorted_vals = sorted(raw_vals) sorted_str = "|".join(sorted_vals) values_list += "<p id=\"%i\">%s</p>" % (w_p.key.id(), sorted_str) else: values_list += "<p id=\"%i\">%s</p>" % (w_p.key.id(), str(w_p.valid_values)) properties_select += "</select>" properties_select += first_property_input properties_select += "</p>" values_js = "\njQuery('#validValues').append('%s');" % values_list properties_js = "\njQuery('#propertyBtn').click(function() {" properties_js += "\n\tjQuery('#propertyBtns').prepend('%s');" % properties_select properties_js += "\n\tjQuery('#prop_change select').change(function() {" properties_js += "\n\t\tvar optval = jQuery(this).find('option:selected').val();" properties_js += "\n\t\tvar valid = jQuery('#'+optval).text();" properties_js += "\n\t\tjQuery(this).next('#prop_val').replaceWith(get_input_type(valid));" properties_js += "\n\t\tjQuery(this).next('input').val(valid);" properties_js += "\n\t});" properties_js += "});" js += values_js js += properties_js memcache.add(key, js) add_user_to_cache_list("_properties-", world, self.page_user.user.user_id()) return js
def set_menu(self, world, access): key = self.menu_key(world, access) data = self.make_menu(world) try: """ If access can be an int, it's a user_id(), so add to list of users with personal menus. """ int(access) add_user_to_cache_list("", world, access) except ValueError: pass return memcache.set(key, data)
def js_add_properties(self, properties, world): if world.is_mod(self.page_user): key = "_properties-%s-global" % world.key.id() else: key = "_properties-%s-%s" % (world.key.id(), self.page_user.user.user_id()) js = memcache.get(key) if js is not None: return js world_properties = properties.get_result() js = "" values_list = "" properties_select = "<p id=\"prop_change\"><select id=\"prop_name\" name=\"prop_name\" class=\"prop_name\">" first_property_input = world_properties[0].get_input_type() for w_p in world_properties: properties_select += "<option value=\"%i\">%s</option>" % (w_p.key.id(), w_p.name) if w_p.discrete and w_p.valid_values != "|text|" and w_p.valid_values != "|num|": #split, sort, rejoin and append raw_vals = w_p.valid_values.split("|") sorted_vals = sorted(raw_vals) sorted_str = "|".join(sorted_vals) values_list += "<p id=\"%i\">%s</p>" % (w_p.key.id(), sorted_str) else: values_list += "<p id=\"%i\">%s</p>" % (w_p.key.id(), str(w_p.valid_values)) properties_select += "</select>" properties_select += first_property_input properties_select += "</p>" values_js = "\njQuery('#validValues').append('%s');" % values_list properties_js = "\njQuery('#propertyBtn').click(function() {" properties_js += "\n\tjQuery('#propertyBtns').prepend('%s');" % properties_select properties_js += "\n\tjQuery('#prop_change select').change(function() {" properties_js += "\n\t\tvar optval = jQuery(this).find('option:selected').val();" properties_js += "\n\t\tvar valid = jQuery('#'+optval).text();" properties_js += "\n\t\tjQuery(this).next('#prop_val').replaceWith(get_input_type(valid));" properties_js += "\n\t\tjQuery(this).next('input').val(valid);" properties_js += "\n\t});" properties_js += "});" js += values_js js += properties_js memcache.add(key, js) add_user_to_cache_list("_properties-", world, self.page_user.user.user_id()) return js