diff --git a/one_wiki/overrides/overrides.py b/one_wiki/overrides/overrides.py index 1726f32..74b2656 100644 --- a/one_wiki/overrides/overrides.py +++ b/one_wiki/overrides/overrides.py @@ -1,4 +1,4 @@ -import frappe +import frappe,random import re import os from frappe.website.utils import is_binary_file @@ -103,13 +103,17 @@ def update_old_page_(self): def create_new_wiki_page_(self): self.new_wiki_page = frappe.new_doc("Wiki Page") - + #Check for existing routes and update the route value with _ with one + route ="/".join(self.wiki_page_doc.route.split("/")[:-1] + [cleanup_page_name(self.new_title)]) + existing_routes = frappe.get_all("Wiki Page",{'route':route}) + if existing_routes: + str_index = random.choice(range(len(route)-1)) + route = route.replace(route[str_index],"_") + wiki_page_dict = { "title": self.new_title, "content": self.new_code, - "route": "/".join( - self.wiki_page_doc.route.split("/")[:-1] + [cleanup_page_name(self.new_title)] - ), + "route": route, "published": 1, "language":'عربي' if frappe.cache().get_value(f'wiki_language_{frappe.session.user}') =='ar' else 'English', "allow_guest": self.wiki_page_doc.allow_guest, diff --git a/one_wiki/public/js/editor.js b/one_wiki/public/js/editor.js index a447505..0614b33 100644 --- a/one_wiki/public/js/editor.js +++ b/one_wiki/public/js/editor.js @@ -43,11 +43,22 @@ const getContent = () => { }; const saveWikiPage = (draft = false) => { - console.log("INSIDE FUNC") + + const urlParams = new URLSearchParams(window.location.search); const isEmptyEditor = !!urlParams.get("newWiki"); const title = $(`.wiki-editor .ProseMirror h1`).html(); + if (!title){ + if(window.wiki_language == "English"){ + $(`.wiki-editor .ProseMirror h1`).focus(); + frappe.throw("Please set a Title") + } + else{ + $(`.wiki-editor .ProseMirror h1`).focus(); + frappe.throw("يرجى تحديد عنوان لهذه الوثيقة") + } + } // markdown=1 tag is needed for older wiki content to properly render // TODO: use editor.getHTML() instead of this when ueberdosis/tiptap#4044 is fixed const content = `